Skip to content

Commit beb7576

Browse files
committed
support eu api domain
1 parent 9048a04 commit beb7576

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

flareio/api_client.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,30 @@
1515
from flareio.version import __version__ as _flareio_version
1616

1717

18+
ALLOWED_API_DOMAINS: set[str] = (
19+
"api.flare.io",
20+
"api.eu.flare.io",
21+
)
22+
23+
1824
class FlareApiClient:
1925
def __init__(
2026
self,
2127
*,
2228
api_key: str,
2329
tenant_id: t.Optional[int] = None,
2430
session: t.Optional[requests.Session] = None,
31+
api_domain: str = "api.flare.io",
2532
) -> None:
2633
if not api_key:
2734
raise Exception("API Key cannot be empty.")
35+
36+
if api_domain not in ALLOWED_API_DOMAINS:
37+
raise Exception(
38+
f"Invalid API domain: {api_domain}. Only {ALLOWED_API_DOMAINS} are supported."
39+
)
40+
41+
self.api_domain: str = api_domain
2842
self._api_key: str = api_key
2943
self._tenant_id: t.Optional[int] = tenant_id
3044

@@ -93,7 +107,7 @@ def generate_token(self) -> str:
93107
}
94108

95109
resp = self._session.post(
96-
"https://api.flare.io/tokens/generate",
110+
f"https://{self.api_domain}/tokens/generate",
97111
json=payload,
98112
headers={
99113
"Authorization": self._api_key,
@@ -128,12 +142,12 @@ def _request(
128142
json: t.Optional[t.Dict[str, t.Any]] = None,
129143
headers: t.Optional[t.Dict[str, t.Any]] = None,
130144
) -> requests.Response:
131-
url = urljoin("https://api.flare.io", url)
145+
url = urljoin(f"https://{self.api_domain}", url)
132146

133147
netloc: str = urlparse(url).netloc
134-
if not netloc == "api.flare.io":
148+
if not netloc == self.api_domain:
135149
raise Exception(
136-
f"Client was used to access {netloc=} at {url=}. Only the domain api.flare.io is supported."
150+
f"Client was used to access {netloc=} at {url=}. Only the domain {self.api_domain} is supported."
137151
)
138152

139153
headers = {

0 commit comments

Comments
 (0)