Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with limit duplication leading to errors #204

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions snyk/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions snyk/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def _rest_to_v1_response_format(self, project):

def _query(self, tags: List[Dict[str, str]] = [], next_url: str = None):
projects = []
params: dict = {
"limit": 100,
}
params: dict = {"limit": 100}
if self.instance:
path = "/orgs/%s/projects" % self.instance.id if not next_url else next_url

Expand Down
7 changes: 7 additions & 0 deletions snyk/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)