작업 내용 저장

This commit is contained in:
2026-04-23 10:16:09 +00:00
parent d383c7086f
commit bc56c5c101
7 changed files with 307 additions and 1 deletions
+32 -1
View File
@@ -2,10 +2,13 @@
from __future__ import annotations
from typing import Optional
import typer
from app.cli.core.output import mask_token_text, render_service_token_result
from app.schemas.auth import ServiceTokenIssueCliResponse, ServiceTokenRevokeCliResponse
from app.cli.core.utils import render_output
from app.schemas.auth import AuthTokenResponse, ServiceTokenIssueCliResponse, ServiceTokenRevokeCliResponse
from app.services.auth_service import AuthService
token_app = typer.Typer(help="Service token lifecycle commands.")
@@ -23,6 +26,34 @@ def _with_service(ctx: typer.Context, callback):
repository.close()
@token_app.command("list")
def list_service_tokens(
ctx: typer.Context,
user: Optional[str] = typer.Option(None, "--user", help="Filter by username."),
show_revoked: bool = typer.Option(False, "--show-revoked", help="Include revoked tokens."),
) -> None:
def _list(service: AuthService, app_context):
tokens = service.list_service_tokens(user, include_revoked=show_revoked)
return [
AuthTokenResponse(
id=t.id,
user_id=t.user_id,
name=t.name,
token_prefix=t.token_prefix,
permission=t.permission,
token_type=t.token_type,
expires_at=t.expires_at,
last_used_at=t.last_used_at,
revoked_at=t.revoked_at,
created_at=t.created_at,
)
for t in tokens
]
result = _with_service(ctx, _list)
render_output(ctx.obj.console, ctx.obj.output_format, result, empty_message="No service tokens found.")
@token_app.command("issue")
def issue_service_token(
ctx: typer.Context,
+26
View File
@@ -13,6 +13,7 @@ from rich.panel import Panel
from rich.table import Table
from app.core.errors import FeatureNotReadyError
from app.schemas.auth import AuthTokenResponse
from app.schemas.portfolio import CommentResponse, PortfolioDetailResponse, PortfolioListItem
from app.schemas.user import UserResponse
@@ -162,6 +163,28 @@ def print_user_detail(console: Console, user: UserResponse) -> None:
)
def print_service_token_table(console: Console, tokens: list[AuthTokenResponse]) -> None:
table = Table(title="Service Tokens", expand=True)
table.add_column("Name", style="cyan", no_wrap=True)
table.add_column("Permission", no_wrap=True)
table.add_column("User ID", no_wrap=True)
table.add_column("Prefix", no_wrap=True)
table.add_column("Expires At", no_wrap=True)
table.add_column("Revoked At", no_wrap=True)
table.add_column("Created At", no_wrap=True)
for token in tokens:
table.add_row(
token.name,
token.permission,
token.user_id,
token.token_prefix,
token.expires_at.isoformat(timespec="seconds") if token.expires_at else "never",
token.revoked_at.isoformat(timespec="seconds") if token.revoked_at else "-",
token.created_at.isoformat(timespec="seconds") if token.created_at else "N/A",
)
console.print(table)
def print_comment_table(console: Console, comments: list[CommentResponse]) -> None:
table = Table(title="Portfolio Comments", expand=True)
table.add_column("ID", style="cyan", no_wrap=True)
@@ -219,6 +242,9 @@ def render_output(console: Console, output_format: str, payload: Any, *, empty_m
if all(isinstance(item, CommentResponse) for item in payload):
print_comment_table(console, payload)
return
if all(isinstance(item, AuthTokenResponse) for item in payload):
print_service_token_table(console, payload)
return
return
if isinstance(payload, PortfolioDetailResponse):