From 5d41a7124f5188a278f638a4b1329ff79ac98201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DF?= Date: Mon, 30 Oct 2023 11:01:10 +0100 Subject: [PATCH] Let the user choose the tenant (US, EU, etc). REST_API_URL as user parameter. --- snyk/client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/snyk/client.py b/snyk/client.py index 36cb0e6..6530bdc 100644 --- a/snyk/client.py +++ b/snyk/client.py @@ -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, @@ -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, @@ -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) @@ -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}"