mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
Go CLI: refactor some commands (#16204)
### What problem does this PR solve? - list resources ### Type of change - [x] New Feature (non-breaking change which adds functionality) - [x] Refactoring --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"ragflow/internal/common"
|
||||
)
|
||||
|
||||
// PingServer pings the server to check if it's alive
|
||||
@@ -58,7 +58,7 @@ func (c *CLI) PingAdmin(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
// Show admin version to show RAGFlow admin version
|
||||
// Returns benchmark result map if iterations > 1, otherwise prints status
|
||||
func (c *CLI) ShowAdminVersion(cmd *Command) (ResponseIf, error) {
|
||||
func (c *CLI) AdminShowVersionCommand(cmd *Command) (ResponseIf, error) {
|
||||
// Get iterations from command params (for benchmark)
|
||||
iterations := 1
|
||||
if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
|
||||
@@ -92,8 +92,36 @@ func (c *CLI) ShowAdminVersion(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListRoles to list roles (admin mode only)
|
||||
func (c *CLI) ListRoles(cmd *Command) (ResponseIf, error) {
|
||||
// AdminListResourcesCommand to list resources command (admin mode only)
|
||||
func (c *CLI) AdminListResourcesCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", "/admin/roles/resource", "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list resources: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list resources: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list resources failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminListRolesCommand to list roles command (admin mode only)
|
||||
func (c *CLI) AdminListRolesCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
@@ -178,21 +206,21 @@ func (c *CLI) ShowRole(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// CreateRole creates a new role (admin mode only)
|
||||
func (c *CLI) CreateRole(cmd *Command) (ResponseIf, error) {
|
||||
// AdminCreateRoleCommand creates a new role (admin mode only)
|
||||
func (c *CLI) AdminCreateRoleCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
roleName, ok := cmd.Params["role_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
return nil, fmt.Errorf("role_name not provided")
|
||||
}
|
||||
|
||||
description, ok := cmd.Params["description"].(string)
|
||||
payload := map[string]interface{}{
|
||||
"role_name": roleName,
|
||||
}
|
||||
description, ok := cmd.Params["description"].(string)
|
||||
if ok {
|
||||
payload["description"] = description
|
||||
}
|
||||
@@ -206,7 +234,7 @@ func (c *CLI) CreateRole(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to create role: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
var result CommonDataResponse
|
||||
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("create role failed: invalid JSON (%w)", err)
|
||||
@@ -304,7 +332,10 @@ func (c *CLI) GrantAdmin(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/users/%s/admin", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to grant admin: %w", err)
|
||||
}
|
||||
@@ -337,7 +368,10 @@ func (c *CLI) RevokeAdmin(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/admin", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to revoke admin: %w", err)
|
||||
}
|
||||
@@ -359,8 +393,8 @@ func (c *CLI) RevokeAdmin(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// CreateUser creates a new user (admin mode only)
|
||||
func (c *CLI) CreateUser(cmd *Command) (ResponseIf, error) {
|
||||
// AdminCreateUserCommand creates a new user (admin mode only)
|
||||
func (c *CLI) AdminCreateUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
@@ -409,6 +443,47 @@ func (c *CLI) CreateUser(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminCreateUserAPIKeyCommand creates a new user API key (admin mode only)
|
||||
func (c *CLI) AdminCreateUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
userName, ok := cmd.Params["user_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create API key: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create API key: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("create API key failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
delete(result.Data, "update_date")
|
||||
delete(result.Data, "update_time")
|
||||
delete(result.Data, "create_time")
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ActivateUser activates or deactivates a user (admin mode only)
|
||||
func (c *CLI) ActivateUser(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
@@ -434,7 +509,10 @@ func (c *CLI) ActivateUser(cmd *Command) (ResponseIf, error) {
|
||||
"activate_status": activateStatus,
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/users/%s/activate", userName), "admin", nil, payload)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/activate", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update user status: %w", err)
|
||||
}
|
||||
@@ -482,7 +560,10 @@ func (c *CLI) AlterUserPassword(cmd *Command) (ResponseIf, error) {
|
||||
"new_password": encryptedPassword,
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/users/%s/password", userName), "admin", nil, payload)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/password", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to change user password: %w", err)
|
||||
}
|
||||
@@ -691,6 +772,79 @@ func (c *CLI) ShowVariable(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) AdminSetLicenseCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
license, ok := cmd.Params["license"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("license not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"license": license,
|
||||
}
|
||||
resp, err := c.AdminServerClient.Request("POST", "/admin/system/license", "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to set license: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to set license: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("set license failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) AdminSetLicenseConfigCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
value1, ok := cmd.Params["number1"].(int)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("number1 not provided")
|
||||
}
|
||||
value2, ok := cmd.Params["number2"].(int)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("number2 not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"value1": value1,
|
||||
"value2": value2,
|
||||
}
|
||||
resp, err := c.AdminServerClient.Request("PUT", "/admin/system/license/config", "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to set license config: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to set license config: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("set license config failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// SetVariable updates a system variable (admin mode only).
|
||||
func (c *CLI) SetVariable(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
@@ -732,8 +886,8 @@ func (c *CLI) SetVariable(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// DropUser deletes a user (admin mode only)
|
||||
func (c *CLI) DropUser(cmd *Command) (ResponseIf, error) {
|
||||
// AdminDropUserCommand deletes a user (admin mode only)
|
||||
func (c *CLI) AdminDropUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
@@ -743,7 +897,10 @@ func (c *CLI) DropUser(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/users/%s", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to drop user: %w", err)
|
||||
}
|
||||
@@ -765,6 +922,47 @@ func (c *CLI) DropUser(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminDropUserAPIKeyCommand drops an API key for a user (admin mode only)
|
||||
func (c *CLI) AdminDropUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
userName, ok := cmd.Params["user_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiKey, ok := cmd.Params["api_key"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("api_key not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys/%s", encodedUserName, apiKey)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to drop API key: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to drop API key: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("drop API key failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListUserDatasets lists datasets for a specific user (admin mode)
|
||||
// Returns (result_map, error) - result_map is non-nil for benchmark mode
|
||||
func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
|
||||
@@ -783,12 +981,15 @@ func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
|
||||
iterations = val
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
|
||||
|
||||
if iterations > 1 {
|
||||
// Benchmark mode - return raw result for benchmark stats
|
||||
return c.AdminServerClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil, iterations)
|
||||
return c.AdminServerClient.RequestWithIterations("GET", apiURL, "admin", nil, nil, iterations)
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil)
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list datasets: %w", err)
|
||||
}
|
||||
@@ -838,12 +1039,15 @@ func (c *CLI) ListAgents(cmd *Command) (ResponseIf, error) {
|
||||
iterations = val
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/agents", encodedUserName)
|
||||
|
||||
if iterations > 1 {
|
||||
// Benchmark mode - return raw result for benchmark stats
|
||||
return c.AdminServerClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/agents", userName), "admin", nil, nil, iterations)
|
||||
return c.AdminServerClient.RequestWithIterations("GET", apiURL, "admin", nil, nil, iterations)
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s/agents", userName), "admin", nil, nil)
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list agents: %w", err)
|
||||
}
|
||||
@@ -886,7 +1090,10 @@ func (c *CLI) GrantPermission(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list tokens: %w", err)
|
||||
}
|
||||
@@ -993,7 +1200,10 @@ func (c *CLI) AlterUserRole(cmd *Command) (ResponseIf, error) {
|
||||
"role_name": roleName,
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/users/%s/role", userName), "admin", nil, payload)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/role", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to alter user role: %w", err)
|
||||
}
|
||||
@@ -1031,7 +1241,10 @@ func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s/permission", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to show user permission: %w", err)
|
||||
}
|
||||
@@ -1069,7 +1282,10 @@ func (c *CLI) GenerateAdminToken(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("POST", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate token: %w", err)
|
||||
}
|
||||
@@ -1106,7 +1322,10 @@ func (c *CLI) ListAdminTokens(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list tokens: %w", err)
|
||||
}
|
||||
@@ -1137,47 +1356,6 @@ func (c *CLI) ListAdminTokens(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// DropToken drops an API token for a user (admin mode only)
|
||||
func (c *CLI) DropAdminToken(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
userName, ok := cmd.Params["user_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
token, ok := cmd.Params["token"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("token not provided")
|
||||
}
|
||||
|
||||
// URL encode the token to handle special characters
|
||||
encodedToken := url.QueryEscape(token)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/keys/%s", userName, encodedToken), "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to drop token: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to drop token: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("drop token failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) ListAdminTasks(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
@@ -1536,7 +1714,97 @@ func (c *CLI) AdminRemoveServiceCommand(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// Show user show user (admin mode only)
|
||||
// AdminCheckLicenseCommand check license command (admin mode only)
|
||||
func (c *CLI) AdminCheckLicenseCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/system/license?check=true")
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check license: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to check license: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check license failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminShowFingerprintCommand show fingerprint command (admin mode only)
|
||||
func (c *CLI) AdminShowFingerprintCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/system/fingerprint")
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to show fingerprint: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show fingerprint: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("show fingerprint failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminShowLicenseCommand show license command (admin mode only)
|
||||
func (c *CLI) AdminShowLicenseCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/system/license")
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to show license: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show license: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("show license failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// AdminShowUserInfoCommand show user info command (admin mode only)
|
||||
func (c *CLI) AdminShowUserInfoCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
@@ -1547,7 +1815,8 @@ func (c *CLI) AdminShowUserInfoCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -1592,7 +1861,8 @@ func (c *CLI) AdminShowUserActivityCommand(cmd *Command) (ResponseIf, error) {
|
||||
"email": email,
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/activity", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/activity", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
@@ -1626,7 +1896,8 @@ func (c *CLI) AdminShowUserSummaryCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/summary", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/summary", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -1670,7 +1941,8 @@ func (c *CLI) AdminShowUserDatasetCommand(cmd *Command) (ResponseIf, error) {
|
||||
"dataset": dataset,
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/dataset", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/dataset", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
@@ -1705,7 +1977,8 @@ func (c *CLI) AdminShowUserStorageCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/storage", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -1740,7 +2013,8 @@ func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/quota", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/quota", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -1775,7 +2049,8 @@ func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/index", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/index", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -1810,7 +2085,8 @@ func (c *CLI) AdminShowUserPermissionCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/permission", email)
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2260,7 +2536,8 @@ func (c *CLI) AdminPurgeUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
"preview": preview,
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/data", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/data", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
|
||||
if err != nil {
|
||||
@@ -2404,7 +2681,8 @@ func (c *CLI) AdminListUserDatasetsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/datasets", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2438,7 +2716,8 @@ func (c *CLI) AdminListUserAgentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/agents", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/agents", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2472,7 +2751,8 @@ func (c *CLI) AdminListUserChatsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/chats", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/chats", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2506,7 +2786,8 @@ func (c *CLI) AdminListUserSearchesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/searches", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/searches", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2540,7 +2821,8 @@ func (c *CLI) AdminListUserModelsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/models", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/models", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2574,7 +2856,8 @@ func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/files", userName)
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/files", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
@@ -2598,6 +2881,42 @@ func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) AdminListUserKeysCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
|
||||
}
|
||||
|
||||
userName, ok := cmd.Params["user_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list user %s keys: %w", userName, err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list user %s keys: HTTP %d, body: %s", userName, resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list user %s keys failed: invalid JSON (%w)", userName, err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) AdminStopUserIngestionTasksCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
|
||||
|
||||
@@ -146,12 +146,9 @@ func (p *Parser) parseAdminListCommand() (*Command, error) {
|
||||
case TokenAgents:
|
||||
return p.parseAdminListAgents()
|
||||
case TokenRoles:
|
||||
p.nextToken()
|
||||
// Semicolon is optional for SHOW TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return NewCommand("list_roles"), nil
|
||||
return p.parseAdminListRoles()
|
||||
case TokenResources:
|
||||
return p.parseAdminListResources()
|
||||
case TokenVars:
|
||||
p.nextToken()
|
||||
// Semicolon is optional for SHOW TOKEN
|
||||
@@ -259,6 +256,26 @@ func (p *Parser) parseAdminListAgents() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminListRoles() (*Command, error) {
|
||||
p.nextToken() // consume ROLES
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return NewCommand("admin_list_roles_command"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminListResources() (*Command, error) {
|
||||
p.nextToken() // consume RESOURCES
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return NewCommand("admin_list_resources_command"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminListTokens() (*Command, error) {
|
||||
p.nextToken() // consume TOKENS
|
||||
cmd := NewCommand("list_tokens")
|
||||
@@ -378,11 +395,10 @@ func (p *Parser) parseAdminShowCommand() (*Command, error) {
|
||||
return p.parseShowVariable()
|
||||
case TokenCurrent:
|
||||
return p.parseAdminShowCurrentCommand()
|
||||
// SHOW CURRENT USER
|
||||
//case TokenFingerprint:
|
||||
// return p.parseAdminShowFingerprintCommand()
|
||||
//case TokenLicense :
|
||||
// return p.parseAdminShowLicenseCommand()
|
||||
case TokenFingerprint:
|
||||
return p.parseAdminShowFingerprintCommand()
|
||||
case TokenLicense:
|
||||
return p.parseAdminShowLicenseCommand()
|
||||
case TokenProvider:
|
||||
return p.parseShowProvider()
|
||||
case TokenModel:
|
||||
@@ -541,6 +557,28 @@ func (p *Parser) parseCommonShowPoolModel() (*Command, error) {
|
||||
|
||||
// endregion SHOW commands
|
||||
|
||||
// parseAdminCheckCommand
|
||||
func (p *Parser) parseAdminCheckCommand() (*Command, error) {
|
||||
p.nextToken() // consume CHECK
|
||||
switch p.curToken.Type {
|
||||
case TokenLicense:
|
||||
return p.parseAdminCheckLicenseCommand()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown CHECK target: %s", p.curToken.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminCheckLicenseCommand() (*Command, error) {
|
||||
p.nextToken() // consume LICENSE
|
||||
cmd := NewCommand("admin_check_license_command")
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminStopIngestionTasks() (*Command, error) {
|
||||
p.nextToken() // consume STOP
|
||||
|
||||
@@ -611,9 +649,9 @@ func (p *Parser) parseAdminCreateCommand() (*Command, error) {
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenUser:
|
||||
return p.parseCreateUser()
|
||||
return p.parseAdminCreateUserCommand()
|
||||
case TokenRole:
|
||||
return p.parseCreateRole()
|
||||
return p.parseAdminCreateRoleCommand()
|
||||
case TokenModel:
|
||||
return p.parseCreateModelProvider()
|
||||
case TokenDataset:
|
||||
@@ -627,57 +665,72 @@ func (p *Parser) parseAdminCreateCommand() (*Command, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminCreateToken() (*Command, error) {
|
||||
p.nextToken() // consume TOKEN
|
||||
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return NewCommand("create_token"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminCreateUser() (*Command, error) {
|
||||
func (p *Parser) parseAdminCreateUserCommand() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
password, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var cmd *Command
|
||||
switch p.curToken.Type {
|
||||
case TokenQuotedString:
|
||||
var password string
|
||||
password, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
cmd = NewCommand("admin_create_user_command")
|
||||
cmd.Params["user_name"] = userName
|
||||
cmd.Params["password"] = password
|
||||
cmd.Params["role"] = "user"
|
||||
case TokenKey:
|
||||
return p.parseAdminCreateUserAPIKeyCommand(userName)
|
||||
default:
|
||||
return nil, fmt.Errorf("expected password or KEY after USER, got %s", p.curToken.Value)
|
||||
}
|
||||
|
||||
cmd := NewCommand("create_user")
|
||||
cmd.Params["user_name"] = userName
|
||||
cmd.Params["password"] = password
|
||||
cmd.Params["role"] = "user"
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminCreateRole() (*Command, error) {
|
||||
// CREATE USER 'user@example.com' KEY;
|
||||
func (p *Parser) parseAdminCreateUserAPIKeyCommand(userName string) (*Command, error) {
|
||||
p.nextToken() // consume KEY
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_create_user_api_key_command")
|
||||
cmd.Params["user_name"] = userName
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminCreateRoleCommand() (*Command, error) {
|
||||
p.nextToken() // consume ROLE
|
||||
roleName, err := p.parseIdentifier()
|
||||
roleName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("create_role")
|
||||
cmd := NewCommand("admin_create_role_command")
|
||||
cmd.Params["role_name"] = roleName
|
||||
|
||||
p.nextToken()
|
||||
if p.curToken.Type == TokenDescription {
|
||||
p.nextToken()
|
||||
description, err := p.parseQuotedString()
|
||||
var description string
|
||||
description, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -802,70 +855,60 @@ func (p *Parser) parseAdminDropCommand() (*Command, error) {
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenUser:
|
||||
return p.parseDropUser()
|
||||
return p.parseAdminDropUserCommand()
|
||||
case TokenRole:
|
||||
return p.parseDropRole()
|
||||
case TokenDataset:
|
||||
return p.parseDropDataset()
|
||||
case TokenChat:
|
||||
return p.parseDropChat()
|
||||
case TokenToken:
|
||||
return p.parseDropToken()
|
||||
return p.parseAdminDropRoleCommand()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown DROP target: %s", p.curToken.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminDropToken() (*Command, error) {
|
||||
p.nextToken() // consume TOKEN
|
||||
func (p *Parser) parseAdminDropUserCommand() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
|
||||
tokenValue, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if p.curToken.Type != TokenQuotedString {
|
||||
return nil, fmt.Errorf("expected USER name, got %s", p.curToken.Value)
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
if p.curToken.Type != TokenOf {
|
||||
return nil, fmt.Errorf("expected OF")
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("drop_token")
|
||||
cmd.Params["token"] = tokenValue
|
||||
cmd.Params["user_name"] = userName
|
||||
|
||||
p.nextToken()
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenKey:
|
||||
return p.parseAdminDropUserAPIKeyCommand(userName)
|
||||
default:
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
cmd := NewCommand("admin_drop_user_command")
|
||||
cmd.Params["user_name"] = userName
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminDropUserAPIKeyCommand(userName string) (*Command, error) {
|
||||
p.nextToken() // consume KEY
|
||||
|
||||
apiKey, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminDropUser() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("drop_user")
|
||||
cmd := NewCommand("admin_drop_user_api_key_command")
|
||||
cmd.Params["user_name"] = userName
|
||||
cmd.Params["api_key"] = apiKey
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminDropRole() (*Command, error) {
|
||||
func (p *Parser) parseAdminDropRoleCommand() (*Command, error) {
|
||||
p.nextToken() // consume ROLE
|
||||
roleName, err := p.parseIdentifier()
|
||||
if err != nil {
|
||||
@@ -1253,17 +1296,56 @@ func (p *Parser) parseAdminIdentifierList() ([]string, error) {
|
||||
func (p *Parser) parseAdminSetCommand() (*Command, error) {
|
||||
p.nextToken() // consume SET
|
||||
|
||||
if p.curToken.Type == TokenVar {
|
||||
return p.parseSetVariable()
|
||||
switch p.curToken.Type {
|
||||
case TokenLicense:
|
||||
return p.parseAdminSetLicense()
|
||||
case TokenVar:
|
||||
return p.parseAdminSetVariable()
|
||||
case TokenDefault:
|
||||
return p.parseAdminSetDefault()
|
||||
case TokenToken:
|
||||
return p.parseAdminSetToken()
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown SET target: %s", p.curToken.Value)
|
||||
}
|
||||
if p.curToken.Type == TokenDefault {
|
||||
return p.parseSetDefault()
|
||||
}
|
||||
if p.curToken.Type == TokenToken {
|
||||
return p.parseSetToken()
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminSetLicense() (*Command, error) {
|
||||
p.nextToken() // consume LICENSE
|
||||
|
||||
if p.curToken.Type == TokenConfig {
|
||||
p.nextToken() // consume CONFIG
|
||||
// SET LICENSE CONFIG <number1> <number2>
|
||||
cmd := NewCommand("admin_set_license_config_command")
|
||||
number1, err := p.parseNumber()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
number2, err := p.parseNumber()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
cmd.Params["number1"] = number1
|
||||
cmd.Params["number2"] = number2
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown SET target: %s", p.curToken.Value)
|
||||
license, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.nextToken()
|
||||
|
||||
cmd := NewCommand("admin_set_license_command")
|
||||
cmd.Params["license"] = license
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminSetVariable() (*Command, error) {
|
||||
@@ -1951,7 +2033,7 @@ func (p *Parser) parseAdminShowVersionCommand() (*Command, error) {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return NewCommand("show_version"), nil
|
||||
return NewCommand("admin_show_version_command"), nil
|
||||
}
|
||||
|
||||
// SHOW CURRENT;
|
||||
@@ -1966,6 +2048,28 @@ func (p *Parser) parseAdminShowCurrentCommand() (*Command, error) {
|
||||
return NewCommand("show_current"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminShowFingerprintCommand() (*Command, error) {
|
||||
p.nextToken() // consume FINGERPRINT
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return NewCommand("admin_show_fingerprint_command"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseAdminShowLicenseCommand() (*Command, error) {
|
||||
p.nextToken() // consume LICENSE
|
||||
|
||||
// Semicolon is optional
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return NewCommand("admin_show_license_command"), nil
|
||||
}
|
||||
|
||||
// SHOW USER 'user@example.com';
|
||||
// SHOW USER 'user@example.com' DATASET 'dataset_name';
|
||||
// SHOW USER 'user@example.com' SUMMARY;
|
||||
@@ -2596,6 +2700,9 @@ func (p *Parser) parseAdminListUserCommand() (*Command, error) {
|
||||
case TokenFiles:
|
||||
p.nextToken()
|
||||
cmd = NewCommand("admin_list_user_files_command")
|
||||
case TokenKeys:
|
||||
p.nextToken()
|
||||
cmd = NewCommand("admin_list_user_keys_command")
|
||||
default:
|
||||
return nil, fmt.Errorf("expected INGESTION or DATASETS or AGENTS or CHATS or SEARCHES or MODELS or FILES after USER")
|
||||
}
|
||||
|
||||
@@ -51,36 +51,48 @@ func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.GrantAdmin(cmd)
|
||||
case "revoke_admin":
|
||||
return c.RevokeAdmin(cmd)
|
||||
case "create_user":
|
||||
return c.CreateUser(cmd)
|
||||
case "admin_create_user_command":
|
||||
return c.AdminCreateUserCommand(cmd)
|
||||
case "admin_create_user_api_key_command":
|
||||
return c.AdminCreateUserAPIKeyCommand(cmd)
|
||||
case "admin_create_role_command":
|
||||
return c.AdminCreateRoleCommand(cmd)
|
||||
case "activate_user":
|
||||
return c.ActivateUser(cmd)
|
||||
case "alter_user":
|
||||
return c.AlterUserPassword(cmd)
|
||||
case "drop_user":
|
||||
return c.DropUser(cmd)
|
||||
case "admin_drop_user_command":
|
||||
return c.AdminDropUserCommand(cmd)
|
||||
case "admin_drop_user_api_key_command":
|
||||
return c.AdminDropUserAPIKeyCommand(cmd)
|
||||
case "show_service":
|
||||
return c.ShowService(cmd)
|
||||
case "show_version":
|
||||
return c.ShowAdminVersion(cmd)
|
||||
case "admin_show_version_command":
|
||||
return c.AdminShowVersionCommand(cmd)
|
||||
case "show_current":
|
||||
return c.ShowCommonCurrent(cmd)
|
||||
case "list_variables":
|
||||
return c.ListVariables(cmd)
|
||||
case "show_variable":
|
||||
return c.ShowVariable(cmd)
|
||||
case "admin_set_license_command":
|
||||
return c.AdminSetLicenseCommand(cmd)
|
||||
case "admin_set_license_config_command":
|
||||
return c.AdminSetLicenseConfigCommand(cmd)
|
||||
case "set_variable":
|
||||
return c.SetVariable(cmd)
|
||||
case "list_user_datasets":
|
||||
return c.ListUserDatasets(cmd)
|
||||
case "list_agents":
|
||||
return c.ListAgents(cmd)
|
||||
case "admin_list_resources_command":
|
||||
return c.AdminListResourcesCommand(cmd)
|
||||
case "admin_list_roles_command":
|
||||
return c.AdminListRolesCommand(cmd)
|
||||
case "generate_token":
|
||||
return c.GenerateAdminToken(cmd)
|
||||
case "list_tokens":
|
||||
return c.ListAdminTokens(cmd)
|
||||
case "drop_token":
|
||||
return c.DropAdminToken(cmd)
|
||||
case "list_available_providers":
|
||||
return c.ListAvailableProviders(cmd)
|
||||
case "show_provider":
|
||||
@@ -119,6 +131,12 @@ func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.UserShowMessageQueueCommand(cmd)
|
||||
case "admin_remove_service_command":
|
||||
return c.AdminRemoveServiceCommand(cmd)
|
||||
case "admin_check_license_command":
|
||||
return c.AdminCheckLicenseCommand(cmd)
|
||||
case "admin_show_fingerprint_command":
|
||||
return c.AdminShowFingerprintCommand(cmd)
|
||||
case "admin_show_license_command":
|
||||
return c.AdminShowLicenseCommand(cmd)
|
||||
case "admin_show_user_info_command":
|
||||
return c.AdminShowUserInfoCommand(cmd)
|
||||
case "admin_show_user_activity_command":
|
||||
@@ -175,6 +193,8 @@ func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return c.AdminListUserModelsCommand(cmd)
|
||||
case "admin_list_user_files_command":
|
||||
return c.AdminListUserFilesCommand(cmd)
|
||||
case "admin_list_user_keys_command":
|
||||
return c.AdminListUserKeysCommand(cmd)
|
||||
case "admin_stop_user_ingestion_tasks_command":
|
||||
return c.AdminStopUserIngestionTasksCommand(cmd)
|
||||
case "admin_remove_user_ingestion_tasks_command":
|
||||
|
||||
@@ -367,6 +367,10 @@ func (l *Lexer) lookupIdent(ident string) Token {
|
||||
return Token{Type: TokenRetrieve, Value: ident}
|
||||
case "CURRENT":
|
||||
return Token{Type: TokenCurrent, Value: ident}
|
||||
case "FINGERPRINT":
|
||||
return Token{Type: TokenFingerprint, Value: ident}
|
||||
case "LICENSE":
|
||||
return Token{Type: TokenLicense, Value: ident}
|
||||
case "VISION":
|
||||
return Token{Type: TokenVision, Value: ident}
|
||||
case "EMBEDDING":
|
||||
|
||||
@@ -92,6 +92,8 @@ func (p *Parser) parseAdminCommand() (*Command, error) {
|
||||
return p.parseAdminListCommand()
|
||||
case TokenShow:
|
||||
return p.parseAdminShowCommand()
|
||||
case TokenCheck:
|
||||
return p.parseAdminCheckCommand()
|
||||
case TokenCreate:
|
||||
return p.parseAdminCreateCommand()
|
||||
case TokenDrop:
|
||||
|
||||
@@ -104,6 +104,8 @@ const (
|
||||
TokenSearch
|
||||
TokenRetrieve
|
||||
TokenCurrent
|
||||
TokenFingerprint
|
||||
TokenLicense
|
||||
TokenVision
|
||||
TokenEmbedding
|
||||
TokenRerank
|
||||
|
||||
@@ -579,7 +579,7 @@ func (p *Parser) parseCreateCommand() (*Command, error) {
|
||||
|
||||
switch p.curToken.Type {
|
||||
case TokenUser:
|
||||
return p.parseCreateUser()
|
||||
return p.parseAdminCreateUserCommand()
|
||||
case TokenRole:
|
||||
return p.parseCreateRole()
|
||||
case TokenModel:
|
||||
@@ -697,32 +697,6 @@ func (p *Parser) parseCreateMetadataStore() (*Command, error) {
|
||||
return NewCommand("create_metadata_store"), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseCreateUser() (*Command, error) {
|
||||
p.nextToken() // consume USER
|
||||
userName, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
password, err := p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := NewCommand("create_user")
|
||||
cmd.Params["user_name"] = userName
|
||||
cmd.Params["password"] = password
|
||||
cmd.Params["role"] = "user"
|
||||
|
||||
p.nextToken()
|
||||
// Semicolon is optional for UNSET TOKEN
|
||||
if p.curToken.Type == TokenSemicolon {
|
||||
p.nextToken()
|
||||
}
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseCreateRole() (*Command, error) {
|
||||
p.nextToken() // consume ROLE
|
||||
roleName, err := p.parseIdentifier()
|
||||
|
||||
Reference in New Issue
Block a user