feat: マルチテナント対応 — テナント名ログイン & プロフィル連携#95
Conversation
- auth login で --service (-s) によるテナント名指定に対応 availableTenants から name/tenantId をマッチして解決 - GdbConfig に tenantId / availableTenants フィールドを追加 service との意味的分離で config の可読性を向上 - profile use 時にトークンが期限切れなら refreshToken で自動リフレッシュ - profile show で availableTenants を一覧表示(current マーカー付き) - TenantChoice に name フィールド追加、選択プロンプトで名前表示に対応
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughこのプルリクエストはマルチテナント対応を追加します。ログインでテナント名指定( Changes
Sequence Diagram(s)sequenceDiagram
participant User as ユーザー
participant CLI as CLI (auth.ts)
participant Server as Server (/auth/login)
participant Config as Config
User->>CLI: geonic auth login
CLI->>Server: POST /auth/login (email,password)
Server-->>CLI: tokens + availableTenants[]
alt 複数テナント
CLI->>User: テナント選択プロンプト
User->>CLI: テナント選択
CLI->>Server: POST /auth/login (email,password,tenantId)
Server-->>CLI: 選択テナントのトークン
else 単一テナントまたは解決済み
CLI->>Server: (必要なら)POST /auth/login (tenantId)
Server-->>CLI: トークン
end
CLI->>Config: tenantId, availableTenants を保存
CLI-->>User: ✓ <tenant label> でログインしました
sequenceDiagram
participant User as ユーザー
participant CLI as CLI (profile.ts)
participant Config as Config
participant Server as Server (/auth/refresh)
User->>CLI: geonic profile use <name>
CLI->>Config: プロファイル読み込み
Config-->>CLI: {token, refreshToken, tenantId, url,...}
CLI->>CLI: getTokenStatus(token)
alt トークン期限切れ/間近
CLI->>Server: POST /auth/refresh (refreshToken)
Server-->>CLI: 新 accessToken (+refreshToken?)
CLI->>Config: 新トークンを保存 (saveConfig)
CLI-->>User: ✓ Switched to <name>\n✓ Token refreshed
else トークン有効
CLI-->>User: ✓ Switched to <name>
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/types.ts (1)
3-7:TenantInfoとTenantChoiceの型重複について
src/prompt.tsのTenantChoiceインターフェースと構造が同一です(tenantId,name?,role)。現状は動作に問題ありませんが、将来的にどちらかの型が変更された場合、不整合が発生するリスクがあります。共通の型を定義して両方で再利用することを検討してください。例えば
TenantChoiceをTenantInfoのエイリアスにするか、TenantInfoをsrc/prompt.tsでインポートして使用する方法があります。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/types.ts` around lines 3 - 7, TenantInfo and TenantChoice duplicate the same shape; pick one canonical type and reuse it to avoid drift: remove the duplicate TenantChoice declaration and update the code that referenced TenantChoice (e.g., in prompt.ts) to import and use TenantInfo, or conversely make TenantChoice a type alias of TenantInfo (export type TenantChoice = TenantInfo) and import that alias where needed; ensure all references to TenantChoice/TenantInfo compile and update any exports so only the shared type is maintained.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/types.ts`:
- Around line 3-7: TenantInfo and TenantChoice duplicate the same shape; pick
one canonical type and reuse it to avoid drift: remove the duplicate
TenantChoice declaration and update the code that referenced TenantChoice (e.g.,
in prompt.ts) to import and use TenantInfo, or conversely make TenantChoice a
type alias of TenantInfo (export type TenantChoice = TenantInfo) and import that
alias where needed; ensure all references to TenantChoice/TenantInfo compile and
update any exports so only the shared type is maintained.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b50d66e3-bb63-4871-ac57-bb2c719651f4
📒 Files selected for processing (8)
CHANGELOG.mdsrc/commands/auth.tssrc/commands/profile.tssrc/config.tssrc/prompt.tssrc/types.tstests/auth.test.tstests/commands-profile.test.ts
Summary
Closes #90 (Phase 1 残り + Phase 2)
-s <テナント名>でログイン対応:geonic auth login -s demo_smartcityでavailableTenantsから名前 or tenantId をマッチしてテナントスコープログイン。マッチしなければ利用可能なテナント一覧をエラー表示tenantId/availableTenantsを config に保存:GdbConfigに明示的フィールド追加。service(NGSILD-Tenant ヘッダー) との意味的分離profile use時のトークン自動リフレッシュ: プロフィル切り替え時にトークンが期限切れ/間近ならrefreshTokenで自動更新。テナント名を成功メッセージに表示profile showでテナント一覧表示:availableTenantsを整形表示、現在のテナントに← currentマーカーTenantChoiceにnameフィールド追加、名前 (tenantId) [role]形式で表示Phase 3 (
auth switch) はprofile useでカバーできるため不要と判断し、スコープ外とした。Test plan
npm run lint— パスnpm run typecheck— パスnpm test— 684/684 パス(新規テスト 11 件追加)geonic auth loginで複数テナント所属ユーザーのインタラクティブ選択を確認geonic auth login -s <テナント名>でプロンプトなしにテナント指定ログインを確認geonic profile showでavailableTenants一覧とカレントマーカーを確認geonic profile use <name>で期限切れトークンの自動リフレッシュを確認Summary by CodeRabbit
-s <テナント名>で名前指定またはID指定が可能になりました。