Skip to content

Commit

Permalink
{RDBMS} az postgres flexible-server restore: Add empty string valid…
Browse files Browse the repository at this point in the history
…ation to resource group name (Azure#29916)

* add validation to resource group name to remove empty string

* fix linting issue

* add tests

* fix the recording

* fix the issue with failing test

* Revert "fix the issue with failing test"

This reverts commit e3d174d.

* fix the issue with test recording

---------

Co-authored-by: Matthew Boentoro <mboentoro@microsoft.com>
  • Loading branch information
mattboentoro and Matthew Boentoro authored Oct 10, 2024
1 parent 764bd69 commit 5cbb8ef
Show file tree
Hide file tree
Showing 5 changed files with 1,369 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,46 @@
from ._client_factory import cf_postgres_flexible_replica
from ._flexible_server_util import run_subprocess, run_subprocess_get_output, \
fill_action_template, get_git_root_dir, resolve_poller, GITHUB_ACTION_PATH
from .validators import validate_public_access_server
from .validators import validate_public_access_server, validate_resource_group, check_resource_group

logger = get_logger(__name__)
# pylint: disable=raise-missing-from


# Common functions used by other providers
def flexible_server_update_get(client, resource_group_name, server_name):
validate_resource_group(resource_group_name)

return client.get(resource_group_name, server_name)


def flexible_server_stop(client, resource_group_name=None, server_name=None, no_wait=False):
if (not check_resource_group(resource_group_name)):
resource_group_name = None

days = 7
logger.warning("Server will be automatically started after %d days "
"if you do not perform a manual start operation", days)
return sdk_no_wait(no_wait, client.begin_stop, resource_group_name, server_name)


def flexible_server_update_set(client, resource_group_name, server_name, parameters):
validate_resource_group(resource_group_name)

return client.begin_update(resource_group_name, server_name, parameters)


def server_list_custom_func(client, resource_group_name=None):
if (not check_resource_group(resource_group_name)):
resource_group_name = None

if resource_group_name:
return client.list_by_resource_group(resource_group_name)
return client.list()


def firewall_rule_delete_func(cmd, client, resource_group_name, server_name, firewall_rule_name, yes=None):
validate_resource_group(resource_group_name)
validate_public_access_server(cmd, client, resource_group_name, server_name)

result = None
Expand All @@ -61,7 +72,7 @@ def firewall_rule_delete_func(cmd, client, resource_group_name, server_name, fir


def firewall_rule_create_func(cmd, client, resource_group_name, server_name, firewall_rule_name=None, start_ip_address=None, end_ip_address=None):

validate_resource_group(resource_group_name)
validate_public_access_server(cmd, client, resource_group_name, server_name)

if end_ip_address is None and start_ip_address is not None:
Expand Down Expand Up @@ -102,11 +113,14 @@ def firewall_rule_create_func(cmd, client, resource_group_name, server_name, fir


def flexible_firewall_rule_custom_getter(cmd, client, resource_group_name, server_name, firewall_rule_name):
validate_resource_group(resource_group_name)
validate_public_access_server(cmd, client, resource_group_name, server_name)
return client.get(resource_group_name, server_name, firewall_rule_name)


def flexible_firewall_rule_custom_setter(client, resource_group_name, server_name, firewall_rule_name, parameters):
validate_resource_group(resource_group_name)

return client.begin_create_or_update(
resource_group_name,
server_name,
Expand All @@ -123,16 +137,21 @@ def flexible_firewall_rule_update_custom_func(instance, start_ip_address=None, e


def firewall_rule_get_func(cmd, client, resource_group_name, server_name, firewall_rule_name):
validate_resource_group(resource_group_name)
validate_public_access_server(cmd, client, resource_group_name, server_name)
return client.get(resource_group_name, server_name, firewall_rule_name)


def firewall_rule_list_func(cmd, client, resource_group_name, server_name):
validate_resource_group(resource_group_name)
validate_public_access_server(cmd, client, resource_group_name, server_name)
return client.list_by_server(resource_group_name, server_name)


def database_delete_func(client, resource_group_name=None, server_name=None, database_name=None, yes=None):
if (not check_resource_group(resource_group_name)):
resource_group_name = None

result = None
if resource_group_name is None or server_name is None or database_name is None:
raise CLIError("Incorrect Usage : Deleting a database needs resource-group, server-name and database-name. "
Expand All @@ -152,6 +171,8 @@ def database_delete_func(client, resource_group_name=None, server_name=None, dat


def create_firewall_rule(db_context, cmd, resource_group_name, server_name, start_ip, end_ip):
validate_resource_group(resource_group_name)

# allow access to azure ip addresses
cf_firewall = db_context.cf_firewall # NOQA pylint: disable=unused-variable
firewall_client = cf_firewall(cmd.cli_ctx, None)
Expand All @@ -164,6 +185,7 @@ def create_firewall_rule(db_context, cmd, resource_group_name, server_name, star


def github_actions_setup(cmd, client, resource_group_name, server_name, database_name, administrator_login, administrator_login_password, sql_file_path, repository, action_name=None, branch=None, allow_push=None):
validate_resource_group(resource_group_name)

server = client.get(resource_group_name, server_name)
if server.network.public_network_access == 'Disabled':
Expand Down Expand Up @@ -217,6 +239,7 @@ def gitcli_check_and_login():

# Custom functions for server logs
def flexible_server_log_download(client, resource_group_name, server_name, file_name):
validate_resource_group(resource_group_name)

files = client.list_by_server(resource_group_name, server_name)

Expand All @@ -227,6 +250,7 @@ def flexible_server_log_download(client, resource_group_name, server_name, file_

def flexible_server_log_list(client, resource_group_name, server_name, filename_contains=None,
file_last_written=None, max_file_size=None):
validate_resource_group(resource_group_name)

all_files = client.list_by_server(resource_group_name, server_name)
files = []
Expand All @@ -250,6 +274,8 @@ def flexible_server_log_list(client, resource_group_name, server_name, filename_


def flexible_server_version_upgrade(cmd, client, resource_group_name, server_name, version, yes=None):
validate_resource_group(resource_group_name)

if not yes:
user_confirmation(
"Upgrading major version in server {} is irreversible. The action you're about to take can't be undone. "
Expand Down
Loading

0 comments on commit 5cbb8ef

Please sign in to comment.