Skip to content

Commit

Permalink
Fix org token cli support (#3884)
Browse files Browse the repository at this point in the history
* chore(docs): Adding the provisioning docs for dev environments

* chore(docs): fixing build

* fix(cli): Organization Token CLI Support
  • Loading branch information
xoscar committed May 30, 2024
1 parent 6b81718 commit 9225aef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cli/cmd/configure_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var configureCmd = &cobra.Command{
flags.ServerURL = configParams.ServerURL
}

if flagProvided(cmd, "token") {
if configParams.Token != "" {
flags.Token = configParams.Token
}

Expand All @@ -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")

Expand Down
1 change: 1 addition & 0 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down
5 changes: 4 additions & 1 deletion cli/config/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9225aef

Please sign in to comment.