@@ -26,17 +26,25 @@ def get_config_value(self, env, default, true_default):
26
26
else :
27
27
return true_default
28
28
29
- def __init__ (self , ** kwargs ):
29
+ def __init__ (self , args : dict = None ):
30
+ if args is None :
31
+ args = {}
30
32
probe_config_file = os .getenv ("SPP_PROBE_CONFIG_FILE" , "spp-probe.yml" )
31
33
probe_config = {}
32
34
if os .path .exists (probe_config_file ):
33
35
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 :
35
39
probe_config ["spp" ] = {}
40
+ if probe_config .get ("skywalking" ) is None :
36
41
probe_config ["skywalking" ] = {}
42
+ if probe_config ["skywalking" ].get ("collector" ) is None :
37
43
probe_config ["skywalking" ]["collector" ] = {}
44
+ if probe_config ["skywalking" ].get ("agent" ) is None :
38
45
probe_config ["skywalking" ]["agent" ] = {}
39
46
47
+ # set default values
40
48
probe_config ["spp" ]["probe_id" ] = self .get_config_value (
41
49
"SPP_PROBE_ID" , probe_config ["spp" ].get ("probe_id" ), str (uuid .uuid4 ())
42
50
)
@@ -46,12 +54,12 @@ def __init__(self, **kwargs):
46
54
probe_config ["spp" ]["platform_port" ] = self .get_config_value (
47
55
"SPP_PLATFORM_PORT" , probe_config ["spp" ].get ("platform_port" ), 5450
48
56
)
49
- probe_config ["spp" ]["verify_host" ] = self .get_config_value (
57
+ probe_config ["spp" ]["verify_host" ] = str ( self .get_config_value (
50
58
"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 (
53
61
"SPP_DISABLE_TLS" , probe_config ["spp" ].get ("disable_tls" ), False
54
- )
62
+ )). lower () == "true"
55
63
probe_config ["skywalking" ]["agent" ]["service_name" ] = self .get_config_value (
56
64
"SPP_SERVICE_NAME" , probe_config ["skywalking" ]["agent" ].get ("service_name" ), "spp"
57
65
)
@@ -63,11 +71,20 @@ def __init__(self, **kwargs):
63
71
probe_config ["skywalking" ]["collector" ].get ("backend_service" ),
64
72
skywalking_host + ":" + str (skywalking_port )
65
73
)
66
- self .probe_config = probe_config
67
74
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
68
87
self .instrument_remote = None
69
- for key , val in kwargs .items ():
70
- self .__dict__ [key ] = val
71
88
72
89
def attach (self ):
73
90
config .init (
@@ -88,7 +105,13 @@ def attach(self):
88
105
89
106
ssl_ctx = ssl .create_default_context (cadata = ca_data )
90
107
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
+
92
115
eb = EventBus (
93
116
host = self .probe_config ["spp" ]["platform_host" ], port = self .probe_config ["spp" ]["platform_port" ],
94
117
ssl_context = ssl_ctx
0 commit comments