Skip to content

Commit 549775f

Browse files
[App Config] Fix #30619: az appconfig: Fix requirement type bug (#31471)
1 parent 382f71d commit 549775f

File tree

9 files changed

+76160
-70594
lines changed

9 files changed

+76160
-70594
lines changed

src/azure-cli/azure/cli/command_modules/appconfig/_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class FeatureFlagConstants:
4949
GROUPS = "groups"
5050

5151
# Requirement type options
52-
REQUIREMENT_TYPE_ALL = "all"
53-
REQUIREMENT_TYPE_ANY = "any"
52+
REQUIREMENT_TYPE_ALL = "All"
53+
REQUIREMENT_TYPE_ANY = "Any"
5454

5555
# Telemetry properties
5656
METADATA = "metadata"

src/azure-cli/azure/cli/command_modules/appconfig/_featuremodels.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,14 +906,15 @@ def map_keyvalue_to_featureflagvalue(keyvalue):
906906
FeatureFlagConstants.REQUIREMENT_TYPE, None
907907
)
908908
if requirement_type:
909-
if requirement_type.lower() not in (
910-
FeatureFlagConstants.REQUIREMENT_TYPE_ALL,
911-
FeatureFlagConstants.REQUIREMENT_TYPE_ANY,
912-
):
909+
# Requirement type is case insensitive.
910+
if requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ALL.lower():
911+
conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ALL
912+
elif requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ANY.lower():
913+
conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ANY
914+
else:
913915
raise ValidationError(
914-
f"Feature '{feature_name}' must have an any/all requirement type."
916+
f"Feature '{feature_name}' must have an Any/All requirement type."
915917
)
916-
conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = requirement_type
917918

918919
# Backend returns conditions: {client_filters: None} for flags with no conditions.
919920
# No need to write empty conditions to key-values.

src/azure-cli/azure/cli/command_modules/appconfig/_kv_import_helpers.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,15 @@ def __read_features_from_msfm_schema(feature_flags_list):
330330
FeatureFlagConstants.REQUIREMENT_TYPE, None
331331
)
332332
if requirement_type:
333-
if requirement_type.lower() not in (
334-
FeatureFlagConstants.REQUIREMENT_TYPE_ALL,
335-
FeatureFlagConstants.REQUIREMENT_TYPE_ANY,
336-
):
333+
# Requirement type is case insensitive.
334+
if requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ALL.lower():
335+
new_feature.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ALL
336+
elif requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ANY.lower():
337+
new_feature.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ANY
338+
else:
337339
raise ValidationError(
338-
f"Feature '{feature_id}' must have an any/all requirement type."
340+
f"Feature '{feature_id}' must have an Any/All requirement type."
339341
)
340-
new_feature.conditions[
341-
FeatureFlagConstants.REQUIREMENT_TYPE
342-
] = requirement_type
343342

344343
if allocation := feature.get(FeatureFlagConstants.ALLOCATION, None):
345344
new_feature.allocation = FeatureAllocation.convert_from_dict(allocation)
@@ -382,18 +381,16 @@ def __read_features_from_dotnet_schema(features_dict, feature_management_keyword
382381
condition == feature_management_keywords.requirement_type and
383382
condition_value
384383
):
385-
if condition_value.lower() not in (
386-
FeatureFlagConstants.REQUIREMENT_TYPE_ALL,
387-
FeatureFlagConstants.REQUIREMENT_TYPE_ANY,
388-
):
384+
if condition_value.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ALL.lower():
385+
feature_flag_value.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ALL
386+
elif condition_value.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ANY.lower():
387+
feature_flag_value.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = FeatureFlagConstants.REQUIREMENT_TYPE_ANY
388+
else:
389389
raise ValidationError(
390-
"Feature '{0}' must have an any/all requirement type. \n".format(
390+
"Feature '{0}' must have an Any/All requirement type. \n".format(
391391
str(k)
392392
)
393393
)
394-
feature_flag_value.conditions[
395-
FeatureFlagConstants.REQUIREMENT_TYPE
396-
] = condition_value
397394
else:
398395
feature_flag_value.conditions[condition] = condition_value
399396
if not enabled_for_found:

src/azure-cli/azure/cli/command_modules/appconfig/feature.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ def set_feature(cmd,
7171
default_conditions = {FeatureFlagConstants.CLIENT_FILTERS: []}
7272

7373
if requirement_type:
74-
default_conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = requirement_type
74+
default_conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = (
75+
FeatureFlagConstants.REQUIREMENT_TYPE_ALL
76+
if requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ALL.lower()
77+
else FeatureFlagConstants.REQUIREMENT_TYPE_ANY
78+
)
7579

7680
default_value = {
7781
FeatureFlagConstants.ID: feature,
@@ -125,7 +129,11 @@ def set_feature(cmd,
125129
feature_flag_value.description = description
126130

127131
if requirement_type is not None:
128-
feature_flag_value.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = requirement_type
132+
feature_flag_value.conditions[FeatureFlagConstants.REQUIREMENT_TYPE] = (
133+
FeatureFlagConstants.REQUIREMENT_TYPE_ALL
134+
if requirement_type.lower() == FeatureFlagConstants.REQUIREMENT_TYPE_ALL.lower()
135+
else FeatureFlagConstants.REQUIREMENT_TYPE_ANY
136+
)
129137

130138
set_kv = KeyValue(key=key,
131139
label=label,

0 commit comments

Comments
 (0)