From 03c0fecc04729dbbe04e2f4c445bae989b060729 Mon Sep 17 00:00:00 2001 From: Matthew Boentoro Date: Tue, 21 Jan 2025 11:12:48 -0800 Subject: [PATCH] {RDBMS} az postgres flexible-server backup create: add backup name validator --- .../rdbms/flexible_server_custom_postgres.py | 3 ++- .../cli/command_modules/rdbms/validators.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py index b62c6b548fe..0169c71b110 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py @@ -36,7 +36,7 @@ from .flexible_server_virtual_network import prepare_private_network, prepare_private_dns_zone, prepare_public_network from .validators import pg_arguments_validator, validate_server_name, validate_and_format_restore_point_in_time, \ validate_postgres_replica, validate_georestore_network, pg_byok_validator, validate_migration_runtime_server, \ - validate_resource_group, check_resource_group, validate_citus_cluster, cluster_byok_validator + validate_resource_group, check_resource_group, validate_citus_cluster, cluster_byok_validator, validate_backup_name logger = get_logger(__name__) DEFAULT_DB_NAME = 'flexibleserverdb' @@ -1422,6 +1422,7 @@ def virtual_endpoint_update_func(cmd, client, resource_group_name, server_name, def backup_create_func(client, resource_group_name, server_name, backup_name): validate_resource_group(resource_group_name) + validate_backup_name(backup_name) return client.begin_create( resource_group_name, diff --git a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py index 3b4075cb7d0..e196d420e9f 100644 --- a/src/azure-cli/azure/cli/command_modules/rdbms/validators.py +++ b/src/azure-cli/azure/cli/command_modules/rdbms/validators.py @@ -915,3 +915,21 @@ def check_resource_group(resource_group_name): def validate_resource_group(resource_group_name): if not check_resource_group(resource_group_name): raise CLIError('Resource group name cannot be empty.') + + +def validate_backup_name(backup_name): + # check if backup_name is already null originally + if not backup_name: + raise CLIError('Backup name cannot be empty.') + + # replace single and double quotes with empty string + backup_name = backup_name.replace("'", '') + backup_name = backup_name.replace('"', '') + + # check if backup_name is empty or contains only whitespace after removing the quote + if not backup_name or backup_name.isspace(): + raise CLIError('Backup name cannot be empty or contain only whitespaces.') + + # check if backup_name exceeds 128 characters + if len(backup_name) > 128: + raise CLIError('Backup name cannot exceed 128 characters.')