From 0b2d02388918c67354a311d9d02b708f1b6b3948 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:23:23 -0700 Subject: [PATCH 1/2] fix: remove 'names_start_with' as required param --- snyk_tags/collection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snyk_tags/collection.py b/snyk_tags/collection.py index 40817e6..e5c4342 100644 --- a/snyk_tags/collection.py +++ b/snyk_tags/collection.py @@ -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 ) From 3ec41538df7cbae8f841e294ba4830510e6e9f25 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:42:54 -0700 Subject: [PATCH 2/2] feat: add filtering for project attributes --- .gitignore | 2 +- snyk_tags/attribute.py | 4 +++- snyk_tags/files.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0840535..b8210ea 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,6 @@ dist .DS_Store **/.DS_Store tests/test_codeowners.py -test.csv +test*.csv TODO rules.yml \ No newline at end of file diff --git a/snyk_tags/attribute.py b/snyk_tags/attribute.py index b5f5fce..2e29365 100644 --- a/snyk_tags/attribute.py +++ b/snyk_tags/attribute.py @@ -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__ @@ -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: @@ -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 ) diff --git a/snyk_tags/files.py b/snyk_tags/files.py index d894197..bd9a332 100644 --- a/snyk_tags/files.py +++ b/snyk_tags/files.py @@ -105,6 +105,7 @@ def target_attributes( ), ): for path in file: + filters = {} if path.is_file(): openfile = open(path) if ".csv" in openfile.name: @@ -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, @@ -128,6 +134,7 @@ def target_attributes( [environment], [lifecycle], tenant, + filters, ) openfile.close() elif ".json" in openfile.name: @@ -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, @@ -151,6 +163,7 @@ def target_attributes( [environment], [lifecycle], tenant, + filters, ) openfile.close() else: