Skip to content

Commit

Permalink
feat(cli): --tenant flag to manage sub-accounts
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
  • Loading branch information
afiune committed Jul 29, 2020
1 parent 24dd1c0 commit 74163f7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
16 changes: 14 additions & 2 deletions cli/cmd/cli_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type cliState struct {
KeyID string
Secret string
Token string
Tenant string
LogLevel string

LwApi *api.Client
Expand Down Expand Up @@ -138,11 +139,17 @@ func (c *cliState) NewClient() error {
return err
}

client, err := api.NewClient(c.Account,
apiOpts := []api.Option{
api.WithLogLevel(c.LogLevel),
api.WithApiKeys(c.KeyID, c.Secret),
api.WithHeader("User-Agent", fmt.Sprintf("Command-Line/%s", Version)),
)
}

if c.Tenant != "" {
apiOpts = append(apiOpts, api.WithHeader("Accountname", c.Tenant))
}

client, err := api.NewClient(c.Account, apiOpts...)
if err != nil {
return errors.Wrap(err, "unable to generate api client")
}
Expand Down Expand Up @@ -244,6 +251,11 @@ func (c *cliState) loadStateFromViper() {
c.Account = v
c.Log.Debugw("state updated", "account", c.Account)
}

if v := viper.GetString("tenant"); v != "" {
c.Tenant = v
c.Log.Debugw("state updated", "tenant", c.Tenant)
}
}

func (c *cliState) extractValueString(key string) string {
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type credsDetails struct {
Account string `toml:"account" json:"account"`
ApiKey string `toml:"api_key" json:"api_key" survey:"api_key"`
ApiSecret string `toml:"api_secret" json:"api_secret" survey:"api_secret"`
Tenant string `toml:"tenant,omitempty" json:"tenant,omitempty"`
}

func (c *credsDetails) Verify() error {
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ func init() {
integrationCmd.AddCommand(integrationDeleteCmd)

// add type flag to integration list command
integrationListCmd.Flags().StringVarP(&integrationType,
"type", "t", "", "list all integrations of a specific type",
integrationListCmd.Flags().StringVar(&integrationType,
"type", "", "list all integrations of a specific type",
)
}

Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func init() {
rootCmd.PersistentFlags().StringP("account", "a", "",
"account subdomain of URL (i.e. <ACCOUNT>.lacework.net)",
)
rootCmd.PersistentFlags().StringP("tenant", "t", "", "tenant name (org admin only)")

errcheckWARN(viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")))
errcheckWARN(viper.BindPFlag("nocolor", rootCmd.PersistentFlags().Lookup("nocolor")))
Expand All @@ -109,6 +110,7 @@ func init() {
errcheckWARN(viper.BindPFlag("account", rootCmd.PersistentFlags().Lookup("account")))
errcheckWARN(viper.BindPFlag("api_key", rootCmd.PersistentFlags().Lookup("api_key")))
errcheckWARN(viper.BindPFlag("api_secret", rootCmd.PersistentFlags().Lookup("api_secret")))
errcheckWARN(viper.BindPFlag("tenant", rootCmd.PersistentFlags().Lookup("tenant")))
}

// initConfig reads in config file and ENV variables if set
Expand Down
1 change: 1 addition & 0 deletions integration/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Global Flags:
--nocolor turn off colors
--noninteractive turn off interactive mode (disable spinners, prompts, etc.)
-p, --profile string switch between profiles configured at ~/.lacework.toml
-t, --tenant string tenant name (org admin only)
Use "lacework compliance [command] --help" for more information about a command.
`,
Expand Down
2 changes: 2 additions & 0 deletions integration/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Global Flags:
--nocolor turn off colors
--noninteractive turn off interactive mode (disable spinners, prompts, etc.)
-p, --profile string switch between profiles configured at ~/.lacework.toml
-t, --tenant string tenant name (org admin only)
`,
out.String(),
"the configure help message changed, please update")
Expand Down Expand Up @@ -152,6 +153,7 @@ Flags:
--nocolor turn off colors
--noninteractive turn off interactive mode (disable spinners, prompts, etc.)
-p, --profile string switch between profiles configured at ~/.lacework.toml
-t, --tenant string tenant name (org admin only)
Use "lacework [command] --help" for more information about a command.
`,
Expand Down

0 comments on commit 74163f7

Please sign in to comment.