flagswitch-sdk 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/PKG-INFO +1 -1
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk/__init__.py +5 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk/client.py +21 -3
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk/exceptions.py +4 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk.egg-info/PKG-INFO +1 -1
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/pyproject.toml +1 -1
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/README.md +0 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk.egg-info/SOURCES.txt +0 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk.egg-info/dependency_links.txt +0 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk.egg-info/requires.txt +0 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/flagswitch_sdk.egg-info/top_level.txt +0 -0
- {flagswitch_sdk-0.2.0 → flagswitch_sdk-0.3.0}/setup.cfg +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
2
|
+
__author__ = "FlagSwitch"
|
|
3
|
+
|
|
1
4
|
from flagswitch_sdk.client import FlagSwitch, FlagSwitchSync
|
|
2
5
|
from flagswitch_sdk.exceptions import (
|
|
6
|
+
EnvironmentNotFoundError,
|
|
3
7
|
FlagSwitchConnectionError,
|
|
4
8
|
FlagSwitchError,
|
|
5
9
|
InvalidApiKeyError,
|
|
@@ -10,5 +14,6 @@ __all__ = [
|
|
|
10
14
|
"FlagSwitchSync",
|
|
11
15
|
"FlagSwitchError",
|
|
12
16
|
"InvalidApiKeyError",
|
|
17
|
+
"EnvironmentNotFoundError",
|
|
13
18
|
"FlagSwitchConnectionError",
|
|
14
19
|
]
|
|
@@ -3,7 +3,11 @@ from typing import Any
|
|
|
3
3
|
|
|
4
4
|
import httpx
|
|
5
5
|
|
|
6
|
-
from flagswitch_sdk.exceptions import
|
|
6
|
+
from flagswitch_sdk.exceptions import (
|
|
7
|
+
EnvironmentNotFoundError,
|
|
8
|
+
FlagSwitchConnectionError,
|
|
9
|
+
InvalidApiKeyError,
|
|
10
|
+
)
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
_BASE_URL = "http://localhost:8010/api/fs"
|
|
@@ -11,8 +15,9 @@ _CACHE_TTL = 30
|
|
|
11
15
|
|
|
12
16
|
|
|
13
17
|
class FlagSwitch:
|
|
14
|
-
def __init__(self, api_key: str):
|
|
18
|
+
def __init__(self, api_key: str, environment: str):
|
|
15
19
|
self._api_key = api_key
|
|
20
|
+
self._environment = environment
|
|
16
21
|
self._cache_ttl = _CACHE_TTL
|
|
17
22
|
self._cache: dict[str, Any] = {}
|
|
18
23
|
self._cache_ts: float = 0
|
|
@@ -26,6 +31,7 @@ class FlagSwitch:
|
|
|
26
31
|
response = await http.get(
|
|
27
32
|
f"{_BASE_URL}/evaluate",
|
|
28
33
|
headers={"X-Api-Key": self._api_key},
|
|
34
|
+
params={"environment": self._environment},
|
|
29
35
|
timeout=5.0,
|
|
30
36
|
)
|
|
31
37
|
except httpx.RequestError as e:
|
|
@@ -34,6 +40,11 @@ class FlagSwitch:
|
|
|
34
40
|
if response.status_code == 401:
|
|
35
41
|
raise InvalidApiKeyError("Invalid or inactive API key.")
|
|
36
42
|
|
|
43
|
+
if response.status_code == 404:
|
|
44
|
+
raise EnvironmentNotFoundError(
|
|
45
|
+
f"Environment '{self._environment}' not found for this project."
|
|
46
|
+
)
|
|
47
|
+
|
|
37
48
|
if response.status_code != 200:
|
|
38
49
|
raise FlagSwitchConnectionError(
|
|
39
50
|
f"Unexpected response from FlagSwitch: {response.status_code}"
|
|
@@ -64,8 +75,9 @@ class FlagSwitch:
|
|
|
64
75
|
|
|
65
76
|
|
|
66
77
|
class FlagSwitchSync:
|
|
67
|
-
def __init__(self, api_key: str):
|
|
78
|
+
def __init__(self, api_key: str, environment: str):
|
|
68
79
|
self._api_key = api_key
|
|
80
|
+
self._environment = environment
|
|
69
81
|
self._cache_ttl = _CACHE_TTL
|
|
70
82
|
self._cache: dict[str, Any] = {}
|
|
71
83
|
self._cache_ts: float = 0
|
|
@@ -79,6 +91,7 @@ class FlagSwitchSync:
|
|
|
79
91
|
response = http.get(
|
|
80
92
|
f"{_BASE_URL}/evaluate",
|
|
81
93
|
headers={"X-Api-Key": self._api_key},
|
|
94
|
+
params={"environment": self._environment},
|
|
82
95
|
timeout=5.0,
|
|
83
96
|
)
|
|
84
97
|
except httpx.RequestError as e:
|
|
@@ -87,6 +100,11 @@ class FlagSwitchSync:
|
|
|
87
100
|
if response.status_code == 401:
|
|
88
101
|
raise InvalidApiKeyError("Invalid or inactive API key.")
|
|
89
102
|
|
|
103
|
+
if response.status_code == 404:
|
|
104
|
+
raise EnvironmentNotFoundError(
|
|
105
|
+
f"Environment '{self._environment}' not found for this project."
|
|
106
|
+
)
|
|
107
|
+
|
|
90
108
|
if response.status_code != 200:
|
|
91
109
|
raise FlagSwitchConnectionError(
|
|
92
110
|
f"Unexpected response from FlagSwitch: {response.status_code}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|