Skip to content

Commit ecccd8c

Browse files
committed
Go report card
1 parent 64fcee6 commit ecccd8c

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# kafka-ops
22

33
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/agapoff/kafka-ops/blob/master/LICENSE)
4+
(https://goreportcard.com/report/github.com/agapoff/kafka-ops) ![GitHub release](https://img.shields.io/github/release/agapoff/kafka-ops.svg)
45

56
Yet another CLI utility to automate Kafka cluster management
67

main.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ var (
4040

4141
type arrFlags []string
4242

43+
// Spec contains the full structure of the manifest
4344
type Spec struct {
4445
Topics []Topic `yaml:"topics" json:"topics"`
4546
Acls []Acl `yaml:"acls" json:"acls"`
4647
Connection Connection `yaml:"connection,omitempty" json:"connection,omitempty"`
4748
}
4849

50+
// Topic describes single topic
4951
type Topic struct {
5052
Name string `yaml:"name" json:"name"`
5153
Partitions int `yaml:"partitions" json:"partitions"`
@@ -54,24 +56,28 @@ type Topic struct {
5456
State string `yaml:"state,omitempty" json:"state,omitempty"`
5557
}
5658

59+
// Acl describes single ACL
5760
type Acl struct {
5861
Principal string `yaml:"principal" json:"principal"`
5962
Permissions []Permission `yaml:"permissions" json:"permissions"`
6063
}
6164

65+
// Permission contains all permissions for a single resource (topic, group, cluster)
6266
type Permission struct {
6367
Resource Resource `yaml:"resource" json:"resource"`
6468
Allow []string `yaml:"allow_operations,omitempty,flow" json:"allow_operations,omitempty"`
6569
Deny []string `yaml:"deny_operations,omitempty" json:"deny_operations,omitempty"`
6670
State string `yaml:"state,omitempty" json:"state,omitempty"`
6771
}
6872

73+
// Resource contains the description of the resource (topic, group, cluster)
6974
type Resource struct {
7075
Type string `yaml:"type" json:"type"`
7176
Pattern string `yaml:"pattern" json:"pattern"`
7277
PatternType string `yaml:"patternType" json:"patternType"`
7378
}
7479

80+
// SingleACL contains one permission for a single resource
7581
type SingleACL struct {
7682
PermissionType string `json:"permission_type"`
7783
Principal string `json:"principal"`
@@ -81,6 +87,7 @@ type SingleACL struct {
8187
State string `json:"state"`
8288
}
8389

90+
// Connection describes the brokers settings defined in the manifest
8491
type Connection struct {
8592
Broker string `yaml:"broker,omitempty" json:"broker,omitempty"`
8693
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
@@ -89,8 +96,10 @@ type Connection struct {
8996
Password string `yaml:"password,omitempty" json:"password,omitempty"`
9097
}
9198

99+
// Exit is used for handling panics
92100
type Exit struct{ Code int }
93101

102+
// The values for coloring the output
94103
const (
95104
Ok = "\033[0;32m"
96105
Changed = "\033[0;33m"
@@ -239,6 +248,7 @@ func dumpSpec() error {
239248
return nil
240249
}
241250

251+
// AddAcl combines permissions with common Resource
242252
func (s *Spec) AddAcl(acl Acl) {
243253
for i, a := range s.Acls {
244254
if a.Principal == acl.Principal {
@@ -256,6 +266,7 @@ func (s *Spec) AddAcl(acl Acl) {
256266
s.Acls = append(s.Acls, acl)
257267
}
258268

269+
// Equals compares Resource structs
259270
func (r Resource) Equals(res Resource) bool {
260271
return r.Type == res.Type && r.Pattern == res.Pattern && r.PatternType == res.PatternType
261272
}
@@ -570,28 +581,27 @@ func alignAcl(admin *sarama.ClusterAdmin, acls *[]sarama.ResourceAcls, acl Singl
570581
}
571582
if len(mAcls) > 0 {
572583
return Changed, nil
573-
} else {
574-
return Ok, nil
575584
}
585+
return Ok, nil
576586
}
577587

578588
if aclExists(admin, acls, acl) {
579589
return Ok, nil
580-
} else {
581-
r := sarama.Resource{
582-
ResourceType: aclResourceTypeFromString(acl.Resource.Type),
583-
ResourceName: acl.Resource.Pattern,
584-
ResourcePatternType: aclResourcePatternTypeFromString(acl.Resource.PatternType),
585-
}
586-
a := sarama.Acl{
587-
Principal: acl.Principal,
588-
Host: acl.Host,
589-
Operation: aclOperationFromString(acl.Operation),
590-
PermissionType: aclPermissionTypeFromString(acl.PermissionType),
591-
}
592-
err := (*admin).CreateACL(r, a)
593-
return Changed, err
594590
}
591+
592+
r := sarama.Resource{
593+
ResourceType: aclResourceTypeFromString(acl.Resource.Type),
594+
ResourceName: acl.Resource.Pattern,
595+
ResourcePatternType: aclResourcePatternTypeFromString(acl.Resource.PatternType),
596+
}
597+
a := sarama.Acl{
598+
Principal: acl.Principal,
599+
Host: acl.Host,
600+
Operation: aclOperationFromString(acl.Operation),
601+
PermissionType: aclPermissionTypeFromString(acl.PermissionType),
602+
}
603+
err := (*admin).CreateACL(r, a)
604+
return Changed, err
595605
}
596606

597607
func aclExists(admin *sarama.ClusterAdmin, acls *[]sarama.ResourceAcls, acl SingleACL) bool {

scram_client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ import (
88
"github.com/xdg/scram"
99
)
1010

11+
// SHA256 contains hash function for SCRAM SHA256
1112
var SHA256 scram.HashGeneratorFcn = func() hash.Hash { return sha256.New() }
13+
14+
// SHA512 contains hash function for SCRAM SHA512
1215
var SHA512 scram.HashGeneratorFcn = func() hash.Hash { return sha512.New() }
1316

17+
// XDGSCRAMClient
1418
type XDGSCRAMClient struct {
1519
*scram.Client
1620
*scram.ClientConversation
1721
scram.HashGeneratorFcn
1822
}
1923

24+
// Begin the negotiation
2025
func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) {
2126
x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID)
2227
if err != nil {
@@ -26,11 +31,13 @@ func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) {
2631
return nil
2732
}
2833

34+
// Perform the step of negotiation
2935
func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) {
3036
response, err = x.ClientConversation.Step(challenge)
3137
return
3238
}
3339

40+
// Done the negotiation
3441
func (x *XDGSCRAMClient) Done() bool {
3542
return x.ClientConversation.Done()
3643
}

0 commit comments

Comments
 (0)