pro-100-bro
pro-100-bro

Reputation: 11

How can I upload archived source code to Checkmarx SAST using the API

I tried to upload the zipped source code to Checkmarx SAST in the following two ways:

  1. Default endpoint according to the official documentation: documentation
import requests

def upload_source(token: str, path_to_archive: str, host: str, project_id: int) -> None:
    headers = {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Accept': 'application/json;v=1.0',
      'Authorization': 'Bearer {token}'
    }

    data = {'zippedSource': open(path_to_archive, 'rb').read()}

    response = requests.post(f'{host}/projects/{project_id}/sourceCode/attachments', 
    headers=headers, data=data)
  1. CheckmarxPythonSDK library: pypi page:
from CheckmarxPythonSDK.CxRestAPISDK import ProjectsAPI

def upload_source(path_to_archive: str, project_id: int) -> None:

    cx_loader = ProjectsAPI()
    cx_loader.upload_source_code_zip_file(project_id, path_to_archive)

In both cases I received the same errors:

{
  "messageCode": 27000,
  "messageDetails": "The requested file not found in Http-Message body"
}

The SDK uses the following parts of the request to download the file. I tried using them with python.requests module instead of the documentation examples but got no changes:

data = {"zippedSource": ("archive_name", open('path_to_arhive', 'rb'), "application/zip")}
headers = {
    'Content-Type': 'multipart/form-data; boundary=1d8174c7f75344e0b5dcd64a9f874c1a',
    'cxOrigin': 'Checkmarx Python SDK 1.0.5',
    'Authorization': f'Bearer {token}'
}

Using different archivers also had no effect:

  1. 7zip
  2. python.shutil.make_archive()
  3. Cx7zip

I can't understand the problem. It could be wrong headers, wrong file management or something else...

Hope you can help. I ran the script from WSL (Ubuntu).

Upvotes: 1

Views: 42

Answers (0)

Related Questions