Skip to content

Commit

Permalink
feat: adding flags for token, environment and organization (#3337)
Browse files Browse the repository at this point in the history
adding flags for environment and organization
  • Loading branch information
danielbdias committed Nov 6, 2023
1 parent e4dd4a0 commit 72a9e3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
25 changes: 22 additions & 3 deletions cli/cmd/configure_cmd.go
Expand Up @@ -34,6 +34,18 @@ var configureCmd = &cobra.Command{
flags.Endpoint = configParams.Endpoint
}

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

if flagProvided(cmd, "environment") {
flags.EnvironmentID = configParams.EnvironmentID
}

if flagProvided(cmd, "organization") {
flags.OrganizationID = configParams.OrganizationID
}

err = configurator.Start(ctx, config, flags)
return "", err
})),
Expand All @@ -48,14 +60,21 @@ func init() {
configureCmd.PersistentFlags().BoolVarP(&configParams.Global, "global", "g", false, "configuration will be saved in your home dir")
configureCmd.PersistentFlags().StringVarP(&configParams.Endpoint, "endpoint", "e", "", "set the value for the endpoint, so the CLI won't ask for this value")

configureCmd.PersistentFlags().StringVarP(&configParams.Token, "token", "t", "", "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")
rootCmd.AddCommand(configureCmd)
}

type configureParameters struct {
Endpoint string
Global bool
CI bool
Endpoint string
Global bool
CI bool
Token string
OrganizationID string
EnvironmentID string
}

func (p configureParameters) Validate(cmd *cobra.Command, args []string) []error {
Expand Down
11 changes: 9 additions & 2 deletions cli/config/configurator.go
Expand Up @@ -117,8 +117,15 @@ func (c Configurator) Start(ctx context.Context, prev Config, flags ConfigFlags)
return err
}

flags.OrganizationID = claims["organization_id"].(string)
flags.EnvironmentID = claims["environment_id"].(string)
organizationId := claims["organization_id"].(string)
environmentId := claims["environment_id"].(string)

if organizationId != "" {
flags.OrganizationID = organizationId
}
if environmentId != "" {
flags.EnvironmentID = environmentId
}
}

if flags.AgentApiKey != "" {
Expand Down

0 comments on commit 72a9e3d

Please sign in to comment.