How to get a JSON report for SAST scan of python files?

Hi folks,

I am trying out Deeper SAST using SonarCloud. I forked and tried the “deeper-sast-demo” repository using GitHub Actions, and it worked. I have some sample Python files like sample1.py, sample2.py, etc., which I created to try out SAST. I have the Sonar CLI installed on my PC.

What I want is to scan these Python files either with the CLI or with Python code, and generate reports (for security) as JSON files.

I tried SonarQube Community Edition before and was able to generate reports for issues like “maintainability” using Python code like the example below:

api_url = f'{sonar_url}/api/issues/search?componentKeys={project_key}'
response = requests.get(api_url, auth=(sonar_token, ''))
issues = response.json()

Thanks in advance.

Sounds like you’re looking for SonarQube Cloud’s Web API, which is very similar to SonarQube Community Build’s Web API (you may find some minor differences).