@@ -41,14 +41,15 @@ type arrFlags []string
41
41
type Spec struct {
42
42
Topics []Topic `yaml:"topics" json:"topics"`
43
43
Acls []Acl `yaml:"acls" json:"acls"`
44
+ Connection `yaml:"connection,omitempty" json:"connection,omitempty"`
44
45
}
45
46
46
47
type Topic struct {
47
48
Name string `yaml:"name" json:"name"`
48
49
Partitions int `yaml:"partitions" json:"partitions"`
49
50
ReplicationFactor int `yaml:"replication_factor" json:"replication_factor"`
50
51
Configs map [string ]string `yaml:"configs" json:"configs"`
51
- State string `yaml:"state" json:"state"`
52
+ State string `yaml:"state,omitempty " json:"state,omitempty "`
52
53
}
53
54
54
55
type Acl struct {
@@ -60,7 +61,7 @@ type Permission struct {
60
61
Resource `yaml:"resource" json:"resource"`
61
62
Allow []string `yaml:"allow_operations,omitempty,flow" json:"allow_operations,omitempty"`
62
63
Deny []string `yaml:"deny_operations,omitempty" json:"deny_operations,omitempty"`
63
- State string `yaml:"state" json:"state"`
64
+ State string `yaml:"state,omitempty " json:"state,omitempty "`
64
65
}
65
66
66
67
type Resource struct {
@@ -78,6 +79,14 @@ type SingleACL struct {
78
79
State string `json:"state"`
79
80
}
80
81
82
+ type Connection struct {
83
+ Broker string `yaml:"broker,omitempty" json:"broker,omitempty"`
84
+ Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
85
+ Mechanism string `yaml:"mechanism,omitempty" json:"mechanism,omitempty"`
86
+ Username string `yaml:"username,omitempty" json:"username,omitempty"`
87
+ Password string `yaml:"password,omitempty" json:"password,omitempty"`
88
+ }
89
+
81
90
type Exit struct { Code int }
82
91
83
92
const (
@@ -123,7 +132,7 @@ func init() {
123
132
}
124
133
if broker == "" {
125
134
broker = loadEnvVar ("KAFKA_BROKER" )
126
- if broker == "" {
135
+ if broker == "" && actionDump {
127
136
broker = "localhost:9092"
128
137
}
129
138
}
@@ -151,19 +160,15 @@ func main() {
151
160
//defer fmt.Println("closed")
152
161
153
162
if actionApply {
154
- admin := connectToKafkaCluster ()
155
- defer func () { _ = (* admin ).Close () }()
156
- err := applySpecFile (admin )
163
+ err := applySpecFile ()
157
164
if err != nil {
158
165
if err .Error () != "" {
159
166
fmt .Println (err .Error ())
160
167
}
161
168
panic (Exit {2 })
162
169
}
163
170
} else if actionDump {
164
- admin := connectToKafkaCluster ()
165
- defer func () { _ = (* admin ).Close () }()
166
- err := dumpSpec (admin )
171
+ err := dumpSpec ()
167
172
if err != nil {
168
173
if err .Error () != "" {
169
174
fmt .Println (err .Error ())
@@ -220,7 +225,9 @@ func handleExit() {
220
225
}
221
226
}
222
227
223
- func dumpSpec (admin * sarama.ClusterAdmin ) error {
228
+ func dumpSpec () error {
229
+ admin := connectToKafkaCluster ()
230
+ defer func () { _ = (* admin ).Close () }()
224
231
// Get current topics from broker
225
232
currentTopics , err := (* admin ).ListTopics ()
226
233
if err != nil {
@@ -334,14 +341,36 @@ func listAllAcls(admin *sarama.ClusterAdmin) ([]sarama.ResourceAcls,error) {
334
341
return currentAcls , nil
335
342
}
336
343
337
- func applySpecFile (admin * sarama. ClusterAdmin ) error {
344
+ func applySpecFile () error {
338
345
var numOk , numChanged , numError int
339
346
340
347
spec , err := parseSpecFile ()
341
348
if err != nil {
342
349
return errors .New ("Can't parse spec manifest: " + err .Error ())
343
350
}
344
351
352
+ if spec .Connection .Broker != "" {
353
+ broker = spec .Connection .Broker
354
+ }
355
+ if spec .Connection .Protocol != "" {
356
+ protocol = spec .Connection .Protocol
357
+ }
358
+ if spec .Connection .Mechanism != "" {
359
+ mechanism = spec .Connection .Mechanism
360
+ }
361
+ if spec .Connection .Username != "" {
362
+ username = spec .Connection .Username
363
+ }
364
+ if spec .Connection .Password != "" {
365
+ password = spec .Connection .Password
366
+ }
367
+ if broker == "" {
368
+ broker = "localhost:9092"
369
+ }
370
+
371
+ admin := connectToKafkaCluster ()
372
+ defer func () { _ = (* admin ).Close () }()
373
+
345
374
// Get number of brokers
346
375
brokers , _ , err := (* admin ).DescribeCluster ()
347
376
if err != nil {
0 commit comments