-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add a task for writing (edge) identity overrides #3127
Changes from 6 commits
ea1f9f9
9f5c3f6
9c9925a
dd19af8
7e05c2f
48f9289
5a7a551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import Any, Literal, TypedDict | ||
|
||
from typing_extensions import NotRequired | ||
|
||
ChangeType = Literal["+", "-", "~"] | ||
|
||
|
||
class FeatureStateChangeDetails(TypedDict): | ||
change_type: ChangeType | ||
old: NotRequired[dict[str, Any]] | ||
new: NotRequired[dict[str, Any]] | ||
|
||
|
||
class IdentityChangeset(TypedDict): | ||
feature_overrides: dict[str, FeatureStateChangeDetails] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import typing | ||
|
||
from flag_engine.features.models import FeatureStateModel | ||
|
||
if typing.TYPE_CHECKING: | ||
from edge_api.identities.types import ChangeType, FeatureStateChangeDetails | ||
|
||
|
||
def generate_change_dict( | ||
change_type: "ChangeType", | ||
identity_id: int | str | None, | ||
new: FeatureStateModel | None = None, | ||
old: FeatureStateModel | None = None, | ||
) -> "FeatureStateChangeDetails": | ||
if not (new or old): | ||
raise ValueError("Must provide one of 'new' or 'old'") | ||
|
||
change_dict = {"change_type": change_type} | ||
if new: | ||
change_dict["new"] = _get_overridden_feature_state_dict( | ||
identity_id=identity_id, | ||
feature_state=new, | ||
) | ||
if old: | ||
change_dict["old"] = _get_overridden_feature_state_dict( | ||
identity_id=identity_id, | ||
feature_state=old, | ||
) | ||
|
||
return change_dict | ||
|
||
|
||
def _get_overridden_feature_state_dict( | ||
identity_id: int | str | None, | ||
feature_state: FeatureStateModel, | ||
) -> dict[str, typing.Any]: | ||
return { | ||
**feature_state.dict(), | ||
"feature_state_value": feature_state.get_value(identity_id), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just making a note here as well that this is different to the previous behaviour - this used to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can tell, this data is used in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ENVIRONMENTS_V2_PARTITION_KEY = "environment_id" | ||
ENVIRONMENTS_V2_SORT_KEY = "document_key" | ||
|
||
ENVIRONMENTS_V2_SECONDARY_INDEX = "environment_api_key-index" | ||
ENVIRONMENTS_V2_SECONDARY_INDEX_PARTITION_KEY = "environment_api_key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewelwell I've relocated these from your endpoint PR so they can be used by some other tests too.