Skip to content

Commit 4258422

Browse files
authored
Merge pull request #2 from wayarmy/v0.1.1
Complete v0.1.1
2 parents fac7727 + 7561efe commit 4258422

21 files changed

Lines changed: 197 additions & 156 deletions

.idea/.gitignore

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

.idea/gonfluent.iml

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

.idea/modules.xml

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

.idea/vcs.xml

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

acls.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ type Acl struct {
2020
Permission string `json:"permission,omitempty"`
2121
}
2222

23+
// Returns a list of ACLs that match the search criteria.
24+
// Parameters:
25+
// cluster_id (string) – The Kafka cluster ID.
26+
// Query Parameters:
27+
// resource_type (string) – The ACL resource type.
28+
// resource_name (string) – The ACL resource name.
29+
// pattern_type (string) – The ACL pattern type.
30+
// principal (string) – The ACL principal.
31+
// host (string) – The ACL host.
32+
// operation (string) – The ACL operation.
33+
// permission (string) – The ACL permission.
34+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-acls
2335
func (c *Client) ListAcls(clusterId string) ([]Acl, error) {
2436
u := "/clusters/" + clusterId + "/" + aclsPath
2537
r, err := c.DoRequest("GET", u, nil)
@@ -39,6 +51,8 @@ func (c *Client) ListAcls(clusterId string) ([]Acl, error) {
3951
return body.Data, nil
4052
}
4153

54+
// Creates an ACL.
55+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#post--clusters-cluster_id-acls
4256
func (c *Client) CreateAcl(clusterId string, aclConfig *Acl) error {
4357
u := "/clusters/" + clusterId + "/" + aclsPath
4458

@@ -52,6 +66,18 @@ func (c *Client) CreateAcl(clusterId string, aclConfig *Acl) error {
5266
return nil
5367
}
5468

69+
// Deletes the list of ACLs that matches the search criteria.
70+
// Parameters:
71+
// cluster_id (string) – The Kafka cluster ID.
72+
// Query Parameters:
73+
// resource_type (string) – The ACL resource type.
74+
// resource_name (string) – The ACL resource name.
75+
// pattern_type (string) – The ACL pattern type.
76+
// principal (string) – The ACL principal.
77+
// host (string) – The ACL host.
78+
// operation (string) – The ACL operation.
79+
// permission (string) – The ACL permission.
80+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#delete--clusters-cluster_id-acls
5581
func (c *Client) DeleteAcl(clusterId, resourceName string) error {
5682
u := "/clusters/" + clusterId + "/" + aclsPath
5783

acls_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func TestAcls_ListAclsSuccess(t *testing.T) {
5353
}
5454
`), 200, "200 OK", nil
5555
}
56-
c := NewClient(&mock, &mk)
56+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
57+
c := NewClient(&mock, &mk, clusterAdmin)
5758
acls, err := c.ListAcls("cluster-1")
5859
assert.NoError(t, err)
5960
assert.Equal(t, 2, len(acls))
@@ -68,7 +69,8 @@ func TestAcls_CreateAclsSuccess(t *testing.T) {
6869
assert.Equal(t, "/clusters/cluster-1/acls", uri)
6970
return []byte(``), 201, "201", nil
7071
}
71-
c := NewClient(&mock, &mk)
72+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
73+
c := NewClient(&mock, &mk, clusterAdmin)
7274
aclConfig := Acl{}
7375
err := c.CreateAcl("cluster-1", &aclConfig)
7476
assert.NoError(t, err)
@@ -115,7 +117,8 @@ func TestAcls_DeleteAclSuccess(t *testing.T) {
115117
}
116118
`), 200, "200", nil
117119
}
118-
c := NewClient(&mock, &mk)
120+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
121+
c := NewClient(&mock, &mk, clusterAdmin)
119122
err := c.DeleteAcl("cluster-1", "")
120123
assert.NoError(t, err)
121124
}

