Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/commands/rhoas_kafka_acl_list.adoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 49 additions & 1 deletion pkg/cmd/kafka/acl/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ type options struct {
size int32
kafkaID string
principal string
output string

topic string
group string
cluster bool

output string
}

// NewListACLCommand creates a new command to list Kafka ACL rules
Expand Down Expand Up @@ -116,6 +121,9 @@ func NewListACLCommand(f *factory.Factory) *cobra.Command {
flags.AddUser(&userID)
flags.AddServiceAccount(&serviceAccount)
flags.AddAllAccounts(&allAccounts)
flags.AddCluster(&opts.cluster)
flags.AddTopic(&opts.topic)
flags.AddConsumerGroup(&opts.group)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add dynamic completions for these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be good to add an additional field factory in the flagSet struct? That will make it easier to reuse completions for topic and group from cmdutils?

Copy link
Contributor

@craicoverflow craicoverflow Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be a good move. You can remove the localizer and conn fields so and just use this :)

I'd recommend refactoring these completions APIs also to look like this one:

func RegisterNameFlagCompletionFunc(cmd *cobra.Command, f *factory.Factory) error {

They also probably should not be in a generic cmdutil package since they are kafka specific (I did that 😂)


return cmd
}
Expand All @@ -141,6 +149,40 @@ func runList(opts *options) (err error) {
req = req.Principal(principalQuery)
}

var selectedResourceTypeCount int
var resourceType string
var resourceName string

if opts.topic != "" {
selectedResourceTypeCount++
resourceType = aclutil.ResourceTypeTOPIC
resourceName = opts.topic
}

if opts.group != "" {
selectedResourceTypeCount++
resourceType = aclutil.ResourceTypeGROUP
resourceName = opts.group
}

if opts.cluster {
selectedResourceTypeCount++
resourceType = aclutil.ResourceTypeCLUSTER
resourceName = aclutil.KafkaCluster
}

if selectedResourceTypeCount > 1 {
return opts.localizer.MustLocalizeError("kafka.acl.common.error.oneResourceTypeAllowed", flagutil.ResourceTypeFlagEntries...)
}

if resourceType != "" {
req = req.ResourceType(aclutil.GetMappedResourceTypeFilterValue(resourceType))
}

if resourceName != "" {
req = req.ResourceName(aclutil.GetResourceName(resourceName))
}

permissionsData, httpRes, err := req.Execute()
if httpRes != nil {
defer httpRes.Body.Close()
Expand All @@ -150,6 +192,12 @@ func runList(opts *options) (err error) {
return err
}

if permissionsData.GetTotal() == 0 && opts.output == "" {
opts.logger.Info(opts.localizer.MustLocalize("kafka.acl.list.log.info.noACLs", localize.NewEntry("InstanceName", kafkaInstance.GetName())))

return nil
}

switch opts.output {
case dump.EmptyFormat:
opts.logger.Info("")
Expand Down
6 changes: 6 additions & 0 deletions pkg/localize/locales/en/cmd/acl.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ $ rhoas kafka acl list --user foo_user

# Display Kafka ACL rules for a specific service account
$ rhoas kafka acl list --service-account srvc-acct-f20a7561-7426-4f5a-b5e7-0ef2db31e15b

# Display Kafka ACL rules for a specific resource
$ rhoas kafka acl list --topic foo_topic_name
'''

[kafka.acl.list.cmd.shortDescription]
Expand Down Expand Up @@ -163,6 +166,9 @@ one = 'is'
[kafka.acl.list.startsWith]
one = 'starts with'

[kafka.acl.list.log.info.noACLs]
one = 'No ACLs found in Kafka instance "{{.InstanceName}}'

[kafka.acl.grantPermissions]

[kafka.acl.grantPermissions.cmd.shortDescription]
Expand Down