forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
57 lines (48 loc) · 1.72 KB
/
configuration.go
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
package kafka
import (
"encoding/json"
)
type ConsumerConfiguration struct {
KeyDeserializer string `json:"keyDeserializer"`
ValueDeserializer string `json:"valueDeserializer"`
}
type ProducerConfiguration struct {
KeySerializer string `json:"keySerializer"`
ValueSerializer string `json:"valueSerializer"`
}
type Configuration struct {
Consumer ConsumerConfiguration `json:"consumer"`
Producer ProducerConfiguration `json:"producer"`
SchemaRegistry SchemaRegistryConfiguration `json:"schemaRegistry"`
}
// UnmarshalConfiguration unmarshalls the given JSON string into a Configuration.
func UnmarshalConfiguration(jsonConfiguration string) (Configuration, *Xk6KafkaError) {
var configuration Configuration
err := json.Unmarshal([]byte(jsonConfiguration), &configuration)
if err != nil {
return Configuration{}, NewXk6KafkaError(
configurationError, "Cannot unmarshal configuration.", err)
}
return configuration, nil
}
// ValidateConfiguration validates the given configuration.
func ValidateConfiguration(configuration Configuration) *Xk6KafkaError {
if (Configuration{}) == configuration {
// No configuration, fallback to default
return nil
}
if useSerializer(configuration, Key) || useSerializer(configuration, Value) {
return nil
}
return nil
}
// GivenCredentials returns true if the given configuration has credentials.
func GivenCredentials(configuration Configuration) bool {
if (Configuration{}) == configuration ||
(SchemaRegistryConfiguration{}) == configuration.SchemaRegistry ||
(BasicAuth{}) == configuration.SchemaRegistry.BasicAuth {
return false
}
return configuration.SchemaRegistry.BasicAuth.Username != "" &&
configuration.SchemaRegistry.BasicAuth.Password != ""
}