Skip to content

Commit 2106b39

Browse files
authored
Merge pull request #167 from dynatrace-oss/issue-166
Fixes #166
2 parents cae2004 + 5ee54c5 commit 2106b39

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

dtcli/scripts/dt.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,26 @@ def extension():
188188
"""
189189
Set of utilities for signing, building and uploading extensions.
190190
191-
\b
192191
Example flow:
193-
gencerts -> build -> upload
192+
1. (optional) When you don't have a developer certificate yet
193+
a) Generate CA key and certificate
194+
b) Generate developer key and certificate from the CA
195+
196+
$ dt ext genca
197+
$ dt ext generate-developer-pem --ca-crt ca.crt --ca-key ca.key -o dev.pem
198+
199+
2. Build and sign the extension
200+
201+
$ dt ext assemble
202+
$ dt ext sign --key dev.pem
203+
204+
3. (optional) Validate the assembled and signed bundle with your Dynatrace tenant
205+
206+
$ dt ext validate bundle.zip --tenant-url https://<tenantid>.live.dynatrace.com --api-token <token>
207+
208+
4. Upload the extension to your Dynatrace tenant
209+
210+
$ dt ext upload bundle.zip --tenant-url https://<tenantid>.live.dynatrace.com --api-token <token>
194211
"""
195212
pass
196213
# TODO: turn completion to True when implementing completion and somehow merge it with click

dtcli/server_api.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ def validate(extension_zip_file, tenant_url, api_token):
2121
url = f"{tenant_url}/api/v2/extensions?validateOnly=true"
2222

2323
with open(extension_zip_file, "rb") as extzf:
24-
headers = {"Accept": "application/json; charset=utf-8", "Authorization": f"Api-Token {api_token}"}
24+
headers = {
25+
"Accept": "application/json; charset=utf-8",
26+
'Content-Type': 'application/octet-stream',
27+
"Authorization": f"Api-Token {api_token}",
28+
}
2529
try:
26-
response = requests.post(
27-
url, files={"file": (extension_zip_file, extzf, "application/zip")}, headers=headers
28-
)
30+
extzf_data = extzf.read()
31+
response = requests.post(url, headers=headers, data=extzf_data)
2932
response.raise_for_status()
3033
print("Extension validation successful!")
3134
except requests.exceptions.HTTPError:
@@ -37,11 +40,14 @@ def upload(extension_zip_file, tenant_url, api_token):
3740
url = f"{tenant_url}/api/v2/extensions"
3841

3942
with open(extension_zip_file, "rb") as extzf:
40-
headers = {"Accept": "application/json; charset=utf-8", "Authorization": f"Api-Token {api_token}"}
43+
headers = {
44+
"Accept": "application/json; charset=utf-8",
45+
'Content-Type': 'application/octet-stream',
46+
"Authorization": f"Api-Token {api_token}",
47+
}
4148
try:
42-
response = requests.post(
43-
url, files={"file": (extension_zip_file, extzf, "application/zip")}, headers=headers
44-
)
49+
extzf_data = extzf.read()
50+
response = requests.post(url, headers=headers, data=extzf_data)
4551
response.raise_for_status()
4652
print("Extension upload successful!")
4753
except requests.exceptions.HTTPError:

0 commit comments

Comments
 (0)