Skip to content

Commit c7b5127

Browse files
author
Enda
authored
fix: use mapped lowercase values in ACL table (#1292)
1 parent ab64135 commit c7b5127

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

docs/commands/rhoas_kafka_acl.adoc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/commands/rhoas_kafka_acl_list.adoc

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kafka/aclutil/acl_table.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@ type permissionsRow struct {
1919
func MapACLsToTableRows(bindings []kafkainstanceclient.AclBinding, localizer localize.Localizer) []permissionsRow {
2020
rows := make([]permissionsRow, len(bindings))
2121

22-
for i, p := range bindings {
22+
// get the SDK => CLI key mappings
23+
permissionMap := GetPermissionTypeMap()
24+
reversedPermissionMap := make(map[kafkainstanceclient.AclPermissionType]string)
25+
for k, v := range permissionMap {
26+
reversedPermissionMap[v] = k
27+
}
28+
29+
// get the SDK => CLI key mappings
30+
operationMap := GetOperationMap()
31+
reversedOperationMap := make(map[kafkainstanceclient.AclOperation]string)
32+
for k, v := range operationMap {
33+
reversedOperationMap[v] = k
34+
}
2335

36+
// get the SDK => CLI key mappings
37+
resourceTypeMap := GetResourceTypeMap()
38+
reversedResourceTypeMap := make(map[kafkainstanceclient.AclResourceType]string)
39+
for k, v := range resourceTypeMap {
40+
reversedResourceTypeMap[v] = k
41+
}
42+
43+
for i, p := range bindings {
2444
description := formatTablePatternType(p.PatternType, localizer)
2545
row := permissionsRow{
2646
Principal: formatTablePrincipal(p.GetPrincipal(), localizer),
27-
Permission: string(p.GetPermission()),
28-
Operation: string(p.GetOperation()),
29-
Description: fmt.Sprintf("%s %s \"%s\"", p.GetResourceType(), description, p.GetResourceName()),
47+
Permission: reversedPermissionMap[p.GetPermission()],
48+
Operation: reversedOperationMap[p.GetOperation()],
49+
Description: fmt.Sprintf("%s %s \"%s\"", reversedResourceTypeMap[p.GetResourceType()], description, p.GetResourceName()),
3050
}
3151
rows[i] = row
3252
}

pkg/kafka/aclutil/enums.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ var resourceTypeFilterMap = map[string]kafkainstanceclient.AclResourceTypeFilter
1010
ResourceTypeTRANSACTIONAL_ID: kafkainstanceclient.ACLRESOURCETYPEFILTER_TRANSACTIONAL_ID,
1111
}
1212

13+
var resourceTypeMap = map[string]kafkainstanceclient.AclResourceType{
14+
ResourceTypeCLUSTER: kafkainstanceclient.ACLRESOURCETYPE_CLUSTER,
15+
ResourceTypeTOPIC: kafkainstanceclient.ACLRESOURCETYPE_TOPIC,
16+
ResourceTypeGROUP: kafkainstanceclient.ACLRESOURCETYPE_GROUP,
17+
ResourceTypeTRANSACTIONAL_ID: kafkainstanceclient.ACLRESOURCETYPE_TRANSACTIONAL_ID,
18+
}
19+
1320
var operationFilterMap = map[string]kafkainstanceclient.AclOperationFilter{
1421
OperationALL: kafkainstanceclient.ACLOPERATIONFILTER_ALL,
1522
OperationREAD: kafkainstanceclient.ACLOPERATIONFILTER_READ,
@@ -161,3 +168,8 @@ func getValidOperationsResponseMap() map[string]string {
161168
}
162169
return validOperationsResponseMap
163170
}
171+
172+
// GetResourceTypeMap gets the mappings for ACL resource types
173+
func GetResourceTypeMap() map[string]kafkainstanceclient.AclResourceType {
174+
return resourceTypeMap
175+
}

pkg/localize/locales/en/cmd/acl.en.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ one = 'Kafka ACL management for users and service accounts'
55
[kafka.acl.cmd.longDescription]
66
one = '''
77
Set of commands that will let you manage Kafka ACLs.
8-
By default, every users and service account have limited access to their Kafka instance (Only DESCRIBE permission is enabled for TOPIC, ACL, and GROUP).
8+
By default, every users and service account have limited access to their Kafka instance (Only describe permission is enabled for TOPIC, ACL, and GROUP).
99
'''
1010

1111
[kafka.acl.cmd.example]
@@ -141,10 +141,10 @@ By default, new Kafka instances contain the following ACLs:
141141
142142
PRINCIPAL (4) PERMISSION OPERATION DESCRIPTION
143143
---------------- ------------ ------------------ ----------------
144-
All accounts ALLOW DESCRIBE GROUP is "*"
145-
All accounts ALLOW DESCRIBE CLUSTER is "*"
146-
All accounts ALLOW DESCRIBE_CONFIGS TOPIC is "*"
147-
All accounts ALLOW DESCRIBE TOPIC is "*"
144+
All accounts allow describe group is "*"
145+
All accounts allow describe cluster is "*"
146+
All accounts allow describe-configs topic is "*"
147+
All accounts allow describe topic is "*"
148148
149149
These ACLs allow all accounts in the organization to view the Kafka instance permissions and to view topics and consumer groups in the instance, but not to produce or consume messages.
150150
@@ -155,7 +155,7 @@ The ACLs are displayed in a table by default. Alternatively, you can display the
155155
one = 'Format in which to display the Kafka ACL rules (choose from: "json", "yml", "yaml")'
156156

157157
[kafka.acl.list.allAccounts]
158-
one = 'All accounts'
158+
one = 'All Accounts'
159159

160160
[kafka.acl.list.is]
161161
one = 'is'

0 commit comments

Comments
 (0)