login

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "login",
	Short: "Authenticate with Akita.",
	Long: `The CLI will prompt you to enter information for your Akita API key.

API key information will be stored in ` + cfg.GetCredentialsConfigPath(),
	SuggestFor:   []string{"signin", "sign-in", "log-in"},
	SilenceUsage: true,
	Args:         cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) error {
		ans := struct {
			APIKeyID     string
			APIKeySecret string
		}{}

		if checkCreds {
			return testCredentials()
		} else {

			qs := []*survey.Question{
				{
					Name:   "APIKeyID",
					Prompt: &survey.Input{Message: "API Key ID:"},
				},
				{
					Name:   "APIKeySecret",
					Prompt: &survey.Password{Message: "API Key Secret:"},
				},
			}

			if err := survey.Ask(qs, &ans); err != nil {
				return errors.Wrap(err, "failed to get API key ID and secret")
			}

			if err := cfg.WriteAPIKeyAndSecret("default", ans.APIKeyID, ans.APIKeySecret); err != nil {
				return errors.Wrap(err, "failed to save credentials config file")
			}

			fmt.Println("API keys stored in", cfg.GetCredentialsConfigPath())

			err := testCredentials()

			if err == nil {
				envId := os.Getenv("AKITA_API_KEY_ID")
				envSecret := os.Getenv("AKITA_API_KEY_SECRET")
				idIsOverridden := envId != "" && envId != ans.APIKeyID
				secretIsOverridden := envSecret != "" && envSecret != ans.APIKeySecret
				if idIsOverridden || secretIsOverridden {
					fmt.Printf("[WARNING] Login credentials are currently overridden by the AKITA_API_KEY_ID and AKITA_API_KEY_SECRET environment variables.\n")
				}
			}

			return err
		}
	},
}

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