Skip to content

Commit 2d11958

Browse files
committed
Fix rebase + fmt
1 parent 526eedd commit 2d11958

File tree

1 file changed

+4
-41
lines changed

1 file changed

+4
-41
lines changed

src/dda/feature_flags/manager.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FeatureFlagManager(ABC):
3232
"""
3333

3434
def __init__(self, app: Application) -> None:
35-
self.__app = app
35+
self._app = app
3636
# Manually implemented cache to avoid calling several time Feature flag backend on the same flag evaluation.
3737
# Cache key is a tuple of the flag, entity and scopes, to make it hashable.
3838
# For example after calling `enabled("test-flag", default=False, scopes={"user": "user1"}),
@@ -58,7 +58,7 @@ def enabled(self, flag: str, *, default: bool = False, scopes: Optional[dict[str
5858

5959
def __check_flag(self, flag: str, entity: str, scopes: tuple[tuple[str, str], ...]) -> bool | None:
6060
if self.__client is None:
61-
self.__app.display_debug("Feature flag client not initialized properly")
61+
self._app.display_debug("Feature flag client not initialized properly")
6262
return None
6363

6464
cache_key = (flag, entity, scopes)
@@ -81,17 +81,12 @@ def _get_entity(self) -> str:
8181
def _get_base_scopes(self) -> dict[str, str]:
8282
pass
8383

84-
@abstractmethod
85-
def _get_client_token(self) -> str | None:
86-
pass
87-
8884
@cached_property
8985
def __client(self) -> DatadogFeatureFlag | None:
9086
token = self._get_client_token()
9187
if token is None:
9288
return None
93-
return DatadogFeatureFlag(token, self.__app)
94-
89+
return DatadogFeatureFlag(token, self._app)
9590

9691
@cached_property
9792
def __base_scopes(self) -> dict[str, str]:
@@ -173,7 +168,7 @@ def _get_client_token(self) -> str | None: # noqa: PLR6301
173168
client_token = fetch_client_token()
174169
save_client_token(client_token)
175170

176-
return DatadogFeatureFlag(client_token, self.__app)
171+
return client_token
177172

178173
@property
179174
def __user(self) -> FeatureFlagUser:
@@ -182,39 +177,7 @@ def __user(self) -> FeatureFlagUser:
182177
def _get_entity(self) -> str:
183178
return self.__user.machine_id
184179

185-
<<<<<<< HEAD
186-
def enabled(self, flag: str, *, default: bool = False, scopes: Optional[dict[str, str]] = None) -> bool:
187-
entity = self.__get_entity()
188-
base_scopes = self.__get_base_scopes()
189-
if scopes is not None:
190-
base_scopes.update(scopes)
191-
192-
attributes_items = base_scopes.items()
193-
tuple_attributes = tuple(((key, value) for key, value in sorted(attributes_items)))
194-
195-
self.__app.display_debug(f"Checking flag {flag} with entity {entity} and scopes {base_scopes}")
196-
flag_value = self.__check_flag(flag, entity, tuple_attributes)
197-
if flag_value is None:
198-
return default
199-
return flag_value
200-
201-
def __check_flag(self, flag: str, entity: str, scopes: tuple[tuple[str, str], ...]) -> bool | None:
202-
if self.__client is None:
203-
self.__app.display_debug("Feature flag client not initialized properly")
204-
return None
205-
206-
cache_key = (flag, entity, scopes)
207-
if cache_key in self.__cache:
208-
return self.__cache[cache_key]
209-
210-
flag_value = self.__client.get_flag_value(flag, entity, dict(scopes))
211-
self.__cache[cache_key] = flag_value
212-
return flag_value
213-
214-
def __get_base_scopes(self) -> dict[str, str]:
215-
=======
216180
def _get_base_scopes(self) -> dict[str, str]:
217-
>>>>>>> be7a4ee (Add support for CI use for feature flags)
218181
return {
219182
"platform": get_os_name(),
220183
"ci": "false",

0 commit comments

Comments
 (0)