-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from uclahs-cds/aholmes-feature-flag-changes
Make feature flags easier to use and fix database errors
- Loading branch information
Showing
12 changed files
with
338 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ classifiers = [ | |
] | ||
|
||
dependencies = [ | ||
"injector", | ||
"pysaml2", | ||
"requests" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Any, Callable | ||
|
||
from injector import Injector, inject | ||
from typing_extensions import overload | ||
|
||
from .feature_flag_router import FeatureFlag, FeatureFlagRouter | ||
|
||
|
||
@overload | ||
def feature_flag( | ||
feature_flag_name: str, *, enabled_callback: Callable[..., Any] | ||
) -> Callable[..., Callable[..., Any]]: ... | ||
@overload | ||
def feature_flag( | ||
feature_flag_name: str, *, disabled_callback: Callable[..., Any] | ||
) -> Callable[..., Callable[..., Any]]: ... | ||
|
||
|
||
def feature_flag( | ||
feature_flag_name: str, | ||
*, | ||
enabled_callback: Callable[..., None] = lambda: None, | ||
disabled_callback: Callable[..., None] = lambda: None, | ||
) -> Callable[..., Callable[..., Any]]: | ||
def decorator(fn: Callable[..., Any]): | ||
@inject | ||
def wrapper( | ||
feature_flag_router: FeatureFlagRouter[FeatureFlag], | ||
injector: Injector, | ||
): | ||
if feature_flag_router.feature_is_enabled(feature_flag_name): | ||
enabled_callback() | ||
else: | ||
disabled_callback() | ||
|
||
return injector.call_with_injection(fn) | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.