Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions utilities/api/get_projects_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import requests
import sys
import json
import os


def get_deployments():
headers = {"Accept": "application/json", "Authorization": "Bearer " + SEMGREP_APP_TOKEN}

r = requests.get('https://semgrep.dev/api/v1/deployments',headers=headers)
if r.status_code != 200:
sys.exit(f'Get failed: {r.text}')
data = json.loads(r.text)
slug_name = data['deployments'][0].get('slug')
print("Accessing org: " + slug_name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep found a match

Suggested change
print("Accessing org: " + slug_name)
logging.info(("Accessing org: " + slug_name))
Ignore this finding from avoid_print_python_rule.

return slug_name

def get_projects(slug_name):

headers = {"Accept": "application/json", "Authorization": "Bearer " + SEMGREP_APP_TOKEN}

r = requests.get('https://semgrep.dev/api/v1/deployments/' + slug_name + '/projects',headers=headers)
if r.status_code != 200:
sys.exit(f'Get failed: {r.text}')
data = json.loads(r.text)
for project in data['projects']:
project_name = project['name']
print("************")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep found a match

Suggested change
print("************")
logging.info("************")
Ignore this finding from avoid_print_python_rule.

print(project_name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep found a match

Suggested change
print(project_name)
logging.info(project_name)
Ignore this finding from avoid_print_python_rule.

tags = project['tags']
for tag in tags:
print(tag)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep found a match

Suggested change
print(tag)
logging.info(tag)
Ignore this finding from avoid_print_python_rule.



if __name__ == "__main__":
try:
SEMGREP_APP_TOKEN = os.getenv("SEMGREP_APP_TOKEN")
except KeyError:
print("Please set the environment variable SEMGREP_APP_TOKEN")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep found a match

Suggested change
print("Please set the environment variable SEMGREP_APP_TOKEN")
logging.info("Please set the environment variable SEMGREP_APP_TOKEN")
Ignore this finding from avoid_print_python_rule.

sys.exit(1)
slug_name = get_deployments()
get_projects(slug_name)