forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acl_types.go
238 lines (214 loc) · 6.59 KB
/
acl_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package sarama
import (
"fmt"
"strings"
)
type (
AclOperation int
AclPermissionType int
AclResourceType int
AclResourcePatternType int
)
// ref: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/acl/AclOperation.java
const (
AclOperationUnknown AclOperation = iota
AclOperationAny
AclOperationAll
AclOperationRead
AclOperationWrite
AclOperationCreate
AclOperationDelete
AclOperationAlter
AclOperationDescribe
AclOperationClusterAction
AclOperationDescribeConfigs
AclOperationAlterConfigs
AclOperationIdempotentWrite
)
func (a *AclOperation) String() string {
mapping := map[AclOperation]string{
AclOperationUnknown: "Unknown",
AclOperationAny: "Any",
AclOperationAll: "All",
AclOperationRead: "Read",
AclOperationWrite: "Write",
AclOperationCreate: "Create",
AclOperationDelete: "Delete",
AclOperationAlter: "Alter",
AclOperationDescribe: "Describe",
AclOperationClusterAction: "ClusterAction",
AclOperationDescribeConfigs: "DescribeConfigs",
AclOperationAlterConfigs: "AlterConfigs",
AclOperationIdempotentWrite: "IdempotentWrite",
}
s, ok := mapping[*a]
if !ok {
s = mapping[AclOperationUnknown]
}
return s
}
// MarshalText returns the text form of the AclOperation (name without prefix)
func (a *AclOperation) MarshalText() ([]byte, error) {
return []byte(a.String()), nil
}
// UnmarshalText takes a text reprentation of the operation and converts it to an AclOperation
func (a *AclOperation) UnmarshalText(text []byte) error {
normalized := strings.ToLower(string(text))
mapping := map[string]AclOperation{
"unknown": AclOperationUnknown,
"any": AclOperationAny,
"all": AclOperationAll,
"read": AclOperationRead,
"write": AclOperationWrite,
"create": AclOperationCreate,
"delete": AclOperationDelete,
"alter": AclOperationAlter,
"describe": AclOperationDescribe,
"clusteraction": AclOperationClusterAction,
"describeconfigs": AclOperationDescribeConfigs,
"alterconfigs": AclOperationAlterConfigs,
"idempotentwrite": AclOperationIdempotentWrite,
}
ao, ok := mapping[normalized]
if !ok {
*a = AclOperationUnknown
return fmt.Errorf("no acl operation with name %s", normalized)
}
*a = ao
return nil
}
// ref: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/acl/AclPermissionType.java
const (
AclPermissionUnknown AclPermissionType = iota
AclPermissionAny
AclPermissionDeny
AclPermissionAllow
)
func (a *AclPermissionType) String() string {
mapping := map[AclPermissionType]string{
AclPermissionUnknown: "Unknown",
AclPermissionAny: "Any",
AclPermissionDeny: "Deny",
AclPermissionAllow: "Allow",
}
s, ok := mapping[*a]
if !ok {
s = mapping[AclPermissionUnknown]
}
return s
}
// MarshalText returns the text form of the AclPermissionType (name without prefix)
func (a *AclPermissionType) MarshalText() ([]byte, error) {
return []byte(a.String()), nil
}
// UnmarshalText takes a text reprentation of the permission type and converts it to an AclPermissionType
func (a *AclPermissionType) UnmarshalText(text []byte) error {
normalized := strings.ToLower(string(text))
mapping := map[string]AclPermissionType{
"unknown": AclPermissionUnknown,
"any": AclPermissionAny,
"deny": AclPermissionDeny,
"allow": AclPermissionAllow,
}
apt, ok := mapping[normalized]
if !ok {
*a = AclPermissionUnknown
return fmt.Errorf("no acl permission with name %s", normalized)
}
*a = apt
return nil
}
// ref: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/resource/ResourceType.java
const (
AclResourceUnknown AclResourceType = iota
AclResourceAny
AclResourceTopic
AclResourceGroup
AclResourceCluster
AclResourceTransactionalID
AclResourceDelegationToken
)
func (a *AclResourceType) String() string {
mapping := map[AclResourceType]string{
AclResourceUnknown: "Unknown",
AclResourceAny: "Any",
AclResourceTopic: "Topic",
AclResourceGroup: "Group",
AclResourceCluster: "Cluster",
AclResourceTransactionalID: "TransactionalID",
AclResourceDelegationToken: "DelegationToken",
}
s, ok := mapping[*a]
if !ok {
s = mapping[AclResourceUnknown]
}
return s
}
// MarshalText returns the text form of the AclResourceType (name without prefix)
func (a *AclResourceType) MarshalText() ([]byte, error) {
return []byte(a.String()), nil
}
// UnmarshalText takes a text reprentation of the resource type and converts it to an AclResourceType
func (a *AclResourceType) UnmarshalText(text []byte) error {
normalized := strings.ToLower(string(text))
mapping := map[string]AclResourceType{
"unknown": AclResourceUnknown,
"any": AclResourceAny,
"topic": AclResourceTopic,
"group": AclResourceGroup,
"cluster": AclResourceCluster,
"transactionalid": AclResourceTransactionalID,
"delegationtoken": AclResourceDelegationToken,
}
art, ok := mapping[normalized]
if !ok {
*a = AclResourceUnknown
return fmt.Errorf("no acl resource with name %s", normalized)
}
*a = art
return nil
}
// ref: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/resource/PatternType.java
const (
AclPatternUnknown AclResourcePatternType = iota
AclPatternAny
AclPatternMatch
AclPatternLiteral
AclPatternPrefixed
)
func (a *AclResourcePatternType) String() string {
mapping := map[AclResourcePatternType]string{
AclPatternUnknown: "Unknown",
AclPatternAny: "Any",
AclPatternMatch: "Match",
AclPatternLiteral: "Literal",
AclPatternPrefixed: "Prefixed",
}
s, ok := mapping[*a]
if !ok {
s = mapping[AclPatternUnknown]
}
return s
}
// MarshalText returns the text form of the AclResourcePatternType (name without prefix)
func (a *AclResourcePatternType) MarshalText() ([]byte, error) {
return []byte(a.String()), nil
}
// UnmarshalText takes a text reprentation of the resource pattern type and converts it to an AclResourcePatternType
func (a *AclResourcePatternType) UnmarshalText(text []byte) error {
normalized := strings.ToLower(string(text))
mapping := map[string]AclResourcePatternType{
"unknown": AclPatternUnknown,
"any": AclPatternAny,
"match": AclPatternMatch,
"literal": AclPatternLiteral,
"prefixed": AclPatternPrefixed,
}
arpt, ok := mapping[normalized]
if !ok {
*a = AclPatternUnknown
return fmt.Errorf("no acl resource pattern with name %s", normalized)
}
*a = arpt
return nil
}