forked from Zipstack/unstract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature_flag.py
More file actions
42 lines (34 loc) · 1.22 KB
/
feature_flag.py
File metadata and controls
42 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Feature flag utils file."""
import logging
from typing import Optional
from .client.evaluation import EvaluationClient
logger = logging.getLogger(__name__)
def check_feature_flag_status(
flag_key: str,
namespace_key: str = "default",
entity_id: str = "unstract",
context: Optional[dict[str, str]] = None,
) -> bool:
"""Check the status of a feature flag for a given entity.
Args:
namespace_key (str): The namespace key of the feature flag.
flag_key (str): The flag key of the feature flag.
entity_id (str): The ID of the entity for which the feature flag status
is checked.
context (dict, optional): Additional context data for evaluating the
feature flag. Defaults to None.
Returns:
bool:
True if the feature flag is enabled for the entity, False otherwise.
"""
try:
evaluation_client = EvaluationClient()
response = evaluation_client.boolean_evaluate_feature_flag(
namespace_key=namespace_key,
flag_key=flag_key,
entity_id=entity_id,
context=context,
)
return bool(response) # Wrap the response in a boolean check
except Exception:
return False