segmentio / topicctl

Tool for declarative management of Kafka topics
MIT License
590 stars 55 forks source link

feat: delete acl #167

Closed petedannemann closed 9 months ago

petedannemann commented 10 months ago

Add support for deleting ACLs.

Implementation details: Mutliple ACLs can be deleted at a time. The delete acls command requires all flags to be set to narrow down to desired ACLs to delete.

Demo:

$ topicctl get acls --resource-type topic --resource-pattern-type literal --resource-name my-topic --principal 'User:default' --host '*' --operation read --permission-type allow --cluster-config examples/auth/cluster.yaml
[2023-11-21 14:35:48]  INFO ACLs:
----------------+--------------+---------------+--------------+------+-----------+------------------
  RESOURCE TYPE | PATTERN TYPE | RESOURCE NAME |  PRINCIPAL   | HOST | OPERATION | PERMISSION TYPE
----------------+--------------+---------------+--------------+------+-----------+------------------
  topic         | literal      | my-topic      | User:default | *    | read      | allow
----------------+--------------+---------------+--------------+------+-----------+------------------
$ topicctl delete acls --resource-type topic --resource-pattern-type literal --resource-name my-topic --principal 'User:default' --host '*' --operation read --permission-type allow --cluster-config examples/auth/cluster.yaml
[2023-11-21 14:35:54]  INFO Checking if ACLs exists for filter:
{
  "ResourceTypeFilter": "Topic",
  "ResourceNameFilter": "my-topic",
  "ResourcePatternTypeFilter": "Literal",
  "PrincipalFilter": "User:default",
  "HostFilter": "*",
  "Operation": "Read",
  "PermissionType": "Allow"
}
[2023-11-21 14:35:54]  The following ACLs in the cluster are planned for deletion:
{
  "ResourceType": "topic",
  "ResourceName": "my-topic",
  "PatternType": "literal",
  "Principal": "User:default",
  "Host": "*",
  "Operation": "read",
  "PermissionType": "allow"
} 
Delete ACLs? (yes/no) yes
[2023-11-21 14:35:56]  INFO ACLs successfully deleted: {
  "Error": null,
  "ResourceType": "Topic",
  "ResourceName": "my-topic",
  "ResourcePatternType": "Literal",
  "Principal": "User:default",
  "Host": "*",
  "Operation": "Read",
  "PermissionType": "Allow"
}
$ topicctl get acls --resource-type topic --resource-pattern-type literal --resource-name my-topic --principal 'User:default' --host '*' --operation read --permission-type allow --cluster-config examples/auth/cluster.yaml
[2023-11-21 14:36:03]  INFO ACLs:
----------------+--------------+---------------+-----------+------+-----------+------------------
  RESOURCE TYPE | PATTERN TYPE | RESOURCE NAME | PRINCIPAL | HOST | OPERATION | PERMISSION TYPE
----------------+--------------+---------------+-----------+------+-----------+------------------
----------------+--------------+---------------+-----------+------+-----------+------------------