Skip to content

Commit

Permalink
fix: fix issue where duplicate query params were passed to paginated …
Browse files Browse the repository at this point in the history
…queries
  • Loading branch information
nathan-roys committed Sep 11, 2023
1 parent 20ba57f commit c6ba7d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions snyk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion snyk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c6ba7d8

Please sign in to comment.