Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PTSB-11] Support filtering for project attributes #38

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ dist
.DS_Store
**/.DS_Store
tests/test_codeowners.py
test.csv
test*.csv
TODO
rules.yml
4 changes: 3 additions & 1 deletion snyk_tags/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import typer
from rich import print
from snyk import SnykClient
from typing import Dict

from snyk_tags import __app_name__, __version__

Expand Down Expand Up @@ -96,6 +97,7 @@ def apply_attributes_to_projects(
environment: list,
lifecycle: list,
tenant: str,
filters: Dict[str, any],
) -> None:
with create_client(token=token, tenant=tenant) as client:
for org_id in org_ids:
Expand All @@ -107,7 +109,7 @@ def apply_attributes_to_projects(
client_v3 = SnykClient(
token=token, url=base_url, version="2023-08-31~experimental"
)
params = {"limit": 100}
params = {"limit": 100, **filters}
projects = client_v3.get_rest_pages(
f"/orgs/{org_id}/projects", params=params
)
Expand Down
2 changes: 1 addition & 1 deletion snyk_tags/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def apply_tags_to_projects(
client_v3 = SnykClient(
token=token, url=base_url, version="2023-08-31~experimental"
)
params = {"limit": 100, "names_start_with": name, **filters}
params = {"limit": 100, **filters}
projects = client_v3.get_rest_pages(
f"/orgs/{org_id}/projects", params=params
)
Expand Down
13 changes: 13 additions & 0 deletions snyk_tags/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def target_attributes(
),
):
for path in file:
filters = {}
if path.is_file():
openfile = open(path)
if ".csv" in openfile.name:
Expand All @@ -115,6 +116,11 @@ def target_attributes(
criticality = row.get("criticality")
environment = row.get("environment")
lifecycle = row.get("lifecycle")
filters = {
attr: val
for attr, val in row.items()
if attr in ["target_reference", "origins", "types"]
}
typer.secho(
f"\nAdding the attributes {criticality}, {environment} and {lifecycle} to projects within {target} for easy filtering via the UI",
bold=True,
Expand All @@ -128,6 +134,7 @@ def target_attributes(
[environment],
[lifecycle],
tenant,
filters,
)
openfile.close()
elif ".json" in openfile.name:
Expand All @@ -138,6 +145,11 @@ def target_attributes(
criticality = row.get("criticality")
environment = row.get("environment")
lifecycle = row.get("lifecycle")
filters = {
attr: val
for attr, val in row.items()
if attr in ["target_reference", "origins", "types"]
}
typer.secho(
f"\nAdding the attributes {criticality}, {environment} and {lifecycle} to projects within {target} for easy filtering via the UI",
bold=True,
Expand All @@ -151,6 +163,7 @@ def target_attributes(
[environment],
[lifecycle],
tenant,
filters,
)
openfile.close()
else:
Expand Down
Loading