- Add CredentialService for managing broker credentials - Implement credential CLI commands (create, list, get, update, delete) - Add postgres repository support for credential operations - Add comprehensive test coverage for credential CLI - Update docs/batches/index.md and docs/srs/index.md with BAT-005 - Update docs/project-structure.md to reflect credential service
3.0 KiB
3.0 KiB
BAT-005 Planning
- Status: confirmed
- Batch: BAT-005
- Profile: batch-lite
Included REQ
- REQ-015: CLI
credential명령 그룹 구현 (브로커 인증 정보 관리)
Out of Scope
- HTTP API 엔드포인트 추가 (별도 REQ 대상)
- 브로커 인증 정보 복호화 출력 (보안 정책상 CLI에서 plain text 노출 금지)
- 브로커 종류 확장 (현재는
kis기본값만 처리)
구현 순서
1단계: repository 메서드 추가
app/repositories/postgres.pydelete_broker_credential(user_id: str, broker: str) -> bool추가- 레코드 존재 시 삭제 후
True, 미존재 시False반환
- 레코드 존재 시 삭제 후
2단계: CLI 명령 모듈 신규 생성
app/cli/commands/credential.pycredential_app = typer.Typer(help="Broker credential management commands.")_with_service(ctx, callback)헬퍼: repository 생성 → callback 실행 → finally closeset명령:--user,--broker(기본값kis),--account-ref,--app-key,--app-secretget_user_by_username→None이면ValueErrorsettings.require_credential_encryption_key()→ Fernet 암호화upsert_broker_credential호출
list명령:--userget_user_by_username→None이면ValueErrorlist_broker_credentials호출,encrypted_payload제외 출력
remove명령:--user,--broker,--forceget_user_by_username→None이면ValueError_confirm(force, ...)확인 후delete_broker_credential호출
3단계: CLI 등록
app/cli/main.pyfrom app.cli.commands.credential import credential_appimport 추가app.add_typer(credential_app, name="credential")등록
4단계: 문서 갱신
docs/project-structure.md— CLI 모듈 목록에credential.py항목 추가
5단계: 테스트
tests/test_cli.pytest_cli_credential_set_creates_record(신규): alice 생성 후 set 실행 → list에 표시test_cli_credential_list_hides_payload(신규): list 출력에encrypted_payload미포함 확인test_cli_credential_set_with_unknown_user_exits_error(신규): 미존재 user → exit code 1test_cli_credential_remove_deletes_record(신규): set 후 remove → list에서 사라짐test_cli_credential_set_requires_encryption_key(신규): CREDENTIAL_ENCRYPTION_KEY 미설정 → exit code 1
Dependencies
- Internal:
broker_credentials테이블 (migration 0014 — 이미 존재)upsert_broker_credential,list_broker_credentials,get_broker_credential(이미 존재)app/core/encryption.py—encrypt_payload(이미 존재)app/core/config.py—settings.require_credential_encryption_key()(이미 존재)_confirm,execute_command,render_output(기존 CLI 헬퍼 — 이미 존재)
- External: 없음
Design Gate
- Design Required Before Implementation: no
- Reason: 기존
_with_service헬퍼 패턴 재사용 (user.py동일 구조). 구조/런타임 흐름 변경 없음.