-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka_connect_config_generator.py
65 lines (58 loc) · 2.38 KB
/
kafka_connect_config_generator.py
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
58
59
60
61
62
63
64
65
#! /bin/python3.8
import os
script_path = os.path.dirname(os.path.abspath(__file__))
env_prefix = "CONNECT"
properties_file_name = "kafka-connect"
configs_override = {
"client.id" : "kafka_upgrade_simulation",
"producer.client.id" : "kafka_upgrade_simulation",
"consumer.client.id" : "kafka_upgrade_simulation",
"key.converter.schema.registry.url" : "'http://schema-registry:8081'",
"value.converter.schema.registry.url" : "'http://schema-registry:8081'",
"rest.advertised.host.name" : "\"debezium\"",
"security.protocol" : "SASL_PLAINTEXT",
"sasl.jaas.config" : "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"debezium\" password=\"12345\";",
"sasl.mechanism" : "SCRAM-SHA-512",
"producer.security.protocol" : "SASL_PLAINTEXT",
"producer.sasl.jaas.config" : "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"debezium\" password=\"12345\";",
"producer.sasl.mechanism" : "SCRAM-SHA-512",
"consumer.security.protocol" : "SASL_PLAINTEXT",
"consumer.sasl.jaas.config" : "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"debezium\" password=\"12345\";",
"consumer.sasl.mechanism" : "SCRAM-SHA-512"
}
configs_extra = [
"BOOTSTRAP_SERVERS=kafka1:9092,kafka2:9092,kafka3:9092",
"GROUP_ID=1",
"CONFIG_STORAGE_TOPIC=my_connect_configs",
"OFFSET_STORAGE_TOPIC=my_connect_offsets",
"STATUS_STORAGE_TOPIC=my_connect_statuses",
"INTERNAL_KEY_CONVERTER=org.apache.kafka.connect.json.JsonConverter",
"INTERNAL_VALUE_CONVERTER=org.apache.kafka.connect.json.JsonConverter"
]
configs_to_ignore:list[str] = []
with open(
os.path.join(script_path,properties_file_name+'.properties')
) as fp:
configs_raw = fp.readlines()
configs = ""
for line in configs_raw:
if line.strip() == '' or line.startswith("#"):
continue
else:
conf_val_raw = line.strip().split('=')
conf = conf_val_raw[0]
if conf in configs_to_ignore:
continue
elif conf in configs_override:
val = configs_override[conf]
else:
val = '='.join(conf_val_raw[1:])
configs += f"{env_prefix}_{conf.replace('.','_').upper()}={val}\n"
for c in configs_extra:
configs += c+'\n'
configs = configs.strip('\n')
with open(
os.path.join(script_path,f"{properties_file_name}.env"),
"w"
) as fp:
fp.write(configs)