Skip to content

Commit 39121ce

Browse files
committed
Remove comment support for specialized config.
1 parent 019b46b commit 39121ce

File tree

4 files changed

+2444
-2292
lines changed

4 files changed

+2444
-2292
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class KeyVaultConstants:
6363
KEYVAULT_CONTENT_TYPE = "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8"
6464

6565

66+
class AIConfigConstants:
67+
AI_CHAT_COMPLETION_CONTENT_TYPE = "application/vnd.microsoft.appconfig.aichatcompletion+json;charset=utf-8"
68+
69+
6670
class AppServiceConstants:
6771
APPSVC_CONFIG_REFERENCE_PREFIX = "@Microsoft.AppConfiguration"
6872
APPSVC_KEYVAULT_PREFIX = "@Microsoft.KeyVault"

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
)
3636
from knack.log import get_logger
3737
from knack.util import CLIError
38-
from ._constants import HttpHeaders
3938

4039
from azure.appconfiguration import (ConfigurationSetting,
4140
ResourceReadOnlyError)
@@ -50,7 +49,8 @@
5049
from ._constants import (FeatureFlagConstants, KeyVaultConstants,
5150
SearchFilterOptions, StatusCodes,
5251
ImportExportProfiles, CompareFieldsMap,
53-
JsonDiff, ImportMode)
52+
JsonDiff, ImportMode,
53+
AIConfigConstants, HttpHeaders)
5454
from ._featuremodels import map_keyvalue_to_featureflag
5555
from ._json import parse_json_with_comments
5656
from ._models import (convert_configurationsetting_to_keyvalue, convert_keyvalue_to_configurationsetting)
@@ -511,7 +511,7 @@ def set_key(cmd,
511511
# Ensure that provided value is valid JSON and strip comments if needed.
512512
value = 'null' if value is None else value
513513

514-
parse_json_with_comments(value)
514+
__validate_json_value(value, content_type)
515515
except ValueError:
516516
raise CLIErrors.ValidationError('Value "{}" is not a valid JSON object, which conflicts with the content type "{}".'.format(value, content_type))
517517

@@ -526,7 +526,7 @@ def set_key(cmd,
526526
if is_json_content_type(content_type):
527527
try:
528528
# Ensure that provided value is valid JSON and strip comments if needed.
529-
parse_json_with_comments(value)
529+
__validate_json_value(value, content_type)
530530
except (TypeError, ValueError):
531531
raise CLIErrors.ValidationError('Value "{}" is not a valid JSON object, which conflicts with the content type "{}". Set the value again in valid JSON format.'.format(value, content_type))
532532
set_kv = ConfigurationSetting(key=key,
@@ -986,3 +986,12 @@ def list_revision(cmd,
986986
return retrieved_revisions
987987
except HttpResponseError as ex:
988988
raise CLIErrors.AzureResponseError('List revision operation failed.\n' + str(ex))
989+
990+
991+
def __validate_json_value(json_string, content_type):
992+
# We do not allow comments in keyvault references, feature flags, and AI chat completion configs
993+
if content_type in (FeatureFlagConstants.FEATURE_FLAG_CONTENT_TYPE, KeyVaultConstants.KEYVAULT_CONTENT_TYPE, AIConfigConstants.AI_CHAT_COMPLETION_CONTENT_TYPE):
994+
json.loads(json_string)
995+
996+
else:
997+
parse_json_with_comments(json_string)

0 commit comments

Comments
 (0)