Skip to content

基本APIの実装#7

Draft
turtton wants to merge 56 commits intomainfrom
feat/rest-basic
Draft

基本APIの実装#7
turtton wants to merge 56 commits intomainfrom
feat/rest-basic

Conversation

@turtton
Copy link
Member

@turtton turtton commented Jan 25, 2025

  • features
    • add event handler(save event and apply to entity)
    • implement defaults in XXId(Uuid)
  • methods
    • /account
    • /user
    • /metadata

@codecov
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

❌ Patch coverage is 55.20665% with 2211 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.83%. Comparing base (fcf9689) to head (149875a).

Files with missing lines Patch % Lines
application/src/service/profile.rs 0.00% 232 Missing ⚠️
application/src/service/metadata.rs 0.00% 218 Missing ⚠️
server/src/route/account.rs 0.00% 165 Missing ⚠️
application/src/service/account.rs 0.00% 158 Missing ⚠️
server/src/route/metadata.rs 11.76% 135 Missing ⚠️
server/src/route/profile.rs 23.07% 130 Missing ⚠️
server/src/handler.rs 0.00% 120 Missing ⚠️
adapter/src/processor/account.rs 0.00% 96 Missing ⚠️
adapter/src/processor/profile.rs 0.00% 96 Missing ⚠️
adapter/src/processor/metadata.rs 0.00% 79 Missing ⚠️
... and 36 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main       #7       +/-   ##
===========================================
- Coverage   95.08%   66.83%   -28.26%     
===========================================
  Files          58       71       +13     
  Lines        3888     7095     +3207     
===========================================
+ Hits         3697     4742     +1045     
- Misses        191     2353     +2162     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@turtton turtton marked this pull request as draft December 31, 2025 04:08
turtton and others added 22 commits December 31, 2025 19:59
- Add crypto module with RSA-2048 key generation using rsa crate
- Encrypt private keys with Argon2id key derivation + AES-256-GCM
- Read master password from /run/secrets or ./master-key-password
- Add security measures:
  - Zeroize sensitive data in memory
  - Validate password file permissions (Unix 0o600/0o400)
  - Use generic error messages to prevent timing attacks
- Add KernelError::NotFound for proper HTTP 404 responses

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add adapter crate with SigningKeyGenerator composed trait via blanket impl
- Move crypto implementations from application to driver layer
- Improve password memory management with Zeroizing<Vec<u8>>
- Standardize decrypt error messages to prevent information leakage
- Add comprehensive documentation for blanket implementations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Account作成をイベントソーシング経由(CommandEnvelope → event_streams → 非同期Applier)
から直接INSERT方式に変更し、auth_emumet_accountsリンクも同一フローで作成するように修正。

- AccountModifierトレイトにlink_auth_accountメソッド追加
- CreateAccountServiceをAccount::new() + 直接INSERT方式に書き換え
- Account::create()メソッド削除(update/deleteは既存のイベントソーシングを維持)
- EventVersion<T>にDefault実装追加
- 関連テストをAccountEvent::Created直接構築に更新
EditAccountServiceトレイトとupdate_account_by_idハンドラを追加し、
イベントソーシングによるアカウントのis_botフィールド更新を実装
非同期プロジェクション適用前に再取得すると古いデータを返す可能性があるため、
DELETEと同様に204 No Contentを返すように変更
cryptoで採用したadapterパターン(低レベルtrait合成)をaccountにも適用。
AccountQuery + AccountModifier → AccountRepository として合成し、
application層からはaccount_repository()経由で統一的にアクセスする。
blanket implによりkernel/driver/serverの変更は不要。
…eparation

AccountQuery/AccountModifier/AccountRepositoryを廃止し、CQRS設計に沿った
AccountReadModel(projection読み書き)とAccountEventStore(エンティティ別
イベント永続化)に置き換え。

- kernel: AccountReadModel trait, AccountEventStore trait 新設
- driver: PostgresAccountReadModel, PostgresAccountEventStore 実装
- migration: account_events テーブル追加(エンティティ別イベントストア)
- application: 全Account操作をイベント経由に統一(Command→Event→Projection)
- adapter: AccountRepository 削除(C/Q分離により不要に)
- Account::update/deleteにcurrent_versionパラメータを追加し楽観的排他制御を実装
- Deletedイベントでentityをhard delete (None) に変更
- AccountEventStoreのfind_by_idのSQLバインド順序を修正
- event.rsのfind_by_id_with_versionテストのロジックバグを修正しshouldpanicを除去
- マイグレーションのdata列をJSONBに変更、occurred_at列を追加
- テストでドメインロジック(Account::update/delete)と永続化テストを分離
Query/Modify/EventStore/ReadModel の associated type `Transaction` を
`Executor` にリネーム。引数名も `transaction` → `executor` に統一。
実態はコネクションラッパーであり、トランザクションではないため名前を修正。
…r for CQRS

