Skip to content

Commit 9094c46

Browse files
[App Config] az appconfig feature set/list/delete: Support setting and filtering by tags for feature commands (#31711)
1 parent f691bc7 commit 9094c46

8 files changed

Lines changed: 45570 additions & 10309 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class FeatureFlag:
134134
The list of variants defined for this feature.
135135
:ivar dict {string, object} telemetry:
136136
The declaration of options used to configure telemetry for this feature.
137+
:ivar dict tags:
138+
Tags associated with the feature flag.
137139
"""
138140

139141
def __init__(
@@ -151,6 +153,7 @@ def __init__(
151153
allocation=None,
152154
variants=None,
153155
telemetry=None,
156+
tags=None
154157
):
155158
self.name = name
156159
self.key = key
@@ -165,6 +168,7 @@ def __init__(
165168
self.variants = variants
166169
self.telemetry = telemetry
167170
self.display_name = display_name
171+
self.tags = tags
168172

169173
def __repr__(self):
170174
featureflag = {
@@ -180,7 +184,8 @@ def __repr__(self):
180184
"Allocation": custom_serialize_allocation(self.allocation),
181185
"Variants": custom_serialize_variants(self.variants),
182186
"Telemetry": custom_serialize_telemetry(self.telemetry),
183-
"Display Name": self.display_name
187+
"Display Name": self.display_name,
188+
"Tags": self.tags
184189
}
185190

186191
return json.dumps(featureflag, indent=2, ensure_ascii=False)
@@ -803,7 +808,8 @@ def map_keyvalue_to_featureflag(keyvalue, show_all_details=True, hide_enabled=Tr
803808
last_modified=keyvalue.last_modified,
804809
allocation=feature_flag_value.allocation,
805810
variants=feature_flag_value.variants,
806-
telemetry=feature_flag_value.telemetry
811+
telemetry=feature_flag_value.telemetry,
812+
tags=keyvalue.tags
807813
)
808814

809815
# By Default, we will try to show conditions unless the user has

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@
437437
- name: Set a feature flag with name "Beta" and custom key ".appconfig.featureflag/MyApp1:Beta".
438438
text:
439439
az appconfig feature set -n MyAppConfiguration --feature Beta --key .appconfig.featureflag/MyApp1:Beta
440+
- name: Set a feature flag with name "Beta" and custom key ".appconfig.featureflag/MyApp1:Beta" with tags "tag1=value1" and "tag2=value2".
441+
text:
442+
az appconfig feature set -n MyAppConfiguration --feature Beta --key .appconfig.featureflag/MyApp1:Beta --tags tag1=value1 tag2=value2
440443
"""
441444

442445
helps['appconfig feature delete'] = """
@@ -455,6 +458,9 @@
455458
- name: Delete a feature whose name is "Beta" but key is ".appconfig.featureflag/MyApp1:Beta".
456459
text:
457460
az appconfig feature delete -n MyAppConfiguration --key .appconfig.featureflag/MyApp1:Beta --yes
461+
- name: Delete a feature whose name is "Beta" but key is ".appconfig.featureflag/MyApp1:Beta" with tags "tag1=value1" and "tag2=value2".
462+
text:
463+
az appconfig feature delete -n MyAppConfiguration --key .appconfig.featureflag/MyApp1:Beta --tags tag1=value1 tag2=value2 --yes
458464
"""
459465

460466
helps['appconfig feature show'] = """
@@ -500,6 +506,12 @@
500506
- name: List all features starting with "MyApp1".
501507
text:
502508
az appconfig feature list -n MyAppConfiguration --key .appconfig.featureflag/MyApp1*
509+
- name: List all feature flags with specific tags.
510+
text:
511+
az appconfig feature list -n MyAppConfiguration --tags tag1=value1 tag2=value2
512+
- name: List all feature flags with tag name "tag1" with empty value.
513+
text:
514+
az appconfig feature list -n MyAppConfiguration --tags tag1=
503515
"""
504516

505517
helps['appconfig feature lock'] = """

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,21 @@ def load_arguments(self, _):
367367
c.argument('key', validator=validate_feature_key, help='Key of the feature flag. Key must start with the ".appconfig.featureflag/" prefix. Key cannot contain the "%" character. Default key is the reserved prefix ".appconfig.featureflag/" + feature name.')
368368
c.argument('requirement_type', arg_type=get_enum_type([FeatureFlagConstants.REQUIREMENT_TYPE_ALL, FeatureFlagConstants.REQUIREMENT_TYPE_ANY]),
369369
help='Requirement type determines if filters should use "Any" or "All" logic when evaluating the state of a feature.')
370+
c.argument('tags', arg_type=tags_type)
370371

371372
with self.argument_context('appconfig feature delete') as c:
372373
c.argument('feature', help='Name of the feature to be deleted. If the feature flag key is different from the default key, provide the `--key` argument instead. Support star sign as filters, for instance * means all features and abc* means features with abc as prefix. Comma separated features are not supported. Please provide escaped string if your feature name contains comma.')
373374
c.argument('label', help="If no label specified, delete the feature flag with null label by default. Support star sign as filters, for instance * means all labels and abc* means labels with abc as prefix.")
374375
c.argument('key', validator=validate_feature_key, help='Key of the feature flag. Key must start with the ".appconfig.featureflag/" prefix. Key cannot contain the "%" character. If both key and feature arguments are provided, only key will be used. Support star sign as filters, for instance ".appconfig.featureflag/*" means all features and ".appconfig.featureflag/abc*" means features with abc as prefix. Comma separated features are not supported. Please provide escaped string if your feature name contains comma.')
376+
c.argument('tags', arg_type=tags_arg_type, help="If no tags are specified, delete all feature flags with any tags. Support space-separated tags: key[=value] [key[=value] ...].")
375377

376378
with self.argument_context('appconfig feature list') as c:
377379
c.argument('feature', help='Name of the feature to be listed. If the feature flag key is different from the default key, provide the `--key` argument instead. Support star sign as filters, for instance * means all features and abc* means features with abc as prefix. Comma separated features are not supported. Please provide escaped string if your feature name contains comma.')
378380
c.argument('label', help="If no label specified, list all labels. Support star sign as filters, for instance * means all labels and abc* means labels with abc as prefix. Use '\\0' for null label.")
379381
c.argument('fields', arg_type=feature_fields_arg_type)
380382
c.argument('all_', help="List all feature flags.")
381383
c.argument('key', validator=validate_feature_key, help='Key of the feature flag. Key must start with the ".appconfig.featureflag/" prefix. Key cannot contain the "%" character. If both key and feature arguments are provided, only key will be used. Support star sign as filters, for instance ".appconfig.featureflag/*" means all features and ".appconfig.featureflag/abc*" means features with abc as prefix. Comma separated features are not supported. Please provide escaped string if your feature name contains comma.')
384+
c.argument('tags', arg_type=tags_arg_type, help="If no tags are specified, list all feature flags with any tags. Support space-separated tags: key[=value] [key[=value] ...].")
382385

383386
with self.argument_context('appconfig feature lock') as c:
384387
c.argument('feature', help='Name of the feature to be locked. If the feature flag key is different from the default key, provide the `--key` argument instead.')

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def set_feature(cmd,
5151
yes=False,
5252
connection_string=None,
5353
auth_mode="key",
54-
endpoint=None):
54+
endpoint=None,
55+
tags=None):
5556
if key is None and feature is None:
5657
raise CLIErrors.RequiredArgumentMissingError("Please provide either `--key` or `--feature` value.")
5758

@@ -67,7 +68,6 @@ def set_feature(cmd,
6768
raise exception
6869

6970
# when creating a new Feature flag, these defaults will be used
70-
tags = {}
7171
default_conditions = {FeatureFlagConstants.CLIENT_FILTERS: []}
7272

7373
if requirement_type:
@@ -145,6 +145,7 @@ def set_feature(cmd,
145145

146146
# Convert KeyValue object to required FeatureFlag format for
147147
# display
148+
148149
feature_flag = map_keyvalue_to_featureflag(set_kv, show_all_details=True)
149150
entry = json.dumps(feature_flag, default=lambda o: o.__dict__, indent=2, sort_keys=True, ensure_ascii=False)
150151

@@ -185,7 +186,8 @@ def delete_feature(cmd,
185186
yes=False,
186187
connection_string=None,
187188
auth_mode="key",
188-
endpoint=None):
189+
endpoint=None,
190+
tags=None):
189191
if key is None and feature is None:
190192
raise CLIErrors.RequiredArgumentMissingError("Please provide either `--key` or `--feature` value.")
191193
if key and feature:
@@ -204,9 +206,10 @@ def delete_feature(cmd,
204206
retrieved_keyvalues = __list_all_keyvalues(azconfig_client,
205207
key_filter=key_filter,
206208
label=SearchFilterOptions.EMPTY_LABEL if label is None else label,
207-
correlation_request_id=correlation_request_id)
209+
correlation_request_id=correlation_request_id,
210+
tags=tags)
208211

209-
confirmation_message = "Found '{}' feature flags matching the specified feature and label. Are you sure you want to delete these feature flags?".format(len(retrieved_keyvalues))
212+
confirmation_message = "Found '{}' feature flags matching the specified feature, label, and tags. Are you sure you want to delete these feature flags?".format(len(retrieved_keyvalues))
210213
user_confirmation(confirmation_message, yes)
211214

212215
deleted_kvs = []
@@ -304,7 +307,8 @@ def list_feature(cmd,
304307
top=None,
305308
all_=False,
306309
auth_mode="key",
307-
endpoint=None):
310+
endpoint=None,
311+
tags=None):
308312
return __list_features(
309313
cmd=cmd,
310314
feature=feature,
@@ -316,7 +320,8 @@ def list_feature(cmd,
316320
top=top,
317321
all_=all_,
318322
auth_mode=auth_mode,
319-
endpoint=endpoint
323+
endpoint=endpoint,
324+
tags=tags
320325
)
321326

322327

0 commit comments

Comments
 (0)