From 1a402b5dca3d4fad3304ed227fe8a920112fe6f2 Mon Sep 17 00:00:00 2001 From: Nathan Roys Date: Mon, 11 Sep 2023 14:38:07 +0100 Subject: [PATCH] fix: fix issue where duplicate query params were passed to paginated queries --- snyk/client.py | 7 +++++-- snyk/utils.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/snyk/client.py b/snyk/client.py index 4c3df5d..d3cc63f 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,9 @@ 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: