dynatrace-oss / dt-cli

Command line tool for Dynatrace
https://pypi.org/project/dt-cli/
Apache License 2.0
17 stars 12 forks source link

`dt ext upload` sends a malformed POST request which unnecessarily wraps extension zip #166

Closed vduseev closed 8 months ago

vduseev commented 8 months ago

Describe the bug dt ext upload sends a malformed POST request which unnecessarily wraps extension zip

To Reproduce Steps to reproduce the behavior:

  1. dt ext upload after building and signing using dt-cli
  2. Download the uploaded build from cluster

ZIP downloaded from the cluster contains extra bytes. image

Expected behavior dt ext upload should upload built binary of archive as-is.

Additional context Add any other context about the problem here.

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}"}
        try:
            response = requests.post(
                url, files={"file": (extension_zip_file, extzf, "application/zip")}, headers=headers
            )
            response.raise_for_status()
            print("Extension upload successful!")
        except requests.exceptions.HTTPError:
            print("Extension upload failed!")
            raise dtcliutils.ExtensionValidationError(response.text)

We must replace the requests.post portion here with something like

curl -X 'POST' \
  'https://fys58062.dev.dynatracelabs.com/api/v2/extensions?validateOnly=false' \
  -H 'accept: application/json; charset=utf-8' \
  -H 'Content-Type: application/octet-stream' \
  --data-binary '@extension.zip'