Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ApiKeyCmd = &cobra.Command{ Use: "api-key", Short: "Api Key commands", Args: cobra.NoArgs, GroupID: util.SERVER_GROUP, }
View Source
var GenerateCmd = &cobra.Command{ Use: "generate [NAME]", Short: "Generate a new API key", Aliases: []string{"g", "new"}, Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() var keyName string apiClient, err := apiclient_util.GetApiClient(nil) if err != nil { return err } apiKeyList, _, err := apiClient.ApiKeyAPI.ListClientApiKeys(ctx).Execute() if err != nil { return apiclient_util.HandleErrorResponse(nil, err) } if len(args) == 1 { keyName = args[0] } else { apikey.ApiKeyCreationView(&keyName, apiKeyList) } for _, key := range apiKeyList { if key.Name == keyName { return errors.New("key name already exists, please choose a different one") } } key, _, err := apiClient.ApiKeyAPI.GenerateApiKey(ctx, keyName).Execute() if err != nil { return apiclient_util.HandleErrorResponse(nil, err) } serverConfig, _, err := apiClient.ServerAPI.GetConfigExecute(apiclient.ApiGetConfigRequest{}) if err != nil { return err } if serverConfig.Frps == nil { return errors.New("frps config is missing") } apiUrl := util.GetFrpcApiUrl(serverConfig.Frps.Protocol, serverConfig.Id, serverConfig.Frps.Domain) view.Render(key, apiUrl) return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.