|
15 | 15 | from flareio.version import __version__ as _flareio_version |
16 | 16 |
|
17 | 17 |
|
| 18 | +ALLOWED_API_DOMAINS: set[str] = ( |
| 19 | + "api.flare.io", |
| 20 | + "api.eu.flare.io", |
| 21 | +) |
| 22 | + |
| 23 | + |
18 | 24 | class FlareApiClient: |
19 | 25 | def __init__( |
20 | 26 | self, |
21 | 27 | *, |
22 | 28 | api_key: str, |
23 | 29 | tenant_id: t.Optional[int] = None, |
24 | 30 | session: t.Optional[requests.Session] = None, |
| 31 | + api_domain: str = "api.flare.io", |
25 | 32 | ) -> None: |
26 | 33 | if not api_key: |
27 | 34 | 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 |
28 | 42 | self._api_key: str = api_key |
29 | 43 | self._tenant_id: t.Optional[int] = tenant_id |
30 | 44 |
|
@@ -93,7 +107,7 @@ def generate_token(self) -> str: |
93 | 107 | } |
94 | 108 |
|
95 | 109 | resp = self._session.post( |
96 | | - "https://api.flare.io/tokens/generate", |
| 110 | + f"https://{self.api_domain}/tokens/generate", |
97 | 111 | json=payload, |
98 | 112 | headers={ |
99 | 113 | "Authorization": self._api_key, |
@@ -128,12 +142,12 @@ def _request( |
128 | 142 | json: t.Optional[t.Dict[str, t.Any]] = None, |
129 | 143 | headers: t.Optional[t.Dict[str, t.Any]] = None, |
130 | 144 | ) -> requests.Response: |
131 | | - url = urljoin("https://api.flare.io", url) |
| 145 | + url = urljoin(f"https://{self.api_domain}", url) |
132 | 146 |
|
133 | 147 | netloc: str = urlparse(url).netloc |
134 | | - if not netloc == "api.flare.io": |
| 148 | + if not netloc == self.api_domain: |
135 | 149 | 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." |
137 | 151 | ) |
138 | 152 |
|
139 | 153 | headers = { |
|
0 commit comments