From 9225aeff2dc32947a4be12ba5b1c647e22d433a6 Mon Sep 17 00:00:00 2001 From: Oscar Reyes Date: Thu, 30 May 2024 15:24:27 -0600 Subject: [PATCH] Fix org token cli support (#3884) * chore(docs): Adding the provisioning docs for dev environments * chore(docs): fixing build * fix(cli): Organization Token CLI Support --- cli/cmd/configure_cmd.go | 6 +++--- cli/config/config.go | 1 + cli/config/configurator.go | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/cmd/configure_cmd.go b/cli/cmd/configure_cmd.go index 0ad4db749b..d757a24c6a 100644 --- a/cli/cmd/configure_cmd.go +++ b/cli/cmd/configure_cmd.go @@ -36,7 +36,7 @@ var configureCmd = &cobra.Command{ flags.ServerURL = configParams.ServerURL } - if flagProvided(cmd, "token") { + if configParams.Token != "" { flags.Token = configParams.Token } @@ -62,13 +62,13 @@ var deprecatedEndpoint string func init() { configureCmd.PersistentFlags().BoolVarP(&configParams.Global, "global", "g", false, "configuration will be saved in your home dir") - configureCmd.PersistentFlags().StringVarP(&configParams.Token, "token", "t", "", "set authetication with token, so the CLI won't ask you for authentication") + configureCmd.PersistentFlags().StringVarP(&configParams.Token, "token", "t", defaultToken, "set authetication with token, so the CLI won't ask you for authentication") configureCmd.PersistentFlags().StringVarP(&configParams.EnvironmentID, "environment", "", "", "set environmentID, so the CLI won't ask you for it") configureCmd.PersistentFlags().StringVarP(&configParams.OrganizationID, "organization", "", "", "set organizationID, so the CLI won't ask you for it") configureCmd.PersistentFlags().BoolVarP(&configParams.CI, "ci", "", false, "if cloud is used, don't ask for authentication") - configureCmd.PersistentFlags().StringVarP(&deprecatedEndpoint, "endpoint", "e", "", "set the value for the endpoint, so the CLI won't ask for this value") + configureCmd.PersistentFlags().StringVarP(&deprecatedEndpoint, "endpoint", "e", defaultEndpoint, "set the value for the endpoint, so the CLI won't ask for this value") configureCmd.PersistentFlags().MarkDeprecated("endpoint", "use --server-url instead") configureCmd.PersistentFlags().MarkShorthandDeprecated("e", "use --server-url instead") diff --git a/cli/config/config.go b/cli/config/config.go index 0aaf045d9b..57ae20e15c 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -29,6 +29,7 @@ type Config struct { OrganizationID string `yaml:"organizationID,omitempty"` EnvironmentID string `yaml:"environmentID,omitempty"` Token string `yaml:"token,omitempty"` + IsOrgToken bool `yaml:"isOrgToken,omitempty"` Jwt string `yaml:"jwt,omitempty"` AgentApiKey string `yaml:"-"` EndpointOverriden bool `yaml:"-"` diff --git a/cli/config/configurator.go b/cli/config/configurator.go index e7c583e635..99ca05bb53 100644 --- a/cli/config/configurator.go +++ b/cli/config/configurator.go @@ -329,6 +329,9 @@ func (c Configurator) exchangeToken(cfg Config, token string) (Config, error) { if environmentId != "" { c.logger.Debug("Using environment ID from token", zap.String("environmentID", environmentId)) c.flags.EnvironmentID = environmentId + } else { + c.logger.Debug("Environment ID not found in token, using default") + cfg.IsOrgToken = true } return cfg, nil @@ -374,7 +377,7 @@ func (c Configurator) showOrganizationSelector(ctx context.Context, prev *Config } cfg.EnvironmentID = c.flags.EnvironmentID - if cfg.EnvironmentID == "" && c.flags.AgentApiKey == "" { + if cfg.EnvironmentID == "" && c.flags.AgentApiKey == "" && !cfg.IsOrgToken { c.logger.Debug("Environment ID not found, prompting for environment") envID, err := c.environmentSelector(ctx, cfg, prev) if err != nil {