From 6819d45a16ee68f2dcc2f5fc226e9220bb18d6d6 Mon Sep 17 00:00:00 2001 From: Sebastian Revuelta Date: Wed, 3 Jan 2024 17:35:02 +0100 Subject: [PATCH] print tags for projects --- utilities/api/get_projects_tags.py | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 utilities/api/get_projects_tags.py diff --git a/utilities/api/get_projects_tags.py b/utilities/api/get_projects_tags.py new file mode 100644 index 0000000..e796a99 --- /dev/null +++ b/utilities/api/get_projects_tags.py @@ -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) + 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("************") + print(project_name) + tags = project['tags'] + for tag in tags: + print(tag) + + +if __name__ == "__main__": + try: + SEMGREP_APP_TOKEN = os.getenv("SEMGREP_APP_TOKEN") + except KeyError: + print("Please set the environment variable SEMGREP_APP_TOKEN") + sys.exit(1) + slug_name = get_deployments() + get_projects(slug_name) \ No newline at end of file