Conversation
Reads the csv to put a tag against a given project.
armchairlinguist
left a comment
There was a problem hiding this comment.
I'm not comfortable with adding scripts that are essentially looking to hardcode the token - that's a practice we should avoid, and there are good examples in several places of other ways to approach it.
Can you also add a README to the folder with a small guide on using the functions?
| import csv | ||
| import requests | ||
|
|
||
| SEMGREP_API_KEY = "" |
There was a problem hiding this comment.
Can you set this up to get the value from the env var or settings YAML? There are related routines in quite a few of the existing utilities for this which you can base it on. Same for all these files.
| CSV_FILE = "projects_tags.csv" | ||
|
|
||
| # Headers for API request | ||
| def get_headers(): |
There was a problem hiding this comment.
I think this can be a constant here like it is in the other files, yeah? No need for a function.
| import requests | ||
|
|
||
| SEMGREP_API_KEY = "" | ||
| API_URL = "https://semgrep.dev/api/v1/deployments/{deployment-slug}/projects/{project_name}/tags" |
There was a problem hiding this comment.
Probably want to provide a way to get the deployment slug automatically too, either from the CLI or from the endpoint using the token. Same again for all the files.
| SEMGREP_API_KEY = "" | ||
| API_URL = "https://semgrep.dev/api/v1/deployments/{deployment-slug}/projects/{project_name}/tags" | ||
| # Path to your CSV file | ||
| CSV_FILE = "projects_tags.csv" |
There was a problem hiding this comment.
Ideally we'd have this come in as a CLI option too, but I wouldn't block on that.
addTagsUsingCSV.py reads a comma separated csv file (projects_tags.csv) with project and tag as headers and adds the tag mentioned against a project.
API used: https://semgrep.dev/api/v1/deployments/{deployment_slug}/projects/{project_name}/tags
method: PUT
searchForATag.py tags tag as an input parameter and lists all the projects that contains that tag (pagination applied)
API used: https://semgrep.dev/api/v1/deployments/{deployment_slug}/projects
removeTags.py reads a comma separated csv file (remove_tags) with project and tag as headers and remove the tag listed against a project
API used: https://semgrep.dev/api/v1/deployments/{deployment_slug}/projects/{project_name}/tags
method: DELETE