Skip to content

[AppConfiguration] Appconfig consistency #18493

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

Merged
merged 3 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
import json
from typing import Dict, Union, List, Any, Optional
from msrest.serialization import Model
from ._generated.models import KeyValue

Expand Down Expand Up @@ -60,18 +61,21 @@ def _from_generated(cls, key_value):
if key_value is None:
return None
if key_value.content_type is not None:
if key_value.content_type.startswith(
FeatureFlagConfigurationSetting._feature_flag_content_type # pylint:disable=protected-access
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix):
return FeatureFlagConfigurationSetting._from_generated( # pylint: disable=protected-access
key_value
)
if key_value.content_type.startswith(
SecretReferenceConfigurationSetting._secret_reference_content_type # pylint:disable=protected-access
):
return SecretReferenceConfigurationSetting._from_generated( # pylint: disable=protected-access
key_value
)
try:
if key_value.content_type.startswith(
FeatureFlagConfigurationSetting._feature_flag_content_type # pylint:disable=protected-access
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix):
return FeatureFlagConfigurationSetting._from_generated( # pylint: disable=protected-access
key_value
)
if key_value.content_type.startswith(
SecretReferenceConfigurationSetting._secret_reference_content_type # pylint:disable=protected-access
):
return SecretReferenceConfigurationSetting._from_generated( # pylint: disable=protected-access
key_value
)
except (KeyError, AttributeError, TypeError):
pass

return cls(
key=key_value.key,
Expand Down Expand Up @@ -143,7 +147,7 @@ class FeatureFlagConfigurationSetting(
kind = "FeatureFlag"

def __init__(self, feature_id, enabled, filters=[], **kwargs): # pylint: disable=dangerous-default-value
# type: (str, bool, Optional[List[Dict[str, Any]]]) -> None
# type: (str, bool, Optional[List[Dict[str, Any]]], **Any) -> None
super(FeatureFlagConfigurationSetting, self).__init__(**kwargs)
if not feature_id.startswith(self.key_prefix):
feature_id = self.key_prefix + feature_id
Expand Down Expand Up @@ -236,19 +240,12 @@ def _from_generated(cls, key_value):
return ConfigurationSetting._from_generated(key_value)

def _to_generated(self):
# type: (...) -> KeyValue
# value = {
# u"id": self.key,
# u"description": self.description,
# u"enabled": self._enabled,
# u"conditions": {u"client_filters": self._filters},
# }
# value = json.dumps(value)
# type: () -> KeyValue

return KeyValue(
key=self.key,
label=self.label,
value=self.value,
value=json.dumps(self.value), # NOTE: This has to be added for valid json
content_type=self.content_type,
last_modified=self.last_modified,
tags=self.tags,
Expand Down Expand Up @@ -297,7 +294,7 @@ class SecretReferenceConfigurationSetting(ConfigurationSetting):
kind = "SecretReference"

def __init__(self, key, secret_uri, label=None, **kwargs):
# type: (str, str, str) -> None
# type: (str, str, str, **Any) -> None
self._secret_uri = secret_uri
super(SecretReferenceConfigurationSetting, self).__init__(**kwargs)
self.key = key
Expand Down Expand Up @@ -334,26 +331,24 @@ def _validate(self):
@classmethod
def _from_generated(cls, key_value):
# type: (KeyValue) -> SecretReferenceConfigurationSetting
try:
if key_value is None:
return None
if key_value.value:
try:
key_value.value = json.loads(key_value.value)
except json.decoder.JSONDecodeError:
pass
return cls(
key=key_value.key,
secret_uri=key_value.value[u"secret_uri"],
label=key_value.label,
secret_id=key_value.value,
last_modified=key_value.last_modified,
tags=key_value.tags,
read_only=key_value.locked,
etag=key_value.etag,
)
except (KeyError, AttributeError):
return ConfigurationSetting._from_generated(key_value)
if key_value is None:
return None
if key_value.value:
try:
key_value.value = json.loads(key_value.value)
except json.decoder.JSONDecodeError:
pass

return cls(
key=key_value.key,
secret_uri=key_value.value[u"secret_uri"],
label=key_value.label,
secret_id=key_value.value,
last_modified=key_value.last_modified,
tags=key_value.tags,
read_only=key_value.locked,
etag=key_value.etag,
)

def _to_generated(self):
# type: (...) -> KeyValue
Expand Down
Loading