Skip to content

Commit 1a2e055

Browse files
authored
Merge pull request #4 from sourceplusplus/load-args
Load args
2 parents a35c3f2 + 5262089 commit 1a2e055

File tree

8 files changed

+71
-22
lines changed

8 files changed

+71
-22
lines changed

.github/workflows/e2e.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ jobs:
2525
- run: |
2626
PROBE_VERSION="$(python setup.py --version)"
2727
echo "SPP_PROBE_VERSION=$PROBE_VERSION" >> $GITHUB_ENV
28-
- run: python setup.py sdist
29-
- run: cp dist/sourceplusplus-${{ env.SPP_PROBE_VERSION }}.tar.gz e2e
30-
- run: cd e2e && docker-compose up -d
28+
29+
- run: ./gradlew assembleUp
30+
3131
- name: Docker IPs
3232
run: docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
3333
- name: Set E2E_APP_HOST
34-
run: E2E_APP_HOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aqf "name=e2e_e2e-test_1")) && echo "E2E_APP_HOST=$E2E_APP_HOST" >> $GITHUB_ENV
34+
run: E2E_APP_HOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aqf "name=e2e-test")) && echo "E2E_APP_HOST=$E2E_APP_HOST" >> $GITHUB_ENV
3535
- name: Set SPP_PLATFORM_HOST
3636
run: SPP_PLATFORM_HOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aqf "name=spp-platform")) && echo "SPP_PLATFORM_HOST=$SPP_PLATFORM_HOST" >> $GITHUB_ENV
3737
- name: Wait for platform

build.gradle.kts

+24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
plugins {
22
id("ru.vyarus.use-python") version "2.3.0"
3+
id("com.avast.gradle.docker-compose")
34
}
45

56
python {
67
pip("apache-skywalking:0.7.0")
78
pip("vertx-eventbus-client:1.0.0")
89
}
10+
11+
tasks {
12+
register<Exec>("buildDist") {
13+
commandLine("sh", "-c", "python setup.py sdist")
14+
}
15+
16+
register<Copy>("updateDockerFiles") {
17+
dependsOn("buildDist")
18+
from("dist/")
19+
into("e2e/")
20+
}
21+
22+
register("assembleUp") {
23+
dependsOn("updateDockerFiles", "composeUp")
24+
}
25+
getByName("composeUp").mustRunAfter("updateDockerFiles")
26+
}
27+
28+
dockerCompose {
29+
dockerComposeWorkingDirectory.set(File("./e2e"))
30+
removeVolumes.set(true)
31+
waitForTcpPorts.set(false)
32+
}

e2e/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ RUN pip install Flask
66
RUN pip install PyYAML
77
RUN pip install vertx-eventbus-client
88

9-
COPY sourceplusplus-0.1.2.tar.gz .
9+
COPY sourceplusplus-0.1.3.tar.gz .
1010

11-
RUN pip install sourceplusplus-0.1.2.tar.gz
11+
RUN pip install sourceplusplus-0.1.3.tar.gz
1212

1313
COPY E2ETest.py .
1414

e2e/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: '3.3'
22
services:
33
e2e-test:
4+
container_name: e2e-test
45
build:
56
context: .
67
depends_on:

settings.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pluginManagement {
2+
plugins {
3+
id 'com.avast.gradle.docker-compose' version "0.14.9" apply false
4+
}
5+
}

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup
33

44
setup(name='sourceplusplus',
5-
version='0.1.2',
5+
version='0.1.3',
66
description='Source++ Python Probe',
77
url='https://github.com/sourceplusplus/probe-python',
88
author='Source++',

sourceplusplus/SourcePlusPlus.py

+33-10
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

sourceplusplus/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
__version__ = '0.1.2'
1+
__version__ = '0.1.3'
22
__name__ = 'Source++'
33
agent_name = 'Source++ Python Probe'
4-
5-
__version_major__ = '0'
6-
__version_minor__ = '1'
7-
__version_micro__ = '2'

0 commit comments

Comments
 (0)