Skip to content
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

refactor(feature-flags): optimize UX and maintenance #563

Merged
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9890170
docs(feature_flags): initial skeleton
heitorlessa Jul 26, 2021
85f4b9d
Merge branch 'develop' into docs/dynamic-feature-toggles
heitorlessa Jul 30, 2021
0b2abc7
docs(feature_flags): initial sections
heitorlessa Jul 30, 2021
566a2f9
docs: add terminology section
heitorlessa Jul 30, 2021
e9f87dc
docs: add IAM permission
heitorlessa Jul 30, 2021
619c547
refactor: rules_context to context
heitorlessa Jul 30, 2021
b274eed
refactor: AppConfig params to match Parameters
heitorlessa Jul 30, 2021
4d397a7
refactor: rename ConfigurationStore, SchemaFetcher
heitorlessa Jul 30, 2021
a70bcd8
refactor: rename schema_fetcher param
heitorlessa Jul 30, 2021
649d987
refactor: rename get_feature_toggle to evaluate
heitorlessa Jul 30, 2021
38c7bd1
chore: improve all_enabled feature tests
heitorlessa Jul 30, 2021
d902018
refactor: get_all_enabled_feature_toggles to get_enabled_features
heitorlessa Jul 30, 2021
ce16548
refactor: remove redundant logger, add newlines
heitorlessa Jul 30, 2021
2f5ccd3
chore: make method static
heitorlessa Jul 30, 2021
0d44e4d
refactor(tests): simplify with pytest raise match str
heitorlessa Aug 1, 2021
6100d38
refactor: rename feature_name to name
heitorlessa Aug 1, 2021
7370464
refactor: remove redundant logger; rename method to validate
heitorlessa Aug 2, 2021
d50650c
refactor: rename to feature_flags
heitorlessa Aug 2, 2021
0c0a4f7
refactor(schema-validator): accept schema in constructor
heitorlessa Aug 2, 2021
0e15b4b
refactor(schema-validator): private fn signature name
heitorlessa Aug 2, 2021
7eb8a67
revert: re-add root schema validation under validate
heitorlessa Aug 2, 2021
9e757fa
fix: regression on empty schemas
heitorlessa Aug 2, 2021
3a71fdf
fix: regression on empty schemas
heitorlessa Aug 2, 2021
bf4bdd6
refactor(schema-validator): initial change to classes
heitorlessa Aug 2, 2021
33f30d2
Merge branch 'docs/dynamic-feature-toggles' of https://github.com/hei…
heitorlessa Aug 2, 2021
7fa8ec2
refactor(schema-validator): rename each Validator
heitorlessa Aug 2, 2021
3b50664
refactor(schema-validator): rename Action to RuleAction
heitorlessa Aug 2, 2021
d22226f
refactor(tests): use public methods
heitorlessa Aug 2, 2021
cd561a1
michaelbrewer Aug 2, 2021
dd2c1f8
test(feature-flags): review issues with pr
michaelbrewer Aug 2, 2021
6ed29ea
Merge pull request #36 from gyft/docs/dynamic-feature-toggles-patch
heitorlessa Aug 3, 2021
b500acb
refactor(tests): use public static methods
heitorlessa Aug 3, 2021
327a4ae
refactor(schema): rename feature_default_value to default
heitorlessa Aug 3, 2021
4bfe2a8
refactor(schema): rename value_when_applies to when_match
heitorlessa Aug 3, 2021
4aba507
refactor(schema): use new rules dict over list
heitorlessa Aug 3, 2021
387da38
refactor(tests): conf_store to feature flags
heitorlessa Aug 3, 2021
a872814
refactor: remove RULE_KEY, exception & rule test consistency
heitorlessa Aug 3, 2021
1f62696
refactor(schema): remove 'features' key
heitorlessa Aug 3, 2021
f63a5da
feat: support JMESPath envelope/options to extract features
heitorlessa Aug 3, 2021
9c714ab
refactor(store): use get_configuration over get_json_configuration
heitorlessa Aug 3, 2021
f89d572
refactor: add docstrings and logging to FeatureFlags, Store
heitorlessa Aug 3, 2021
b61cafa
docs: remove changes; add in PR description
heitorlessa Aug 3, 2021
e9bb190
refactor(schema): add docstrings and schema specification
heitorlessa Aug 3, 2021
a55131f
refactor: add SchemaValidationError
heitorlessa Aug 3, 2021
e0ab7a1
refactor: rename ConfigurationError to ConfigurationStoreError, impro…
heitorlessa Aug 3, 2021
d8125c7
test: conditional dict values
heitorlessa Aug 4, 2021
1b202be
refactor: rename toggles to flags
heitorlessa Aug 4, 2021
a0ae9da
fix: propagate access denied errors
heitorlessa Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions aws_lambda_powertools/utilities/feature_flags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Advanced feature toggles utility
"""
from .appconfig import AppConfigStore
from .base import StoreProvider
from .exceptions import ConfigurationError
from .feature_flags import FeatureFlags
from .schema import RuleAction, SchemaValidator

__all__ = [
"ConfigurationError",
"FeatureFlags",
"RuleAction",
"SchemaValidator",
"AppConfigStore",
"StoreProvider",
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@

from aws_lambda_powertools.utilities.parameters import AppConfigProvider, GetParameterError, TransformParameterError

from .base import StoreProvider
from .exceptions import ConfigurationError
from .schema_fetcher import SchemaFetcher

logger = logging.getLogger(__name__)


TRANSFORM_TYPE = "json"


class AppConfigFetcher(SchemaFetcher):
class AppConfigStore(StoreProvider):
def __init__(
self,
environment: str,
service: str,
configuration_name: str,
application: str,
name: str,
cache_seconds: int,
config: Optional[Config] = None,
):
Expand All @@ -28,19 +27,19 @@ def __init__(
Parameters
----------
environment: str
what appconfig environment to use 'dev/test' etc.
service: str
what service name to use from the supplied environment
configuration_name: str
what configuration to take from the environment & service combination
Appconfig environment, e.g. 'dev/test' etc.
application: str
AppConfig application name, e.g. 'powertools'
name: str
AppConfig configuration name e.g. `my_conf`
cache_seconds: int
cache expiration time, how often to call AppConfig to fetch latest configuration
config: Optional[Config]
boto3 client configuration
"""
super().__init__(configuration_name, cache_seconds)
super().__init__(name, cache_seconds)
self._logger = logger
self._conf_store = AppConfigProvider(environment=environment, application=service, config=config)
self._conf_store = AppConfigProvider(environment=environment, application=application, config=config)