authorize_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
},
2020
ResourceName: "Testing-Principal",
2121
ResourceType: "Cluster",
22-
Operation: "ClusterAdmin",
22+
Operation: "DefaultSaramaClusterAdmin",
2323
},
2424
}
2525
)
@@ -37,7 +37,8 @@ func TestAuthorize_CreatePrincipalSuccess(t *testing.T) {
3737
]
3838
`), 200, "200", nil
3939
}
40-
c := NewClient(&mock, &mk)
40+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
41+
c := NewClient(&mock, &mk, clusterAdmin)
4142
newPrincipal, err := c.CreatePrincipal("User:testing", testPrincipals)
4243
assert.NoError(t, err)
4344
assert.Equal(t, "Testing-Principal", newPrincipal.Actions[0].ResourceName)
@@ -64,7 +65,8 @@ func TestAuthorize_CreatePrincipalFail(t *testing.T) {
6465
}
6566
`), 400, "400 Bad Request", nil
6667
}
67-
c := NewClient(&mock, &mk)
68+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
69+
c := NewClient(&mock, &mk, clusterAdmin)
6870
newPrincipal, err := c.CreatePrincipal("User:testing", testPrincipals)
6971
assert.NotNil(t, err)
7072
assert.Nil(t, newPrincipal)

clusters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
// - Kafka connect cluster
1515
// - KSql cluster
1616
// - Schema Registry cluster
17+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#cluster
1718
type Clusters struct {
1819
// Kafka cluster ID
1920
KafkaCluster string `json:"kafka-cluster,omitempty"`
@@ -36,6 +37,10 @@ type Related struct {
3637
Related string `json:"related"`
3738
}
3839

40+
// Returns a list of known Kafka clusters. Currently both Kafka and Kafka REST Proxy are only aware
41+
// of the Kafka cluster pointed at by the bootstrap.servers configuration.
42+
// Therefore only one Kafka cluster will be returned in the response.
43+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters
3944
func (c *Client) ListKafkaCluster() ([]KafkaCluster, error) {
4045
resp, err := c.DoRequest("GET", clusterUri, nil)
4146
if err != nil {
@@ -54,6 +59,8 @@ func (c *Client) ListKafkaCluster() ([]KafkaCluster, error) {
5459
return body.Data, nil
5560
}
5661

62+
// Returns the Kafka cluster with the specified cluster_id.
63+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id
5764
func (c *Client) GetKafkaCluster(clusterId string) (*KafkaCluster, error) {
5865
pathUri := clusterUri + "/" + clusterId
5966
resp, err := c.DoRequest("GET", pathUri, nil)

clusters_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func TestClusters_ListKafkaCluster(t *testing.T) {
5656
}
5757
`), 200, "200 OK", nil
5858
}
59-
c := NewClient(&mock, &mk)
59+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
60+
c := NewClient(&mock, &mk, clusterAdmin)
6061
clusters, err := c.ListKafkaCluster()
6162
if assert.NoError(t, err) {
6263
assert.Equal(t, 1, len(clusters))
@@ -77,7 +78,8 @@ func TestClusters_GetNonExistingKafkaCluster(t *testing.T) {
7778
}
7879
`), 404, "404 Not Found", nil
7980
}
80-
c := NewClient(&mock, &mk)
81+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
82+
c := NewClient(&mock, &mk, clusterAdmin)
8183
cluster, err := c.GetKafkaCluster("cluster-1")
8284
assert.Equal(t, errors.New("error with status: 404 Not Found HTTP 404 Not Found"), err)
8385
assert.Nil(t, cluster)
@@ -121,7 +123,8 @@ func TestClusters_GetExistingKafkaCluster(t *testing.T) {
121123
}
122124
`), 200, "200 OK", nil
123125
}
124-
c := NewClient(&mock, &mk)
126+
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
127+
c := NewClient(&mock, &mk, clusterAdmin)
125128
cluster, err := c.GetKafkaCluster("cluster-1")
126129
if assert.NoError(t, err) {
127130
assert.Equal(t, "cluster-1", cluster.ClusterID)

configs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type Synonyms struct {
2424
Operation string `json:"operation,omitempty"`
2525
}
2626

27+
// @ref https://docs.confluent.io/platform/current/kafka-rest/api.html#get--clusters-cluster_id-topics-topic_name-configs
28+
// Return the list of configs that belong to the specified topic.
2729
func (c *Client) GetTopicConfigs(clusterId string, topicName string) ([]TopicConfig, error) {
2830
u := "/kafka/v3/clusters/" + clusterId + "/topics/" + topicName + "/configs"
2931

@@ -42,6 +44,8 @@ func (c *Client) GetTopicConfigs(clusterId string, topicName string) ([]TopicCon
4244
return res.Data, nil
4345
}
4446

47+
// @ref Return the list of configs that belong to the specified topic.
48+
// Updates or deletes a set of topic configs.
4549
func (c *Client) UpdateTopicConfigs(clusterId string, topicName string, data []TopicConfig) error {
4650
u := "/kafka/v3/clusters/" + clusterId + "/topics/" + topicName + "/configs:alter"
4751

0 commit comments

Comments
 (0)