Skip to content

Commit

Permalink
Let the user choose the tenant (US, EU, etc). REST_API_URL as user pa…
Browse files Browse the repository at this point in the history
…rameter.
  • Loading branch information
clem-decath authored and garethr committed Jan 13, 2024
1 parent 29b5c06 commit 5d41a71
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions snyk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
self,
token: str,
url: Optional[str] = None,
rest_api_url: Optional[str] = None,
user_agent: Optional[str] = USER_AGENT,
debug: bool = False,
tries: int = 1,
Expand All @@ -34,6 +35,7 @@ def __init__(
):
self.api_token = token
self.api_url = url or self.API_URL
self.rest_api_url = rest_api_url or self.REST_API_URL
self.api_headers = {
"Authorization": "token %s" % self.api_token,
"User-Agent": user_agent,
Expand All @@ -45,10 +47,13 @@ def __init__(
self.delay = delay
self.verify = verify
self.version = version

# Ensure we don't have a trailing /
if self.api_url[-1] == "/":
self.api_url = self.api_url.rstrip("/")

if self.rest_api_url[-1] == "/":
self.rest_api_url = self.rest_api_url.rstrip("/")

if debug:
logging.basicConfig(level=logging.DEBUG)

Expand Down Expand Up @@ -141,9 +146,9 @@ def get(
# When calling a "next page" link, it fails if a version parameter is appended on to the URL - this is a
# workaround to prevent that from happening...
if exclude_version:
url = f"{self.REST_API_URL}/{path}"
url = f"{self.rest_api_url}/{path}"
else:
url = f"{self.REST_API_URL}/{path}?version={version}"
url = f"{self.rest_api_url}/{path}?version={version}"
else:
url = f"{self.api_url}/{path}"

Expand Down

0 comments on commit 5d41a71

Please sign in to comment.