From f0b24d13b1884f868aa7638fd8a157c0be408cd1 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Wed, 24 Aug 2022 15:15:02 +0100 Subject: [PATCH] cli: use policy flag for role creation and update. --- command/acl_role_create.go | 8 ++++---- command/acl_role_create_test.go | 4 ++-- command/acl_role_update.go | 8 ++++---- command/acl_role_update_test.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/command/acl_role_create.go b/command/acl_role_create.go index f1aa8482b..ed1ac0c0b 100644 --- a/command/acl_role_create.go +++ b/command/acl_role_create.go @@ -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 } diff --git a/command/acl_role_create_test.go b/command/acl_role_create_test.go index 6b107df3a..000bda470 100644 --- a/command/acl_role_create_test.go +++ b/command/acl_role_create_test.go @@ -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() diff --git a/command/acl_role_update.go b/command/acl_role_update.go index fcb71902f..872cc7f39 100644 --- a/command/acl_role_update.go +++ b/command/acl_role_update.go @@ -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 } diff --git a/command/acl_role_update_test.go b/command/acl_role_update_test.go index 3e0449bc8..9ae7adc11 100644 --- a/command/acl_role_update_test.go +++ b/command/acl_role_update_test.go @@ -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))