def get_json_configuration(self) -> Dict[str, Any]:
"""Get configuration string from AWs AppConfig and return the parsed JSON dictionary
Expand All @@ -60,12 +59,10 @@ def get_json_configuration(self) -> Dict[str, Any]:
return cast(
dict,
self._conf_store.get(
name=self.configuration_name,
name=self.name,
transform=TRANSFORM_TYPE,
max_age=self._cache_seconds,
),
)
except (GetParameterError, TransformParameterError) as exc:
error_str = f"unable to get AWS AppConfig configuration file, exception={str(exc)}"
self._logger.error(error_str)
raise ConfigurationError(error_str)
raise ConfigurationError("Unable to get AWS AppConfig configuration file") from exc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from typing import Any, Dict


class SchemaFetcher(ABC):
class StoreProvider(ABC):
def __init__(self, configuration_name: str, cache_seconds: int):
self.configuration_name = configuration_name
self.name = configuration_name
self._cache_seconds = cache_seconds

@abstractmethod
def get_json_configuration(self) -> Dict[str, Any]:
"""Get configuration string from any configuration storing service and return the parsed JSON dictionary
"""Get configuration string from any configuration storing application and return the parsed JSON dictionary

Raises
------
Expand All @@ -22,3 +22,9 @@ def get_json_configuration(self) -> Dict[str, Any]:
parsed JSON dictionary
"""
return NotImplemented # pragma: no cover


class BaseValidator(ABC):
@abstractmethod
def validate(self):
return NotImplemented # pragma: no cover
Loading