Skip to content

Commit

Permalink
cli: use policy flag for role creation and update.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Aug 24, 2022
1 parent 34a1591 commit f0b24d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions command/acl_role_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ACL Create Options:
A free form text description of the role that must not exceed 256
characters.
-policy-name
-policy
Specifies a policy to associate with the role identified by their name. This
flag can be specified multiple times and must be specified at least once.
Expand All @@ -62,7 +62,7 @@ func (a *ACLRoleCreateCommand) AutocompleteFlags() complete.Flags {
complete.Flags{
"-name": complete.PredictAnything,
"-description": complete.PredictAnything,
"-policy-name": complete.PredictAnything,
"-policy": complete.PredictAnything,
"-json": complete.PredictNothing,
"-t": complete.PredictAnything,
})
Expand All @@ -86,7 +86,7 @@ func (a *ACLRoleCreateCommand) Run(args []string) int {
flags.Var((funcVar)(func(s string) error {
a.policyNames = append(a.policyNames, s)
return nil
}), "policy-name", "")
}), "policy", "")
flags.BoolVar(&a.json, "json", false, "")
flags.StringVar(&a.tmpl, "t", "", "")
if err := flags.Parse(args); err != nil {
Expand All @@ -107,7 +107,7 @@ func (a *ACLRoleCreateCommand) Run(args []string) int {
return 1
}
if len(a.policyNames) < 1 {
a.Ui.Error("At least one policy name must be specified using the -policy-name flag")
a.Ui.Error("At least one policy name must be specified using the -policy flag")
return 1
}

Expand Down
4 changes: 2 additions & 2 deletions command/acl_role_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestACLRoleCreateCommand_Run(t *testing.T) {
ui.ErrorWriter.Reset()

require.Equal(t, 1, cmd.Run([]string{"-address=" + url, `-name="foobar"`}))
require.Contains(t, ui.ErrorWriter.String(), "At least one policy name must be specified using the -policy-name flag")
require.Contains(t, ui.ErrorWriter.String(), "At least one policy name must be specified using the -policy flag")

ui.OutputWriter.Reset()
ui.ErrorWriter.Reset()
Expand All @@ -67,7 +67,7 @@ func TestACLRoleCreateCommand_Run(t *testing.T) {
// Create an ACL role.
args := []string{
"-address=" + url, "-token=" + rootACLToken.SecretID, "-name=acl-role-cli-test",
"-policy-name=acl-role-cli-test-policy", "-description=acl-role-all-the-things",
"-policy=acl-role-cli-test-policy", "-description=acl-role-all-the-things",
}
require.Equal(t, 0, cmd.Run(args))
s := ui.OutputWriter.String()
Expand Down
8 changes: 4 additions & 4 deletions command/acl_role_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Update Options:
A free form text description of the role that must not exceed 256
characters.
-policy-name
-policy
Specifies a policy to associate with the role identified by their name. This
flag can be specified multiple times.
Expand All @@ -70,7 +70,7 @@ func (a *ACLRoleUpdateCommand) AutocompleteFlags() complete.Flags {
"-name": complete.PredictAnything,
"-description": complete.PredictAnything,
"-no-merge": complete.PredictNothing,
"-policy-name": complete.PredictAnything,
"-policy": complete.PredictAnything,
"-json": complete.PredictNothing,
"-t": complete.PredictAnything,
})
Expand All @@ -94,7 +94,7 @@ func (a *ACLRoleUpdateCommand) Run(args []string) int {
flags.Var((funcVar)(func(s string) error {
a.policyNames = append(a.policyNames, s)
return nil
}), "policy-name", "")
}), "policy", "")
flags.BoolVar(&a.noMerge, "no-merge", false, "")
flags.BoolVar(&a.json, "json", false, "")
flags.StringVar(&a.tmpl, "t", "", "")
Expand Down Expand Up @@ -140,7 +140,7 @@ func (a *ACLRoleUpdateCommand) Run(args []string) int {
return 1
}
if len(a.policyNames) < 1 {
a.Ui.Error("At least one policy name must be specified using the -policy-name flag")
a.Ui.Error("At least one policy name must be specified using the -policy flag")
return 1
}

Expand Down
4 changes: 2 additions & 2 deletions command/acl_role_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func TestACLRoleUpdateCommand_Run(t *testing.T) {
code = cmd.Run([]string{
"-address=" + url, "-token=" + rootACLToken.SecretID, "-no-merge", "-name=update-role-name", aclRole.ID})
require.Equal(t, 1, code)
require.Contains(t, ui.ErrorWriter.String(), "At least one policy name must be specified using the -policy-name flag")
require.Contains(t, ui.ErrorWriter.String(), "At least one policy name must be specified using the -policy flag")

// Update the role using no-merge with all required flags set.
code = cmd.Run([]string{
"-address=" + url, "-token=" + rootACLToken.SecretID, "-no-merge", "-name=update-role-name",
"-description=updated-description", "-policy-name=acl-role-cli-test-policy", aclRole.ID})
"-description=updated-description", "-policy=acl-role-cli-test-policy", aclRole.ID})
require.Equal(t, 0, code)
s = ui.OutputWriter.String()
require.Contains(t, s, fmt.Sprintf("ID = %s", aclRole.ID))
Expand Down

0 comments on commit f0b24d1

Please sign in to comment.