Skip to content
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 @@ -130,7 +130,7 @@ class FeatureFilter:

:ivar str Name:
Name of the filter
:ivar dict {str, str} parameters:
:ivar dict parameters:
Name-Value pairs of parameters
'''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
examples:
- name: Add a filter for feature 'color' with label MyLabel with name 'MyFilter' and 2 parameters.
text:
az appconfig feature filter add -n MyAppConfiguration --feature color --label MyLabel --filter-name MyFilter --filter-parameters Name=Value Name2=Value2
az appconfig feature filter add -n MyAppConfiguration --feature color --label MyLabel --filter-name MyFilter --filter-parameters Name=\\"Value\\" Name2=\\"Value2\\"
- name: Insert a filter at index 2 (zero-based index) for feature 'color' with label MyLabel and filter name 'MyFilter' with no parameters
text:
az appconfig feature filter add -n MyAppConfiguration --feature color --label MyLabel --filter-name MyFilter --index 2
Expand All @@ -430,6 +430,9 @@
- name: Add a filter with name 'MyFilter' using App Configuration endpoint and your 'az login' credentials.
text:
az appconfig feature filter add --endpoint=https://contoso.azconfig.io --feature color --filter-name MyFilter --auth-mode login
- name: Add a filter for feature 'color' with label MyLabel with name 'MyFilter' and array parameters.
text:
az appconfig feature filter add -n MyAppConfiguration --feature color --label MyLabel --filter-name MyFilter --filter-parameters ArrayParam=[1,2,3]
"""

helps['appconfig feature filter delete'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def load_arguments(self, _):
)
filter_parameters_arg_type = CLIArgumentType(
validator=validate_filter_parameters,
help="Space-separated filter parameters in 'name[=value]' format.",
help="Space-separated filter parameters in 'name[=value]' format. The value must be an escaped JSON string.",
nargs='*'
)
datatime_filter_arg_type = CLIArgumentType(
Expand Down
32 changes: 21 additions & 11 deletions src/azure-cli/azure/cli/command_modules/appconfig/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# pylint: disable=line-too-long

import json
import re
from knack.log import get_logger
from knack.util import CLIError
Expand Down Expand Up @@ -141,15 +142,10 @@ def validate_filter_parameters(namespace):
if param_tuple:
# pylint: disable=unbalanced-tuple-unpacking
param_name, param_value = param_tuple
# If param_name already exists, convert the values to a list
# If param_name already exists, error out
if param_name in filter_parameters_dict:
old_param_value = filter_parameters_dict[param_name]
if isinstance(old_param_value, list):
old_param_value.append(param_value)
else:
filter_parameters_dict[param_name] = [old_param_value, param_value]
else:
filter_parameters_dict.update({param_name: param_value})
raise CLIError('Filter parameter name "{}" cannot be duplicated.'.format(param_name))
filter_parameters_dict.update({param_name: param_value})
namespace.filter_parameters = filter_parameters_dict


Expand All @@ -158,11 +154,25 @@ def validate_filter_parameter(string):
result = ()
if string:
comps = string.split('=', 1)
# Ignore invalid arguments like '=value' or '='

if comps[0]:
result = (comps[0], comps[1]) if len(comps) > 1 else (string, '')
if len(comps) > 1:
# In the portal, if value textbox is blank we store the value as empty string.
# In CLI, we should allow inputs like 'name=', which correspond to empty string value.
# But there is no way to differentiate between CLI inputs 'name=' and 'name=""'.
# So even though "" is invalid JSON escaped string, we will accept it and set the value as empty string.
filter_param_value = '\"\"' if comps[1] == "" else comps[1]
try:
# Ensure that provided value of this filter parameter is valid JSON. Error out if value is invalid JSON.
filter_param_value = json.loads(filter_param_value)
except ValueError:
raise CLIError('Filter parameter value must be a JSON escaped string. "{}" is not a valid JSON object.'.format(filter_param_value))
result = (comps[0], filter_param_value)
else:
result = (string, '')
else:
logger.warning("Ignoring filter parameter '%s' because parameter name is empty.", string)
# Error out on invalid arguments like '=value' or '='
raise CLIError('Invalid filter parameter "{}". Parameter name cannot be empty.'.format(string))
return result


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Color": "Red",
"Region": "West US",
"FeatureManagement": {
"feature_management": {
"Beta": false,
"Percentage": true,
"Timestamp": {
"EnabledFor": [
"enabled_for": [
{
"Name": "Local Tests",
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Dec 28 11:55:37 Pacific Standard Time 2020
#Wed Jan 13 17:05:25 Pacific Standard Time 2021
Color=Red
Region=West US
feature-management.FalseFeature=false
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading