@@ -40,12 +40,14 @@ var (
40
40
41
41
type arrFlags []string
42
42
43
+ // Spec contains the full structure of the manifest
43
44
type Spec struct {
44
45
Topics []Topic `yaml:"topics" json:"topics"`
45
46
Acls []Acl `yaml:"acls" json:"acls"`
46
47
Connection Connection `yaml:"connection,omitempty" json:"connection,omitempty"`
47
48
}
48
49
50
+ // Topic describes single topic
49
51
type Topic struct {
50
52
Name string `yaml:"name" json:"name"`
51
53
Partitions int `yaml:"partitions" json:"partitions"`
@@ -54,24 +56,28 @@ type Topic struct {
54
56
State string `yaml:"state,omitempty" json:"state,omitempty"`
55
57
}
56
58
59
+ // Acl describes single ACL
57
60
type Acl struct {
58
61
Principal string `yaml:"principal" json:"principal"`
59
62
Permissions []Permission `yaml:"permissions" json:"permissions"`
60
63
}
61
64
65
+ // Permission contains all permissions for a single resource (topic, group, cluster)
62
66
type Permission struct {
63
67
Resource Resource `yaml:"resource" json:"resource"`
64
68
Allow []string `yaml:"allow_operations,omitempty,flow" json:"allow_operations,omitempty"`
65
69
Deny []string `yaml:"deny_operations,omitempty" json:"deny_operations,omitempty"`
66
70
State string `yaml:"state,omitempty" json:"state,omitempty"`
67
71
}
68
72
73
+ // Resource contains the description of the resource (topic, group, cluster)
69
74
type Resource struct {
70
75
Type string `yaml:"type" json:"type"`
71
76
Pattern string `yaml:"pattern" json:"pattern"`
72
77
PatternType string `yaml:"patternType" json:"patternType"`
73
78
}
74
79
80
+ // SingleACL contains one permission for a single resource
75
81
type SingleACL struct {
76
82
PermissionType string `json:"permission_type"`
77
83
Principal string `json:"principal"`
@@ -81,6 +87,7 @@ type SingleACL struct {
81
87
State string `json:"state"`
82
88
}
83
89
90
+ // Connection describes the brokers settings defined in the manifest
84
91
type Connection struct {
85
92
Broker string `yaml:"broker,omitempty" json:"broker,omitempty"`
86
93
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
@@ -89,8 +96,10 @@ type Connection struct {
89
96
Password string `yaml:"password,omitempty" json:"password,omitempty"`
90
97
}
91
98
99
+ // Exit is used for handling panics
92
100
type Exit struct { Code int }
93
101
102
+ // The values for coloring the output
94
103
const (
95
104
Ok = "\033 [0;32m"
96
105
Changed = "\033 [0;33m"
@@ -239,6 +248,7 @@ func dumpSpec() error {
239
248
return nil
240
249
}
241
250
251
+ // AddAcl combines permissions with common Resource
242
252
func (s * Spec ) AddAcl (acl Acl ) {
243
253
for i , a := range s .Acls {
244
254
if a .Principal == acl .Principal {
@@ -256,6 +266,7 @@ func (s *Spec) AddAcl(acl Acl) {
256
266
s .Acls = append (s .Acls , acl )
257
267
}
258
268
269
+ // Equals compares Resource structs
259
270
func (r Resource ) Equals (res Resource ) bool {
260
271
return r .Type == res .Type && r .Pattern == res .Pattern && r .PatternType == res .PatternType
261
272
}
@@ -570,28 +581,27 @@ func alignAcl(admin *sarama.ClusterAdmin, acls *[]sarama.ResourceAcls, acl Singl
570
581
}
571
582
if len (mAcls ) > 0 {
572
583
return Changed , nil
573
- } else {
574
- return Ok , nil
575
584
}
585
+ return Ok , nil
576
586
}
577
587
578
588
if aclExists (admin , acls , acl ) {
579
589
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
594
590
}
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
595
605
}
596
606
597
607
func aclExists (admin * sarama.ClusterAdmin , acls * []sarama.ResourceAcls , acl SingleACL ) bool {
0 commit comments