diff --git a/pyproject.toml b/pyproject.toml index 9b8c65b..c21557a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pysnyk" -version = "0.9.16" +version = "0.9.18" description = "A Python client for the Snyk API" authors = [ "Gareth Rushgrove ", diff --git a/snyk/client.py b/snyk/client.py index 8665ae0..e3fa329 100644 --- a/snyk/client.py +++ b/snyk/client.py @@ -1,6 +1,7 @@ import logging import urllib.parse from typing import Any, List, Optional +from urllib.parse import parse_qs, urlparse import requests from retry.api import retry_call @@ -162,6 +163,11 @@ def get( if isinstance(v, bool): params[k] = str(v).lower() + # the limit is returned in the url, and if two limits are passed + # the API interprets as an array and throws an error + if "limit" in parse_qs(urlparse(path).query): + params.pop("limit", None) + debug_url = f"{url}&{urllib.parse.urlencode(params)}" fkwargs = {"headers": self.api_headers, "params": params} else: diff --git a/snyk/managers.py b/snyk/managers.py index 4db2d89..e7bafd5 100644 --- a/snyk/managers.py +++ b/snyk/managers.py @@ -191,7 +191,7 @@ def _rest_to_v1_response_format(self, project): def _query(self, tags: List[Dict[str, str]] = [], next_url: str = None): projects = [] - params = {} + params: dict = {"limit": 100} if self.instance: path = "/orgs/%s/projects" % self.instance.id if not next_url else next_url diff --git a/snyk/test_client.py b/snyk/test_client.py index f97ab97..ec0bb93 100644 --- a/snyk/test_client.py +++ b/snyk/test_client.py @@ -322,3 +322,10 @@ def test_get_rest_pages( data = rest_client.get_rest_pages(f"orgs/{V3_ORG}/targets", t_params) assert len(data) == 30 + + def test_rest_limit_deduplication(self, requests_mock, rest_client): + requests_mock.get( + f"{REST_URL}/orgs/{REST_ORG}/projects?limit=100&version={REST_VERSION}" + ) + params = {"limit": 10} + rest_client.get(f"orgs/{REST_ORG}/projects?limit=100", params)