Skip to content

Commit

Permalink
CLI-1473: Update example text for iam rbac role-binding create (#1120)
Browse files Browse the repository at this point in the history
* updated example text

* pr comments

* updated example text

* pr comments
  • Loading branch information
mtodzo committed Dec 9, 2021
1 parent b853015 commit cf13b5d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
29 changes: 19 additions & 10 deletions internal/cmd/iam/command_rbac_role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func NewRoleBindingCommand(cfg *v1.Config, prerunner pcmd.PreRunner) *cobra.Comm
return roleBindingCmd.Command
}

func (c *roleBindingCommand) getCreateExample(cloud bool) examples.Example {
createCmdExampleText := `Create a role binding for the principal permitting it produce to the "users" topic.`
createCmdExampleCode := version.CLIName + " iam rbac role-binding create --principal User:appSA --role DeveloperWrite --resource Topic:users --kafka-cluster-id $KAFKA_CLUSTER_ID"
if cloud {
if c.ccloudRbacDataplaneEnabled {
createCmdExampleCode = version.CLIName + " iam rbac role-binding create --principal User:u-ab1234 --role DeveloperWrite --resource Topic:users --cloud-cluster lkc-ab123 --environment env-abcde"
} else {
createCmdExampleText = "Create a role binding for the principal giving it the CloudClusterAdmin role for the specified cluster and environment."
createCmdExampleCode = version.CLIName + " iam rbac role-binding create --principal User:u-ab1234 --role CloudClusterAdmin --cloud-cluster lkc-ab123 --environment env-abcde"
}
}
return examples.Example{Code: createCmdExampleCode, Text: createCmdExampleText}
}

func (c *roleBindingCommand) init() {
isCloud := c.cfg.IsCloudLogin()

Expand Down Expand Up @@ -191,16 +205,11 @@ func (c *roleBindingCommand) init() {
c.AddCommand(listCmd)

createCmd := &cobra.Command{
Use: "create",
Short: "Create a role binding.",
Args: cobra.NoArgs,
RunE: pcmd.NewCLIRunE(c.create),
Example: examples.BuildExampleString(
examples.Example{
Text: "Create a role binding for the client permitting it produce to the topic users:",
Code: version.CLIName + " iam rbac role-binding create --principal User:appSA --role DeveloperWrite --resource Topic:users --kafka-cluster-id $KAFKA_CLUSTER_ID",
},
),
Use: "create",
Short: "Create a role binding.",
Args: cobra.NoArgs,
RunE: pcmd.NewCLIRunE(c.create),
Example: examples.BuildExampleString(c.getCreateExample(isCloud)),
}
createCmd.Flags().String("role", "", "Role name of the new role binding.")
createCmd.Flags().String("principal", "", "Qualified principal name for the role binding.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Create a role binding.

Usage:
confluent iam rbac role-binding create [flags]

Examples:
Create a role binding for the principal permitting it produce to the "users" topic.

$ confluent iam rbac role-binding create --principal User:u-ab1234 --role DeveloperWrite --resource Topic:users --cloud-cluster lkc-ab123 --environment env-abcde

Flags:
--role string REQUIRED: Role name of the new role binding.
--principal string REQUIRED: Qualified principal name for the role binding.
--cloud-cluster string Cloud cluster ID for the role binding.
--environment string Environment ID for scope of role-binding create.
--current-env Use current environment ID for scope.
--prefix Whether the provided resource name is treated as a prefix pattern.
--resource string Qualified resource name for the role binding.
--kafka-cluster-id string Kafka cluster ID for the role binding.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")

Global Flags:
-h, --help Show help for this command.
-v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace).
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Usage:
confluent iam rbac role-binding create [flags]

Examples:
Create a role binding for the client permitting it produce to the topic users:
Create a role binding for the principal permitting it produce to the "users" topic.

$ confluent iam rbac role-binding create --principal User:appSA --role DeveloperWrite --resource Topic:users --kafka-cluster-id $KAFKA_CLUSTER_ID

Expand Down
1 change: 1 addition & 0 deletions test/iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *CLITestSuite) TestIAMRBACRoleCloud() {

func (s *CLITestSuite) TestIAMRBACRoleBindingCRUDCloud() {
tests := []CLITest{
{args: "iam rbac role-binding create --help", fixture: "iam/rbac/role-binding/create-help-cloud.golden"},
{args: "iam rbac role-binding create --principal User:u-11aaa --role CloudClusterAdmin --current-env --cloud-cluster lkc-1111aaa"},
{args: "iam rbac role-binding create --principal User:u-11aaa --role CloudClusterAdmin --environment a-595 --cloud-cluster lkc-1111aaa"},
{args: "iam rbac role-binding create --principal User:u-11aaa --role CloudClusterAdmin", fixture: "iam/rbac/role-binding/missing-cloud-cluster-cloud.golden", wantErrCode: 1},
Expand Down

0 comments on commit cf13b5d

Please sign in to comment.