Skip to content

Commit

Permalink
Merge pull request #38 from Torsten1014/feature/PSTB-11
Browse files Browse the repository at this point in the history
[PTSB-11] Support filtering for project attributes
  • Loading branch information
EricFernandezSnyk authored Oct 7, 2024
2 parents 67b0b8a + 3ec4153 commit 546edde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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

0 comments on commit 546edde

Please sign in to comment.