cli: use policy flag for role creation and update.

This commit is contained in:
James Rasell 2022-08-24 15:15:02 +01:00
parent 7401677e4e
commit 2ccc48c167
No known key found for this signature in database
GPG Key ID: AA7D460F5C8377AA
4 changed files with 12 additions and 12 deletions

View File

@ -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.
@ -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,
})
@ -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 {
@ -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
}

View File

@ -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()
@ -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()

View File

@ -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.
@ -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,
})
@ -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", "", "")
@ -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
}

View File

@ -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))