- AccountEvent::Created に auth_account_id を追加し Account::create() static メソッドを追加
- adapter層に AccountCommandProcessor (EventStore + Signal をラップ) と
  AccountQueryProcessor (ReadModel読み取り専用) を配置
- application層のサービスを UseCase トレイトに書き換え (Get/Create/Edit/Delete)
  signal パラメータと認証関連DI境界を削除
- 認証ロジック (resolve_auth_account_id) を server層に移動
- AppModule に DependOn* トレイトを手動実装し blanket impl 経由で全UseCase を自動実装
- AccountApplier を直接ロジックに置き換え (Created イベントから auth_account_id を
  抽出して link_auth_account も処理)
- AuthAccountInfo を削除 (server層の KeycloakAuthAccount で代替)
- Signal::emit に + Send、Executor に : Send を追加
AuthAccountにAccount同様のCQRSパターンを適用:
- AuthAccountEventStore / AuthAccountReadModel を kernel に追加
- AuthAccountCommandProcessor / QueryProcessor を adapter に追加
- CommandProcessor内でprojection書き込みも完結させ、serverからReadModelの直接参照を除去
- 汎用EventModifier/EventQuery/AuthAccountQuery/AuthAccountModifierを削除
- auth_account_eventsテーブルのマイグレーション追加
- AuthAccount::deleteに楽観的排他制御(current_version)を追加
- CommandProcessor::deleteのシグネチャにcurrent_versionを追加
- UpdateAuthAccount applierでDeleted後のprojection削除を処理
- UpdateAuthAccount applierでReadModelに未登録のケース(create)を処理
- EventStoreテストのヘルパー関数重複を解消(親mod testに共通化)
依存グラフの修正、エンティティ分類の明確化、applicationサービスの記述追加
…moteAccount/Image/AuthHost

Profile/MetadataにCQRS + Event Sourcingパターンを適用:
- kernel: EventStore/ReadModelトレイト定義、ProfileEvent::Deleted追加、楽観的並行制御
- adapter: CommandProcessor/QueryProcessor(blanket impl)
- application: CRUD UseCase + EventApplierサービス + DTO
- driver: PostgreSQL EventStore/ReadModel実装
- server: REST API、Applier、DI配線
- migration: profile_events/metadata_eventsテーブル

Follow/RemoteAccount/Image/AuthHostをRepositoryパターンに移行:
- kernel: Repositoryトレイト定義(Query + Modifier統合)
- Follow/RemoteAccount: Event enum, EventApplier, CommandEnvelope削除
- driver: Repository impl書き換え(SQL変更なし)
- legacy Query/Modifierモジュール完全削除
- impl_database_delegation!マクロ + AppModule DI更新
Phase 1: Keycloak → Ory 移行

- Keycloak 依存を全て削除 (axum-keycloak-auth, KeycloakAuthLayer, KeycloakToken, expect_role!)
- JWT 検証ミドルウェア実装 (OIDC Discovery, JWKS キャッシュ, RS256)
- OAuth2 Login/Consent Provider エンドポイント (GET/POST /oauth2/login, /oauth2/consent)
- Hydra Admin API クライアント + Kratos セッションクライアント
- ルートハンドラ書き換え (AuthClaims ベース)
- Handler/AppModule に Hydra/Kratos クライアント統合
- compose.yml で開発環境一括起動 (PostgreSQL, Redis, Kratos, Hydra)
- E2E 検証完了 (Kratos login → OAuth2 flow → JWT → API access)
wiremockでHydra/Kratosをモックし、OAuth2エンドポイントの統合テスト10件を追加。
- GET /oauth2/login: skip/session有効/cookie無し/session無効の4ケース
- GET /oauth2/consent: skip/client skip/通常表示の3ケース
- POST /oauth2/consent: accept/scope不正/rejectの3ケース

その他の変更:
- tower 0.4→0.5にアップグレード(axum 0.7互換)
- Handler::init_with_urls()を抽出しコンストラクタの重複を解消
dotenvy::varでDATABASE_URLの存在を確認し、未設定時はテストをスキップするように変更。
CIなどDB未起動環境でテストが失敗しないようにする。
test_withのコンパイル時envチェックにより、DATABASE_URL未設定時は
テストがignoredとして正しく表示されるようにした。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant