AirGate/backend/utils/ark_service.py
seaislee1209 0ac2ef1f27 feat: add Ark API Key management (list/create/toggle/delete)
- New VolcengineClient.call_json() for POST+JSON signing (Ark API)
- ArkService for API Key CRUD operations
- Backend views: list/create/toggle/delete ark keys per project
- Frontend: ArkKeysView with project selector, key table, create dialog
- Created key value shown once with copy button

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 21:36:13 +08:00

43 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""方舟ArkAPI Key 管理服务"""
import logging
from .volcengine_client import VolcengineClient, VolcengineAPIError, get_ark_client
logger = logging.getLogger(__name__)
class ArkService:
"""方舟 API Key 管理"""
def __init__(self, ak: str, sk: str):
self.client = get_ark_client(ak, sk)
def list_api_keys(self, project_name: str, page_size: int = 100, page_number: int = 1) -> dict:
"""列出项目下的 API Key"""
return self.client.call_json("ListApiKeys", {
"ProjectName": project_name,
"PageSize": page_size,
"PageNumber": page_number,
})
def create_api_key(self, project_name: str, name: str, resource_type: str = "all") -> dict:
"""在项目下创建 API Key"""
return self.client.call_json("CreateApiKey", {
"ProjectName": project_name,
"Name": name,
"ResourceInstances": [{"ResourceId": "*", "ResourceType": resource_type}],
})
def delete_api_key(self, api_key_id: int) -> dict:
"""删除 API Key"""
return self.client.call_json("DeleteApiKey", {
"Id": api_key_id,
})
def update_api_key_status(self, api_key_id: int, status: str) -> dict:
"""启用/停用 API Key (status: Active / Inactive)"""
return self.client.call_json("UpdateApiKey", {
"Id": api_key_id,
"Status": status,
})