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 {