Skip to content

Commit

Permalink
allow deleting multiple acls
Browse files Browse the repository at this point in the history
  • Loading branch information
petedannemann committed Dec 12, 2023
1 parent a32a02c commit 42f0d2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/topicctl/subcmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ var deleteACLsConfig = aclsCmdConfig{}

func deleteACLCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "acl [flags]",
Short: "Delete an ACL. Requires providing flags to only target a single ACL for deletion.",
Use: "acls [flags]",
Short: "Delete ACLs. Requires providing flags to target ACLs for deletion.",
Args: cobra.NoArgs,
Example: `Delete read acls for topic my-topic, user 'User:default', and host '*'
$ topicctl delete acl --resource-type topic --resource-pattern-type literal --resource-name my-topic --principal 'User:default' --host '*' --operation read --permission-type allow
$ topicctl delete acls --resource-type topic --resource-pattern-type literal --resource-name my-topic --principal 'User:default' --host '*' --operation read --permission-type allow
`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down
8 changes: 3 additions & 5 deletions pkg/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func formatNewACLsConfig(config []kafka.ACLEntry) string {

// Delete checks if ACLs exist and deletes them if they do.
func (a *ACLAdmin) Delete(ctx context.Context, filter kafka.DeleteACLsFilter) error {
log.Infof("Checking if ACL exists for filter:\n%+v", formatACLs(filter))
log.Infof("Checking if ACLs exists for filter:\n%+v", formatACLs(filter))

getFilter := kafka.ACLFilter{
ResourceTypeFilter: filter.ResourceTypeFilter,
Expand All @@ -166,17 +166,15 @@ func (a *ACLAdmin) Delete(ctx context.Context, filter kafka.DeleteACLsFilter) er
return fmt.Errorf("No ACL matches filter:\n%+v", formatACLs(filter))
}

log.Infof("ACLs exists in the cluster:\n%+v", formatACLInfos(clusterACLs))
log.Infof("%d ACLs in the cluster match the filter provided", len(clusterACLs))

if a.config.DryRun {
log.Infof("Would delete ACLs:\n%+v", formatACLInfos(clusterACLs))
return nil
}

// TODO: step through each ACL and prompt for deletion

// This isn't settable by the CLI for safety measures but allows for testability
confirm, err := util.Confirm("Delete ACLs?", a.config.SkipConfirm)
confirm, err := util.Confirm(fmt.Sprintf("Delete ACLs?\n%+v", formatACLInfos(clusterACLs)), a.config.SkipConfirm)
if err != nil {
return err
}
Expand Down

0 comments on commit 42f0d2f

Please sign in to comment.