Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{RDBMS} az postgres flexible-server backup create: add backup name validator #30687

Merged
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 @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Loading