Skip to content

Commit

Permalink
{rdbms-connect} Update compatible release version for setproctitle to…
Browse files Browse the repository at this point in the history
… support Python 3.11 (Azure#7138)

* Update compatible release version for setproctitle to support Python 3.11

* Adding dependency for cryotpgraphy for failing builds

* Upgrade mycli and pgcli dependencies to latest versions

* Downgrade version for cryptography

* Fix azdev style errors

* Update mycli dependency

* Rmove dependency on cryptography package
  • Loading branch information
ambrahma authored and blackchoey committed Apr 29, 2024
1 parent 8ffbb80 commit 2abdb47
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/rdbms-connect/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.0.5
++++++
+ Use compatible release for `setproctitle` to support Python 3.11

1.0.4
++++++
+ Update mycli and pgcli versions
Expand Down
10 changes: 5 additions & 5 deletions src/rdbms-connect/azext_rdbms_connect/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def load_arguments(self, _):
for command_group in ('mysql', 'postgres'):
server_name_arg_type = CLIArgumentType(metavar='NAME',
help="Name of the server. The name can contain only lowercase letters, numbers, and the hyphen (-) character. Minimum 3 characters and maximum 63 characters.",
local_context_attribute=LocalContextAttribute(name='server_name', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=['{} flexible-server'.format(command_group)]))
local_context_attribute=LocalContextAttribute(name='server_name', actions=[LocalContextAction.SET, LocalContextAction.GET], scopes=[f'{command_group} flexible-server']))

administrator_login_arg_type = CLIArgumentType(metavar='NAME',
local_context_attribute=LocalContextAttribute(name='administrator_login', actions=[LocalContextAction.GET, LocalContextAction.SET], scopes=['{} flexible-server'.format(command_group)]))
local_context_attribute=LocalContextAttribute(name='administrator_login', actions=[LocalContextAction.GET, LocalContextAction.SET], scopes=[f'{command_group} flexible-server']))

database_name_arg_type = CLIArgumentType(metavar='NAME',
local_context_attribute=LocalContextAttribute(name='database_name', actions=[LocalContextAction.GET, LocalContextAction.SET], scopes=['{} flexible-server'.format(command_group)]))
local_context_attribute=LocalContextAttribute(name='database_name', actions=[LocalContextAction.GET, LocalContextAction.SET], scopes=[f'{command_group} flexible-server']))

with self.argument_context('{} flexible-server connect'.format(command_group)) as c:
with self.argument_context(f'{command_group} flexible-server connect') as c:
c.argument('server_name', id_part=None, options_list=['--name', '-n'], arg_type=server_name_arg_type)
c.argument('administrator_login', arg_group='Authentication', arg_type=administrator_login_arg_type, options_list=['--admin-user', '-u'],
help='The login username of the administrator.')
Expand All @@ -31,7 +31,7 @@ def load_arguments(self, _):
c.argument('interactive_mode', options_list=['--interactive'], action='store_true', help='Pass this parameter to connect to database in interactive mode.')
c.argument('querytext', options_list=['--querytext', '-q'], deprecate_info=c.deprecate(redirect='execute'), help='A query to run against the flexible server.')

with self.argument_context('{} flexible-server execute'.format(command_group)) as c:
with self.argument_context(f'{command_group} flexible-server execute') as c:
c.argument('server_name', id_part=None, options_list=['--name', '-n'], arg_type=server_name_arg_type)
c.argument('administrator_login', arg_group='Authentication', arg_type=administrator_login_arg_type, options_list=['--admin-user', '-u'],
help='The login username of the administrator.')
Expand Down
15 changes: 7 additions & 8 deletions src/rdbms-connect/azext_rdbms_connect/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def execute_flexible_server_postgres(cmd, server_name, administrator_login, admi
def connect_to_server_helper(server_type, endpoint, default_db_name, server_name, administrator_login,
administrator_login_password, database_name, query_command=None,
interactive=None, file_path=None):
host = '{}{}'.format(server_name, endpoint)
host = f'{server_name}{endpoint}'
json_data = None

# setup or validate passed in params:
Expand Down Expand Up @@ -155,13 +155,12 @@ def _connect_interactive(server_type, host, server_name, database_name, login_us
set_environment_paths(EXTENSIONS_DIR)

if server_type == "postgres":
cmd = "pgcli -h {0} -u {1} -W {2}".format(host, login_username, database_name)
cmd = f"pgcli -h {host} -u {login_username} -W {database_name}"
else:
cmd = "mycli -h {0} -u {1} {2} --ssl-verify-server-cert".format(host, login_username,
database_name)
cmd = f"mycli -h {host} -u {login_username} {database_name} --ssl-verify-server-cert"
os.system(cmd)
except Exception as e:
raise AzureConnectionError("Unable to open interactive mode to {0}. Error: {1}".format(server_name, e))
raise AzureConnectionError(f"Unable to open interactive mode to {server_name}. Error: {e}")


def _connect_execute_query(server_type, host, server_name, database_name, login_username, login_pw, query=None):
Expand Down Expand Up @@ -189,7 +188,7 @@ def _connect_execute_query(server_type, host, server_name, database_name, login_
except Exception as e:
logger.warning("Failed connection to %s. Check error and validate firewall and public access "
"or virtual network settings.", server_name)
raise AzureConnectionError("Unable to connect to flexible server: {}".format(e))
raise AzureConnectionError(f"Unable to connect to flexible server: {e}")

if query is not None:
try:
Expand All @@ -207,7 +206,7 @@ def _connect_execute_query(server_type, host, server_name, database_name, login_
for rv in result:
json_data.append(dict(zip(row_headers, rv)))
except Exception as e:
raise CLIError("Unable to execute query '{0}': {1}".format(query, e))
raise CLIError(f"Unable to execute query '{query}': {e}")
finally:
try:
cursor.close()
Expand Down Expand Up @@ -244,7 +243,7 @@ def _connect_execute_file(server_type, host, server_name, database_name, login_u
except Exception as e:
logger.warning("Failed connection to %s. Check error and validate firewall and public access "
"or virtual network settings.", server_name)
raise AzureConnectionError("Unable to connect to flexible server: {}".format(e))
raise AzureConnectionError(f"Unable to connect to flexible server: {e}")

# Execute the file
fail_flag = False
Expand Down
8 changes: 4 additions & 4 deletions src/rdbms-connect/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '1.0.4'
VERSION = '1.0.5'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand All @@ -33,10 +33,10 @@
]

DEPENDENCIES = [
'setproctitle~=1.2.2',
'setproctitle~=1.3.3',
'psycopg2==2.9.3',
'mycli==1.26.1',
'pgcli==3.4.1'
'mycli~=1.27.0',
'pgcli==4.0.1'
]

with open('README.rst', 'r', encoding='utf-8') as f:
Expand Down

0 comments on commit 2abdb47

Please sign in to comment.