Add api tokens commands of go admin cli (#13765)

### What problem does this PR solve?

- GENERATE TOKENS OF USER 'xxx@xxx.com'
- DROP KEY 'ragflow-yyyyy' OF 'xxx@xxx.com'
- LIST KEYS OF 'xxx@xxx.com'

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-03-25 21:39:14 +08:00
committed by GitHub
parent 33948b9dd8
commit 61cc5ffef2
10 changed files with 3349 additions and 1714 deletions

View File

@@ -983,8 +983,8 @@ func (c *RAGFlowClient) ShowUserPermission(cmd *Command) (ResponseIf, error) {
return &result, nil
}
// CreateAdminToken generates an API token for a user (admin mode only)
func (c *RAGFlowClient) CreateAdminToken(cmd *Command) (ResponseIf, error) {
// GenerateAdminToken generates an API token for a user (admin mode only)
func (c *RAGFlowClient) GenerateAdminToken(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
}
@@ -1003,7 +1003,7 @@ func (c *RAGFlowClient) CreateAdminToken(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("failed to generate token: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
}
var result CommonResponse
var result CommonDataResponse
if err = json.Unmarshal(resp.Body, &result); err != nil {
return nil, fmt.Errorf("generate token failed: invalid JSON (%w)", err)
}
@@ -1012,10 +1012,9 @@ func (c *RAGFlowClient) CreateAdminToken(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("%s", result.Message)
}
// Remove extra field from data
for _, item := range result.Data {
delete(item, "extra")
}
delete(result.Data, "update_date")
delete(result.Data, "update_time")
delete(result.Data, "create_time")
result.Duration = resp.Duration
return &result, nil
@@ -1052,7 +1051,11 @@ func (c *RAGFlowClient) ListAdminTokens(cmd *Command) (ResponseIf, error) {
// Remove extra field from data
for _, item := range result.Data {
delete(item, "extra")
delete(item, "dialog_id")
delete(item, "source")
delete(item, "update_date")
delete(item, "update_time")
delete(item, "create_time")
}
result.Duration = resp.Duration