Skip to content

Commit 7557927

Browse files
committed
load passed args
1 parent 69d5718 commit 7557927

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

sourceplusplus/SourcePlusPlus.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ def get_config_value(self, env, default, true_default):
2626
else:
2727
return true_default
2828

29-
def __init__(self, **kwargs):
29+
def __init__(self, args: dict = None):
30+
if args is None:
31+
args = {}
3032
probe_config_file = os.getenv("SPP_PROBE_CONFIG_FILE", "spp-probe.yml")
3133
probe_config = {}
3234
if os.path.exists(probe_config_file):
3335
probe_config = yaml.full_load(open(probe_config_file, "r"))
34-
else:
36+
37+
# ensure probe_config has required keys
38+
if probe_config.get("spp") is None:
3539
probe_config["spp"] = {}
40+
if probe_config.get("skywalking") is None:
3641
probe_config["skywalking"] = {}
42+
if probe_config["skywalking"].get("collector") is None:
3743
probe_config["skywalking"]["collector"] = {}
44+
if probe_config["skywalking"].get("agent") is None:
3845
probe_config["skywalking"]["agent"] = {}
3946

47+
# set default values
4048
probe_config["spp"]["probe_id"] = self.get_config_value(
4149
"SPP_PROBE_ID", probe_config["spp"].get("probe_id"), str(uuid.uuid4())
4250
)
@@ -46,12 +54,12 @@ def __init__(self, **kwargs):
4654
probe_config["spp"]["platform_port"] = self.get_config_value(
4755
"SPP_PLATFORM_PORT", probe_config["spp"].get("platform_port"), 5450
4856
)
49-
probe_config["spp"]["verify_host"] = self.get_config_value(
57+
probe_config["spp"]["verify_host"] = str(self.get_config_value(
5058
"SPP_TLS_VERIFY_HOST", probe_config["spp"].get("verify_host"), True
51-
)
52-
probe_config["spp"]["disable_tls"] = self.get_config_value(
59+
)).lower() == "true"
60+
probe_config["spp"]["disable_tls"] = str(self.get_config_value(
5361
"SPP_DISABLE_TLS", probe_config["spp"].get("disable_tls"), False
54-
)
62+
)).lower() == "true"
5563
probe_config["skywalking"]["agent"]["service_name"] = self.get_config_value(
5664
"SPP_SERVICE_NAME", probe_config["skywalking"]["agent"].get("service_name"), "spp"
5765
)
@@ -63,11 +71,20 @@ def __init__(self, **kwargs):
6371
probe_config["skywalking"]["collector"].get("backend_service"),
6472
skywalking_host + ":" + str(skywalking_port)
6573
)
66-
self.probe_config = probe_config
6774

75+
for key, val in args.items():
76+
tmp_config = probe_config
77+
loc = key.split(".")
78+
for i in range(len(loc)):
79+
if tmp_config.get(loc[i]) is None:
80+
tmp_config[loc[i]] = {}
81+
if i == len(loc) - 1:
82+
tmp_config[loc[i]] = val
83+
else:
84+
tmp_config = tmp_config[loc[i]]
85+
86+
self.probe_config = probe_config
6887
self.instrument_remote = None
69-
for key, val in kwargs.items():
70-
self.__dict__[key] = val
7188

7289
def attach(self):
7390
config.init(
@@ -88,7 +105,13 @@ def attach(self):
88105

89106
ssl_ctx = ssl.create_default_context(cadata=ca_data)
90107
ssl_ctx.check_hostname = self.probe_config["spp"]["verify_host"]
91-
ssl_ctx.verify_mode = ssl.CERT_NONE # todo: CERT_REQUIRED / load_verify_locations ?
108+
if self.probe_config["spp"]["disable_tls"] is True:
109+
ssl_ctx = None
110+
elif ssl_ctx.check_hostname is True:
111+
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
112+
else:
113+
ssl_ctx.verify_mode = ssl.CERT_NONE
114+
92115
eb = EventBus(
93116
host=self.probe_config["spp"]["platform_host"], port=self.probe_config["spp"]["platform_port"],
94117
ssl_context=ssl_ctx

0 commit comments

Comments
 (0)