apikey

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL