Skip to content

Add search remove tags swati#108

Open
swati-sharma wants to merge 6 commits intomainfrom
add-search-remove-tags-swati
Open

Add search remove tags swati#108
swati-sharma wants to merge 6 commits intomainfrom
add-search-remove-tags-swati

Conversation

@swati-sharma
Copy link
Contributor

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

Copy link
Contributor

@armchairlinguist armchairlinguist left a comment

Choose a reason for hiding this comment

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

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 = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

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():
Copy link
Contributor

Choose a reason for hiding this comment

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

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we'd have this come in as a CLI option too, but I wouldn't block on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants