Skip to content

Commit

Permalink
Fix styling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nasc17 committed Oct 29, 2024
1 parent c299dd8 commit 1e45b53
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,12 @@ def flexible_server_update_custom_func(cmd, client, instance,
byok_key=byok_key)

auth_config = instance.auth_config
administrator_login = None
administrator_login = instance.administrator_login if instance.administrator_login else None
if active_directory_auth:
auth_config.active_directory_auth = active_directory_auth
if password_auth:
if auth_config.password_auth.lower() == 'disabled' and password_auth.lower() == 'enabled':
administrator_login = instance.administrator_login if instance.administrator_login else prompt('Please enter administrator username for the server. Once set, it cannot be changed: ')
if not administrator_login:
raise CLIError('Administrator username is required for enabling password authentication.')
if not administrator_login_password:
administrator_login_password = generate_password(administrator_login_password)
logger.warning('Make a note of password "%s". You can '
'reset your password with "az postgres flexible-server update -n %s -g %s -p <new-password>".',
administrator_login_password, server_name, resource_group_name)
administrator_login, administrator_login_password = _update_login(server_name, resource_group_name, auth_config,
password_auth, administrator_login, administrator_login_password)
auth_config.password_auth = password_auth

params = ServerForUpdate(sku=instance.sku,
Expand Down Expand Up @@ -1530,6 +1523,20 @@ def _create_migration(cmd, logging_name, client, subscription_id, resource_group
return client.create(subscription_id, resource_group_name, target_db_server_name, migration_name, migration_parameters)


def _update_login(server_name, resource_group_name, auth_config, password_auth, administrator_login, administrator_login_password):
if auth_config.password_auth.lower() == 'disabled' and password_auth.lower() == 'enabled':
administrator_login = administrator_login if administrator_login else prompt('Please enter administrator username for the server. Once set, it cannot be changed: ')
if not administrator_login:
raise CLIError('Administrator username is required for enabling password authentication.')
if not administrator_login_password:
administrator_login_password = generate_password(administrator_login_password)
logger.warning('Make a note of password "%s". You can '
'reset your password with "az postgres flexible-server update -n %s -g %s -p <new-password>".',
administrator_login_password, server_name, resource_group_name)

return administrator_login, administrator_login_password


# pylint: disable=too-many-instance-attributes, too-few-public-methods, useless-object-inheritance
class DbContext(object):
def __init__(self, cmd=None, azure_sdk=None, logging_name=None, cf_firewall=None, cf_db=None,
Expand Down

0 comments on commit 1e45b53

Please sign in to comment.