-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[AppConfig] Support Import/Export of features in yaml files #11637
Merged
Juliehzl
merged 6 commits into
Azure:dev
from
avanigupta:avanigupta/importexportyamlfeatures
Jan 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc79695
feature flag import/export for yaml files
avanigupta bed54bf
Remove naming-convention from import and add tests
avanigupta 4509a4b
Change all test files to json for passing CI tests
avanigupta 1d518d3
Using yaml.safe_dump and resolving comments
avanigupta 6393a06
Updating histoy and separating tests
avanigupta c16cb4a
Adding new test recording file to credscansuppressions
avanigupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove naming-convention from import and add tests
- Loading branch information
commit bed54bf3b1bf0a3806e7f1da164e9c0ccdc35a3a
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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
ModifyKeyValueOptions, | ||
QueryKeyValueCollectionOptions, | ||
QueryKeyValueOptions) | ||
from ._kv_helpers import (FeatureManagementReservedKeywords, __compare_kvs_for_restore, __read_kv_from_file, __read_features_from_file, | ||
from ._kv_helpers import (__compare_kvs_for_restore, __read_kv_from_file, __read_features_from_file, | ||
__write_kv_and_features_to_file, __read_kv_from_config_store, | ||
__write_kv_and_features_to_config_store, __discard_features_from_retrieved_kv, __read_kv_from_app_service, | ||
__write_kv_to_app_service, __serialize_kv_list_to_comparable_json_object, __serialize_features_from_kv_list_to_comparable_json_object, | ||
|
@@ -52,31 +52,22 @@ def import_config(cmd, | |
src_label=None, | ||
# from-appservice parameters | ||
appservice_account=None, | ||
skip_features=False, | ||
naming_convention=None): | ||
skip_features=False): | ||
# pylint: disable=too-many-locals | ||
src_features = [] | ||
dest_features = [] | ||
dest_kvs = [] | ||
source = source.lower() | ||
format_ = format_.lower() if format_ else None | ||
|
||
if not naming_convention: | ||
logger.warning("--naming-convention was not provided. Reserved keywords for feature management section will default to PascalCase.") | ||
naming_convention = 'pascal' | ||
else: | ||
naming_convention = naming_convention.lower() | ||
|
||
feature_reserved_keywords = FeatureManagementReservedKeywords(naming_convention) | ||
|
||
# fetch key values from source | ||
if source == 'file': | ||
src_kvs = __read_kv_from_file( | ||
file_path=path, format_=format_, feature_reserved_keywords=feature_reserved_keywords, separator=separator, prefix_to_add=prefix, depth=depth) | ||
file_path=path, format_=format_, separator=separator, prefix_to_add=prefix, depth=depth) | ||
|
||
if not skip_features: | ||
# src_features is a list of KeyValue objects | ||
src_features = __read_features_from_file(file_path=path, format_=format_, feature_reserved_keywords=feature_reserved_keywords) | ||
src_features = __read_features_from_file(file_path=path, format_=format_) | ||
|
||
elif source == 'appconfig': | ||
src_kvs = __read_kv_from_config_store(cmd, name=src_name, connection_string=src_connection_string, | ||
|
@@ -159,13 +150,6 @@ def export_config(cmd, | |
dest_kvs = [] | ||
destination = destination.lower() | ||
format_ = format_.lower() if format_ else None | ||
if not naming_convention: | ||
logger.warning("--naming-convention was not provided. Reserved keywords for feature management section will default to PascalCase.") | ||
naming_convention = 'pascal' | ||
else: | ||
naming_convention = naming_convention.lower() | ||
|
||
feature_reserved_keywords = FeatureManagementReservedKeywords(naming_convention) | ||
|
||
# fetch key values from user's configstore | ||
src_kvs = __read_kv_from_config_store( | ||
|
@@ -176,7 +160,24 @@ def export_config(cmd, | |
|
||
if not skip_features: | ||
# Get all Feature flags with matching label | ||
if destination in ('file', 'appconfig'): | ||
if destination == 'file': | ||
if format_ == 'properties': | ||
skip_features = True | ||
else: | ||
if not naming_convention: | ||
logger.warning("--naming-convention was not provided. Reserved keywords for feature management section will default to PascalCase.") | ||
naming_convention = 'pascal' | ||
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. nit:maybe log debug? or no need to log here as we already have the explanation for default naming convention 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. |
||
else: | ||
naming_convention = naming_convention.lower() | ||
|
||
# src_features is a list of FeatureFlag objects | ||
src_features = list_feature(cmd, | ||
feature='*', | ||
label=QueryKeyValueCollectionOptions.empty_label if label is None else label, | ||
name=name, | ||
connection_string=connection_string, | ||
all_=True) | ||
elif destination == 'appconfig': | ||
# src_features is a list of FeatureFlag objects | ||
src_features = list_feature(cmd, | ||
feature='*', | ||
|
@@ -225,7 +226,7 @@ def export_config(cmd, | |
if destination == 'file': | ||
__write_kv_and_features_to_file(file_path=path, key_values=src_kvs, features=src_features, | ||
format_=format_, separator=separator, skip_features=skip_features, | ||
feature_reserved_keywords=feature_reserved_keywords) | ||
naming_convention=naming_convention) | ||
elif destination == 'appconfig': | ||
__write_kv_and_features_to_config_store(cmd, key_values=src_kvs, features=src_features, name=dest_name, | ||
connection_string=dest_connection_string, label=dest_label) | ||
|
11 changes: 11 additions & 0 deletions
11
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/export_as_kv.properties
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,11 @@ | ||
Color=Red | ||
Region=West US | ||
feature-management.FalseFeature=false | ||
feature-management.FeatureSample.enabled-for[0].Name=Filter1 | ||
feature-management.FeatureSample.enabled-for[0].Parameters.paramforfilter1=value1 | ||
feature-management.FeatureSample.enabled-for[1].Name=Filter2 | ||
feature-management.FeatureSample.enabled-for[2].Name=Filter@3 | ||
feature-management.FeatureSample.enabled-for[3].Name=filter.4 | ||
feature-management.FeatureSample.enabled-for[3].Parameters.EmptyValue= | ||
feature-management.FeatureSample.enabled-for[3].Parameters.dotInFilter.Param=? | ||
feature-management.TrueFeature=true |
4 changes: 2 additions & 2 deletions
4
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/export_features.json
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
12 changes: 12 additions & 0 deletions
12
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/export_features.properties
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,12 @@ | ||
#Fri Dec 20 14:14:34 Pacific Standard Time 2019 | ||
Color=Red | ||
Region=West US | ||
feature-management.FalseFeature=false | ||
feature-management.FeatureSample.enabled-for[0].Name=Filter1 | ||
feature-management.FeatureSample.enabled-for[0].Parameters.paramforfilter1=value1 | ||
feature-management.FeatureSample.enabled-for[1].Name=Filter2 | ||
feature-management.FeatureSample.enabled-for[2].Name=Filter@3 | ||
feature-management.FeatureSample.enabled-for[3].Name=filter.4 | ||
feature-management.FeatureSample.enabled-for[3].Parameters.EmptyValue= | ||
feature-management.FeatureSample.enabled-for[3].Parameters.dotInFilter.Param=? | ||
feature-management.TrueFeature=true |
14 changes: 14 additions & 0 deletions
14
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/export_features.yaml
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,14 @@ | ||
Color: Red | ||
Region: West US | ||
feature-management: | ||
Beta: false | ||
Timestamp: | ||
enabled-for: | ||
- Name: Local Tests | ||
Parameters: | ||
StartTime: '2019-01-01T00:00:00Z' | ||
EndTime: '2019-09-01T00:00:00Z' | ||
- Name: Production Tests | ||
Parameters: | ||
StartTime: '2019-09-02T00:00:00Z' | ||
EndTime: '2019-11-01T00:00:00Z' |
14 changes: 14 additions & 0 deletions
14
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/export_features_hyphen.yaml
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,14 @@ | ||
Color: Red | ||
Region: West US | ||
feature-management: | ||
Beta: false | ||
Timestamp: | ||
enabled-for: | ||
- Name: Local Tests | ||
Parameters: | ||
StartTime: '2019-01-01T00:00:00Z' | ||
EndTime: '2019-09-01T00:00:00Z' | ||
- Name: Production Tests | ||
Parameters: | ||
StartTime: '2019-09-02T00:00:00Z' | ||
EndTime: '2019-11-01T00:00:00Z' |
26 changes: 26 additions & 0 deletions
26
...zure-cli/azure/cli/command_modules/appconfig/tests/latest/export_features_underscore.json
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,26 @@ | ||
{ | ||
"Color": "Red", | ||
"Region": "West US", | ||
"feature_management": { | ||
"Beta": false, | ||
"Percentage": true, | ||
"Timestamp": { | ||
"enabled_for": [ | ||
{ | ||
"Name": "Local Tests", | ||
"Parameters": { | ||
"StartTime": "2019-01-01T00:00:00Z", | ||
"EndTime": "2019-09-01T00:00:00Z" | ||
} | ||
}, | ||
{ | ||
"Name": "Production Tests", | ||
"Parameters": { | ||
"StartTime": "2019-09-02T00:00:00Z", | ||
"EndTime": "2019-11-01T00:00:00Z" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/import_features.properties
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,11 @@ | ||
feature-management.FeatureSample.enabled-for[0].Name=Filter1 | ||
feature-management.FeatureSample.enabled-for[0].Parameters.paramforfilter1=value1 | ||
feature-management.FeatureSample.enabled-for[1].Name=Filter2 | ||
feature-management.FeatureSample.enabled-for[2].Name=Filter@3 | ||
feature-management.FeatureSample.enabled-for[3].Name=filter.4 | ||
feature-management.FeatureSample.enabled-for[3].Parameters.EmptyValue= | ||
feature-management.FeatureSample.enabled-for[3].Parameters.dotInFilter.Param=? | ||
feature-management.TrueFeature=true | ||
feature-management.FalseFeature=false | ||
Color=Red | ||
Region=West US |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: no need to log here as warning will show up in console. We can add log warning in method for reading features from file.
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.
This warning is targeted for the case when user may have feature flags in properties file, but has also supplied --skip-features argument. In that case, we don't read features from file so we cant add any warning. But since this is an edge case, I can make it logger.debug instead of warning here.
In reply to: 361022792 [](ancestors = 361022792)