-
Notifications
You must be signed in to change notification settings - Fork 45
Add all_flags, secure_mode_hash + more #51
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
Changes from all commits
4a197fa
b6ecb82
1093b0d
1f7ea6f
989878d
6ab8ed2
99bb605
a2a7032
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,29 +14,46 @@ | |
| log = logging.getLogger(sys.modules[__name__].__name__) | ||
|
|
||
|
|
||
| def evaluate(flag, user, store, prereq_events=[]): | ||
| def evaluate(flag, user, store): | ||
|
Contributor
Author
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. I moved all the flag eval logic into the flag file. |
||
| prereq_events = [] | ||
| if flag.get('on', False): | ||
| value, prereq_events = _evaluate(flag, user, store) | ||
| if value is not None: | ||
| return value, prereq_events | ||
|
|
||
| if 'offVariation' in flag and flag['offVariation']: | ||
| value = _get_variation(flag, flag['offVariation']) | ||
| return value, prereq_events | ||
| return None, prereq_events | ||
|
|
||
|
|
||
| def _evaluate(flag, user, store, prereq_events=None): | ||
|
Contributor
Author
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. When we had the default value for prereq_events set to [] it was getting reused across function calls and the array just kept getting appended and we sent back a ton of prereq events. |
||
| events = prereq_events or [] | ||
| failed_prereq = None | ||
| prereq_value = None | ||
| for prereq in flag.get('prerequisites') or []: | ||
| prereq_flag = store.get(prereq.get('key')) | ||
| if prereq_flag is None: | ||
| log.warn("Missing prereq flag: " + prereq.get('key')) | ||
| failed_prereq = prereq | ||
| break | ||
| if prereq_flag.get('on', False) is True: | ||
| prereq_value, prereq_events = evaluate(prereq_flag, user, store, prereq_events) | ||
| event = {'kind': 'feature', 'key': prereq.get('key'), 'user': user, 'value': prereq_value} | ||
| prereq_events.append(event) | ||
| prereq_value, events = _evaluate(prereq_flag, user, store, events) | ||
| variation = _get_variation(prereq_flag, prereq.get('variation')) | ||
| if prereq_value is None or not prereq_value == variation: | ||
| failed_prereq = prereq | ||
| else: | ||
| failed_prereq = prereq | ||
|
|
||
| event = {'kind': 'feature', 'key': prereq.get('key'), 'user': user, | ||
| 'value': prereq_value, 'version': prereq_flag.get('version'), 'prereqOf': prereq.get('key')} | ||
| events.append(event) | ||
|
|
||
| if failed_prereq is not None: | ||
| return None, prereq_events | ||
| return None, events | ||
|
|
||
| index = _evaluate_index(flag, user) | ||
| return _get_variation(flag, index), prereq_events | ||
| return _get_variation(flag, index), events | ||
|
|
||
|
|
||
| def _evaluate_index(feature, user): | ||
|
|
||
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.
@jkodumal take note of these checks when implementing in other sdks.