feat(api): add /auth/whoami endpoint and build automation

This commit is contained in:
2025-12-25 14:54:52 +08:00
parent 8e6d86edd7
commit 30f15a84b5
7 changed files with 397 additions and 1 deletions

View File

@@ -2859,6 +2859,40 @@ const docTemplate = `{
}
}
},
"/auth/whoami": {
"get": {
"security": [
{
"AdminAuth": []
},
{
"MasterAuth": []
}
],
"description": "Returns the identity of the authenticated user based on the Authorization header.\nSupports Admin Token, Master Key, and Child Key (API Key) authentication.\n\nResponse varies by token type:\n- Admin Token: {\"type\": \"admin\", \"role\": \"admin\"}\n- Master Key: {\"type\": \"master\", \"id\": 1, \"name\": \"...\", ...}\n- Child Key: {\"type\": \"key\", \"id\": 5, \"master_id\": 1, \"issued_by\": \"master\", ...}",
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Get current identity",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_api.WhoamiResponse"
}
},
"401": {
"description": "Invalid or missing token",
"schema": {
"$ref": "#/definitions/gin.H"
}
}
}
}
},
"/internal/stats/flush": {
"post": {
"description": "Internal endpoint for flushing accumulated key usage stats from DP to CP database",
@@ -4620,6 +4654,83 @@ const docTemplate = `{
}
}
},
"internal_api.WhoamiResponse": {
"type": "object",
"properties": {
"created_at": {
"type": "integer",
"example": 1703505600
},
"default_namespace": {
"type": "string",
"example": "default"
},
"epoch": {
"type": "integer",
"example": 1
},
"global_qps": {
"type": "integer",
"example": 100
},
"group": {
"type": "string",
"example": "default"
},
"id": {
"description": "Master fields (only present when type is \"master\")",
"type": "integer",
"example": 1
},
"issued_at_epoch": {
"type": "integer",
"example": 1
},
"issued_by": {
"type": "string",
"example": "master"
},
"master_id": {
"description": "Key fields (only present when type is \"key\")",
"type": "integer",
"example": 1
},
"max_child_keys": {
"type": "integer",
"example": 5
},
"name": {
"type": "string",
"example": "tenant-a"
},
"namespaces": {
"type": "string",
"example": "default,ns1"
},
"role": {
"description": "Admin fields (only present when type is \"admin\")",
"type": "string",
"example": "admin"
},
"scopes": {
"type": "string",
"example": "chat:write"
},
"status": {
"type": "string",
"example": "active"
},
"type": {
"description": "Type of the authenticated identity: \"admin\", \"master\", or \"key\"",
"type": "string",
"example": "master"
},
"updated_at": {
"type": "integer",
"example": 1703505600
}
}
},
"internal_api.refreshModelRegistryRequest": {
"type": "object",
"properties": {