feat: 주요 CLI, 인증, 서비스 로직 및 문서 개선
This commit is contained in:
+38
-1
@@ -6,6 +6,8 @@ import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
import secrets
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
@@ -47,4 +49,39 @@ def hash_token(token: str) -> str:
|
||||
|
||||
|
||||
def token_prefix(token: str) -> str:
|
||||
return token[:8]
|
||||
return token[:8]
|
||||
|
||||
|
||||
def mask_secret(value: str, *, prefix: int = 6, suffix: int = 4, mask_char: str = "*") -> str:
|
||||
text = (value or "").strip()
|
||||
if not text:
|
||||
return ""
|
||||
if len(text) <= prefix + suffix:
|
||||
return mask_char * len(text)
|
||||
hidden = len(text) - prefix - suffix
|
||||
return f"{text[:prefix]}{mask_char * hidden}{text[-suffix:]}"
|
||||
|
||||
|
||||
def build_audit_event(
|
||||
*,
|
||||
action: str,
|
||||
actor_id: str,
|
||||
bot_id: str,
|
||||
token_id: str,
|
||||
token_ref: str,
|
||||
result: str,
|
||||
detail: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {
|
||||
"event_type": "auth.bot_token",
|
||||
"action": action,
|
||||
"actor_id": actor_id,
|
||||
"bot_id": bot_id,
|
||||
"token_id": mask_secret(token_id, prefix=6, suffix=4),
|
||||
"token_ref": token_ref,
|
||||
"result": result,
|
||||
"occurred_at": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
if detail:
|
||||
payload["detail"] = detail
|
||||
return payload
|
||||
Reference in New Issue
Block a user