Skip to content

Commit

Permalink
Automated from: 3066035
Browse files Browse the repository at this point in the history
  • Loading branch information
thycotic-rd committed Dec 18, 2020
1 parent 1add3ab commit 8400d2d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
18 changes: 9 additions & 9 deletions cicd-integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ func init() {
{"policy-read-fail", []string{"policy", "read", policyName}, outputPattern("will be removed")},
{"policy-restore", []string{"policy", "restore", policyName}, outputEmpty()},

//auth provider operations
{"auth-provider-help", []string{"config", "auth-provider", ""}, outputPattern(`Execute an action on an auth-provider.*`)},
{"auth-provider-create", []string{"config", "auth-provider", "create", "--name", authProvider, "--type", "aws", "--aws-account-id", "1234"}, outputPattern(fmt.Sprintf(`"name":\s*"%s"`, authProvider))},
{"auth-provider-read", []string{"config", "auth-provider", "read", authProvider}, outputPattern(fmt.Sprintf(`"name":\s*"%s"`, authProvider))},
{"auth-provider-update", []string{"config", "auth-provider", "update", "--name", authProvider, "--type", "aws", "--aws-account-id", "65433"}, outputPattern(fmt.Sprintf(`"accountId":\s*"%s"`, "65433"))},
{"auth-provider-rollback-pass", []string{"config", "auth-provider", "rollback", "--name", authProvider}, outputPattern(fmt.Sprintf(`"accountId":\s*"%s"`, "1234"))},

// user operations
{"user-help", []string{"user", ""}, outputPattern(`Execute an action on a user.*`)},
{"user-create-pass", []string{"user", "create", "--username", user1, "--password", user1Pass}, outputPattern(`"userName": "mrmittens"`)},
Expand All @@ -343,8 +350,8 @@ func init() {
{"user-read-fail", []string{"user", "read", user1}, outputPattern("will be removed")},
{"user-restore", []string{"user", "restore", user1}, outputEmpty()},
{"user-read-pass-verify-restore", []string{"user", "read", user1}, outputPattern(`"userName": "mrmittens"`)},
{"user-create-provider-missing", []string{"user", "create", "--username", "bob", "--external-id", "1234"}, outputPattern("must specify both provider and external ID")},
{"user-create-external-id-missing", []string{"user", "create", "--username", "bob", "--provider", "aws-dev"}, outputPattern("must specify both provider and external ID")},
{"user-create-provider-missing", []string{"user", "create", "--username", "bob", "--external-id", "1234"}, outputPattern("provider is required")},
{"user-create-external-id-missing", []string{"user", "create", "--username", "bob", "--provider", authProvider}, outputPattern("external ID is required")},

// group operations
{"group-help", []string{"group", ""}, outputPattern(`Execute an action on a group.*`)},
Expand Down Expand Up @@ -413,13 +420,6 @@ func init() {
{"config-get-implicit-pass", []string{"config"}, outputPattern(`"permissionDocument":`)},
{"config-get-pass", []string{"config", "read"}, outputPattern(`"permissionDocument":`)},

//auth provider operations
{"auth-provider-help", []string{"config", "auth-provider", ""}, outputPattern(`Execute an action on an auth-provider.*`)},
{"auth-provider-create", []string{"config", "auth-provider", "create", "--name", authProvider, "--type", "aws", "--aws-account-id", "1234"}, outputPattern(fmt.Sprintf(`"name":\s*"%s"`, authProvider))},
{"auth-provider-read", []string{"config", "auth-provider", "read", authProvider}, outputPattern(fmt.Sprintf(`"name":\s*"%s"`, authProvider))},
{"auth-provider-update", []string{"config", "auth-provider", "update", "--name", authProvider, "--type", "aws", "--aws-account-id", "65433"}, outputPattern(fmt.Sprintf(`"accountId":\s*"%s"`, "65433"))},
{"auth-provider-rollback-pass", []string{"config", "auth-provider", "rollback", "--name", authProvider}, outputPattern(fmt.Sprintf(`"accountId":\s*"%s"`, "1234"))},

// Home
{"home-help", []string{"home", ""}, outputPattern(`Work with secrets in a personal user space`)},
{"home-create", []string{"home", "create", homeSecretPath, "--desc", "some description"}, outputPattern(strings.ReplaceAll(homeSecretPath, "/", ":"))},
Expand Down
1 change: 0 additions & 1 deletion cicd/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestEnsureNoFmtUsage(t *testing.T) {
assert.False(t, bytes.Contains(b, []byte(fmtPackageName)), fmt.Sprintf(`Usage of "fmt" found in file '%s'`, f))
}
}

func getListGoFilePaths() ([]string, error) {
var pathDelim string
if runtime.GOOS == "windows" {
Expand Down
2 changes: 1 addition & 1 deletion commands/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Usage:
• %[1]s --%[2]s 2020-01-01
`, cst.NounAudit, cst.StartDate, cst.EndDate, cst.Limit),
FlagsPredictor: cli.PredictorWrappers{
preds.LongFlag(cst.StartDate): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.StartDate, Usage: "Start date from which to fetch audit data (required)"}), false},
preds.LongFlag(cst.StartDate): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.StartDate, Shorthand: "s", Usage: "Start date from which to fetch audit data (required)"}), false},
preds.LongFlag(cst.EndDate): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.EndDate, Usage: "End date to which to fetch audit data (optional)"}), false},
preds.LongFlag(cst.Limit): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.Limit, Shorthand: "l", Usage: "Maximum number of results per cursor (optional)"}), false},
preds.LongFlag(cst.Cursor): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.Cursor, Usage: "Next cursor for additional results (optional)"}), false},
Expand Down
8 changes: 8 additions & 0 deletions commands/cli-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ func handleCliConfigInitCmd(args []string) int {

if storeType != store.None {
if authError := tryAuthenticate(); authError != nil {
if isAccountLocked(authError) {
ui.Output(authError.Error())
return 1
}
ui.Output("Failed to authenticate, restoring previous config.")
ui.Output("Please check your credentials, or tenant name, or domain name and try again.")
return 1
Expand Down Expand Up @@ -681,6 +685,10 @@ func tryAuthenticate() error {
return nil
}

func isAccountLocked(err error) bool {
return strings.Contains(err.Error(), "locked out")
}

// WriteCliConfig writes the actual config file given the path, the config data structure and whether an existing config
// must be overwritten or extended with another profile.
func WriteCliConfig(cfgPath string, cfg jsonish, addingProfile bool) error {
Expand Down
12 changes: 9 additions & 3 deletions commands/logs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"time"

cst "thy/constants"
Expand All @@ -26,7 +27,12 @@ func GetLogsSearchCmd() (cli.Command, error) {
Path: []string{cst.NounLogs},
RunFunc: logs{requests.NewHttpClient(), nil}.handleLogsSearch,
SynopsisText: "system logs search",
HelpText: "Search system logs",
HelpText: fmt.Sprintf(`Search system logs
Usage:
• %[1]s --%[2]s 2020-01-01 --%[3]s 2020-01-04 --%[4]s 100
• %[1]s --%[2]s 2020-01-01
`, cst.NounLogs, cst.StartDate, cst.EndDate, cst.Limit),
FlagsPredictor: cli.PredictorWrappers{
preds.LongFlag(cst.StartDate): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.StartDate, Shorthand: "s", Usage: "Start date from which to fetch system log data (required)"}), false},
preds.LongFlag(cst.EndDate): cli.PredictorWrapper{complete.PredictAnything, preds.NewFlagValue(preds.Params{Name: cst.EndDate, Usage: "End date to which to fetch system log data (optional)"}), false},
Expand Down Expand Up @@ -57,8 +63,8 @@ func (l logs) handleLogsSearch(args []string) int {
}

queryParams := map[string]string{
cst.StartDate: startDate,
cst.EndDate: endDate,
"startDate": startDate,
"endDate": endDate,
cst.NounPrincipal: viper.GetString(cst.NounPrincipal),
cst.Path: viper.GetString(cst.Path),
cst.DataAction: viper.GetString(cst.DataAction),
Expand Down
7 changes: 1 addition & 6 deletions commands/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,8 @@ func (u User) handleUserCreateCmd(args []string) int {
}
provider := viper.GetString(cst.DataProvider)
externalID := viper.GetString(cst.DataExternalID)
if (provider != "" && externalID == "") || (provider == "" && externalID != "") {
err := errors.NewS("error: must specify both provider and external ID for third-party users")
u.outClient.WriteResponse(nil, err)
return utils.GetExecStatus(err)
}

isUserLocal := provider == "" || externalID == ""
isUserLocal := provider == "" && externalID == ""
password := viper.GetString(cst.DataPassword)
if password == "" && isUserLocal {
err := errors.NewS("error: must specify password for local users")
Expand Down

0 comments on commit 8400d2d

Please sign in to comment.