Skip to content

Commit

Permalink
[AppConfig] az appconfig kv delete/set/set-keyvault: Add key valida…
Browse files Browse the repository at this point in the history
…tions for null or empty space key parameter (#26928)
  • Loading branch information
albertofori authored Jul 19, 2023
1 parent 7a22417 commit 297ed6b
Show file tree
Hide file tree
Showing 4 changed files with 1,630 additions and 1,390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def load_arguments(self, _):
c.argument('secret_identifier', validator=validate_secret_identifier, help="ID of the Key Vault object. Can be found using 'az keyvault {collection} show' command, where collection is key, secret or certificate. To set reference to the latest version of your secret, remove version information from secret identifier.")

with self.argument_context('appconfig kv delete') as c:
c.argument('key', help='Support star sign as filters, for instance * means all key and abc* means keys with abc as prefix.')
c.argument('key', validator=validate_key, help='Support star sign as filters, for instance * means all key and abc* means keys with abc as prefix.')
c.argument('label', help="If no label specified, delete entry with null label. Support star sign as filters, for instance * means all label and abc* means labels with abc as prefix.")

with self.argument_context('appconfig kv show') as c:
Expand Down
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/appconfig/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ def validate_secret_identifier(namespace):


def validate_key(namespace):
if namespace.key:
input_key = str(namespace.key).lower()
if input_key == '.' or input_key == '..' or '%' in input_key:
raise InvalidArgumentValueError("Key is invalid. Key cannot be a '.' or '..', or contain the '%' character.")
else:
if not namespace.key or str(namespace.key).isspace():
raise RequiredArgumentMissingError("Key cannot be empty.")

input_key = str(namespace.key).lower()
if input_key == '.' or input_key == '..' or '%' in input_key:
raise InvalidArgumentValueError("Key is invalid. Key cannot be a '.' or '..', or contain the '%' character.")


def validate_resolve_keyvault(namespace):
if namespace.resolve_keyvault:
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from azure.cli.testsdk.scenario_tests import AllowLargeResponse, RecordingProcessor
from azure.cli.testsdk.scenario_tests.utilities import is_json_payload
from azure.core.exceptions import ResourceNotFoundError
from azure.cli.core.azclierror import ResourceNotFoundError as CliResourceNotFoundError
from azure.cli.core.azclierror import ResourceNotFoundError as CliResourceNotFoundError, RequiredArgumentMissingError
from azure.cli.core.util import shell_safe_json_parse

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
Expand Down Expand Up @@ -411,6 +411,10 @@ def test_azconfig_kv(self, resource_group, location):
'appconfig revision list -n {config_store_name} --key {key} --label *').get_output_in_json()
assert len(revisions) == 3

# Confirm that delete action errors out for empty or whitespace key
with self.assertRaisesRegex(RequiredArgumentMissingError, "Key cannot be empty."):
self.cmd('appconfig kv delete -n {config_store_name} --key " " -y')

# IN CLI, since we support delete by key/label filters, return is a list of deleted items
deleted = self.cmd('appconfig kv delete -n {config_store_name} --key {key} --label {label} -y',
checks=[self.check('[0].key', entry_key),
Expand Down

0 comments on commit 297ed6b

Please sign in to comment.