Skip to content

Commit

Permalink
Merge pull request #167 from dynatrace-oss/issue-166
Browse files Browse the repository at this point in the history
Fixes #166
  • Loading branch information
vduseev authored Feb 22, 2024
2 parents cae2004 + 5ee54c5 commit 2106b39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
21 changes: 19 additions & 2 deletions dtcli/scripts/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,26 @@ def extension():
"""
Set of utilities for signing, building and uploading extensions.
\b
Example flow:
gencerts -> build -> upload
1. (optional) When you don't have a developer certificate yet
a) Generate CA key and certificate
b) Generate developer key and certificate from the CA
$ dt ext genca
$ dt ext generate-developer-pem --ca-crt ca.crt --ca-key ca.key -o dev.pem
2. Build and sign the extension
$ dt ext assemble
$ dt ext sign --key dev.pem
3. (optional) Validate the assembled and signed bundle with your Dynatrace tenant
$ dt ext validate bundle.zip --tenant-url https://<tenantid>.live.dynatrace.com --api-token <token>
4. Upload the extension to your Dynatrace tenant
$ dt ext upload bundle.zip --tenant-url https://<tenantid>.live.dynatrace.com --api-token <token>
"""
pass
# TODO: turn completion to True when implementing completion and somehow merge it with click
Expand Down
22 changes: 14 additions & 8 deletions dtcli/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ def validate(extension_zip_file, tenant_url, api_token):
url = f"{tenant_url}/api/v2/extensions?validateOnly=true"

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

with open(extension_zip_file, "rb") as extzf:
headers = {"Accept": "application/json; charset=utf-8", "Authorization": f"Api-Token {api_token}"}
headers = {
"Accept": "application/json; charset=utf-8",
'Content-Type': 'application/octet-stream',
"Authorization": f"Api-Token {api_token}",
}
try:
response = requests.post(
url, files={"file": (extension_zip_file, extzf, "application/zip")}, headers=headers
)
extzf_data = extzf.read()
response = requests.post(url, headers=headers, data=extzf_data)
response.raise_for_status()
print("Extension upload successful!")
except requests.exceptions.HTTPError:
Expand Down

0 comments on commit 2106b39

Please sign in to comment.