Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! total confidence
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed May 28, 2024
1 parent 1f0d07e commit 0a6d48e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions confidence/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ class ResolveResult(object):


class Confidence:
context: Dict[str, str] = {}
context: Dict[str, Union[str, int, float, bool]] = {}

def put_context(self, key: str, value: str) -> None:
self.context[key] = value

def with_context(self, context: Dict[str, str]) -> "Confidence":
def with_context(
self, context: Dict[str, Union[str, int, float, bool]]
) -> "Confidence":
new_confidence = Confidence(
self._client_secret, self._region, self._apply_on_resolve
)
Expand All @@ -83,12 +85,10 @@ def __init__(
region: Region = Region.GLOBAL,
apply_on_resolve: bool = True,
):
print("apply", apply_on_resolve)
self._client_secret = client_secret
self._region = region
self._api_endpoint = region.endpoint()
self._apply_on_resolve = apply_on_resolve
print("apply2", self._apply_on_resolve)

def resolve_boolean_details(
self, flag_key: str, default_value: bool
Expand Down Expand Up @@ -124,14 +124,13 @@ def _evaluate(
flag_key: str,
value_type: Type[FieldType],
default_value: FieldType,
context: Dict[str, str],
context: Dict[str, Union[str, int, float, bool]],
) -> FlagResolutionDetails[Any]:
if "." in flag_key:
flag_id, value_path = flag_key.split(".", 1)
else:
flag_id = flag_key
value_path = None
print("HEY!", flag_key)
result = self._resolve(FlagName(flag_id), context)
if result.variant is None or len(str(result.value)) == 0:
return FlagResolutionDetails(
Expand Down Expand Up @@ -178,7 +177,9 @@ async def _send_event(self, event_name: str, context: Dict[str, str]) -> None:
response = requests.post(event_url, json=request_body, headers=headers)
response.raise_for_status()

def _resolve(self, flag_name: FlagName, context: Dict[str, str]) -> ResolveResult:
def _resolve(
self, flag_name: FlagName, context: Dict[str, Union[str, int, float, bool]]
) -> ResolveResult:
request_body = {
"clientSecret": self._client_secret,
"evaluationContext": context,
Expand Down
2 changes: 1 addition & 1 deletion confidence/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _to_openfeature_error_code(
def _confidence_with_context(
self, evaluation_context: Optional[EvaluationContext]
) -> confidence.confidence.Confidence:
eval_context: Dict[str, str] = {}
eval_context: Dict[str, Union[str, int, float, bool]] = {}
if evaluation_context:
if evaluation_context.targeting_key:
eval_context["targeting_key"] = evaluation_context.targeting_key
Expand Down

0 comments on commit 0a6d48e

Please sign in to comment.