From c6ba7d8c6c33365d3dfa61be9ab96b21f1b6cc39 Mon Sep 17 00:00:00 2001 From: Nathan Roys Date: Mon, 11 Sep 2023 14:36:02 +0100 Subject: [PATCH] fix: fix issue where duplicate query params were passed to paginated queries --- snyk/client.py | 5 +++-- snyk/utils.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/snyk/client.py b/snyk/client.py index 4c3df5d..6620f1b 100644 --- a/snyk/client.py +++ b/snyk/client.py @@ -123,6 +123,7 @@ def get( params: dict = None, version: str = None, exclude_version: bool = False, + exclude_params: bool = False, ) -> requests.Response: """ Rest (formerly v3) Compatible Snyk Client, assumes the presence of Version, either set in the client @@ -146,7 +147,7 @@ def get( else: url = f"{self.api_url}/{path}" - if params or self.version: + if (params or self.version) and not exclude_params: if not params: params = {} @@ -223,7 +224,7 @@ def get_rest_pages(self, path: str, params: dict = {}) -> List: next_url = page_data.get("links", {}).get("next") # The next url comes back fully formed (i.e. with all the params already set, so no need to do it here) - next_page_response = self.get(next_url, {}, exclude_version=True) + next_page_response = self.get(next_url, {}, exclude_version=True, exclude_params=True) page_data = next_page_response.json() return_data.extend(page_data["data"]) logger.debug( diff --git a/snyk/utils.py b/snyk/utils.py index 28113ef..4ec3316 100644 --- a/snyk/utils.py +++ b/snyk/utils.py @@ -33,7 +33,12 @@ def cleanup_path(path: str) -> str: if path[-1] == "/": path = path.rstrip("/") - return path + # Ensure we remove "rest/" from next urls + parts = path.split("/") + if parts[0] == "rest": + parts.pop(0) + + return "/".join(parts) def load_test_data(test_dir: str, test_name: str) -> dict: