-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathacls.go
More file actions
96 lines (82 loc) · 2.74 KB
/
acls.go
File metadata and controls
96 lines (82 loc) · 2.74 KB
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
package confluent
import (
"bytes"
"encoding/json"
)
const (
aclsPath = "acls"
)
type Acl struct {
ClusterId string `json:"cluster_id,omitempty"`
ResourceType string `json:"resource_type,omitempty"`
ResourceName string `json:"resource_name,omitempty"`
PatternType string `json:"pattern_type,omitempty"`
Principal string `json:"principal,omitempty"`
Host string `json:"host,omitempty"`
Operation string `json:"operation,omitempty"`
Permission string `json:"permission,omitempty"`
}
// Returns a list of ACLs that match the search criteria.
// Parameters:
// cluster_id (string) – The Kafka cluster ID.
// Query Parameters:
// resource_type (string) – The ACL resource type.
// resource_name (string) – The ACL resource name.
// pattern_type (string) – The ACL pattern type.
// principal (string) – The ACL principal.
// host (string) – The ACL host.
// operation (string) – The ACL operation.
// permission (string) – The ACL permission.
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-acls
func (c *Client) ListAcls(clusterId string) ([]Acl, error) {
u := "/clusters/" + clusterId + "/" + aclsPath
r, err := c.DoRequest("GET", u, nil)
if err != nil {
return nil, err
}
body := struct{
Data []Acl `json:"data"`
}{}
err = json.Unmarshal(r, &body)
if err != nil {
return nil, err
}
return body.Data, nil
}
// Creates an ACL.
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#post--clusters-cluster_id-acls
func (c *Client) CreateAcl(clusterId string, aclConfig *Acl) error {
u := "/clusters/" + clusterId + "/" + aclsPath
payloadBuf := new(bytes.Buffer)
json.NewEncoder(payloadBuf).Encode(aclConfig)
_, err := c.DoRequest("POST", u, payloadBuf)
if err != nil {
return err
}
return nil
}
// Deletes the list of ACLs that matches the search criteria.
// Parameters:
// cluster_id (string) – The Kafka cluster ID.
// Query Parameters:
// resource_type (string) – The ACL resource type.
// resource_name (string) – The ACL resource name.
// pattern_type (string) – The ACL pattern type.
// principal (string) – The ACL principal.
// host (string) – The ACL host.
// operation (string) – The ACL operation.
// permission (string) – The ACL permission.
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#delete--clusters-cluster_id-acls
func (c *Client) DeleteAcl(clusterId, resourceName string) error {
u := "/clusters/" + clusterId + "/" + aclsPath
aclDetele := Acl{
ResourceName: resourceName,
}
payloadBuf := new(bytes.Buffer)
json.NewEncoder(payloadBuf).Encode(aclDetele)
_, err := c.DoRequest("DELETE", u, payloadBuf)
if err != nil {
return err
}
return nil
}