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

[db-up] add connection string commands #537

Merged
merged 1 commit into from
Feb 22, 2019
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
add connection string commands
  • Loading branch information
williexu committed Feb 22, 2019
commit 7ca6e6aac548c007bf9f06c4f9d24f3ebc8fc379
10 changes: 10 additions & 0 deletions src/db-up/azext_db_up/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@
- name: Delete the resource group and the full cache.
text: az postgres down --delete-group
"""

helps['mysql show-connection-string'] = """
type: command
short-summary: Show the connection strings for a MySQL server database.
"""

helps['postgres show-connection-string'] = """
type: command
short-summary: Show the connection strings for a PostgreSQL server database.
"""
6 changes: 6 additions & 0 deletions src/db-up/azext_db_up/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
help='The name of a database to initialize.')
c.argument('tags', tags_type)

with self.argument_context('{} show-connection-string'.format(scope)) as c:
c.argument('database', help='The database to connect to.')
c.argument('host', help='The host name or IP address of the MySQL server.')
c.argument('password', help='The login password of the user.')
c.argument('user', help='The login username.')

with self.argument_context('{} down'.format(scope)) as c:
c.ignore('server_name')
c.ignore('resource_group_name')
Expand Down
2 changes: 2 additions & 0 deletions src/db-up/azext_db_up/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def load_command_table(self, _): # pylint: disable=too-many-locals, too-many-st
table_transformer=table_transform_connection_string)
g.custom_command('down', 'server_down', validator=db_down_namespace_processor('mysql'), supports_no_wait=True,
confirmation=True)
g.custom_command('show-connection-string', 'create_mysql_connection_string')

with self.command_group('postgres', postgres_servers_sdk, client_factory=cf_postgres_servers) as g:
g.custom_command('up', 'postgres_up', validator=db_up_namespace_processor('postgres'),
table_transformer=table_transform_connection_string)
g.custom_command('down', 'server_down', validator=db_down_namespace_processor('postgres'),
supports_no_wait=True, confirmation=True)
g.custom_command('show-connection-string', 'create_postgresql_connection_string')
8 changes: 4 additions & 4 deletions src/db-up/azext_db_up/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def mysql_up(cmd, client, resource_group_name=None, server_name=None, location=N
_run_mysql_commands(host, user, administrator_login_password, database_name)

return {
'connectionStrings': _create_mysql_connection_string(
'connectionStrings': create_mysql_connection_string(
host, user, administrator_login_password, database_name),
'host': host,
'username': user,
Expand Down Expand Up @@ -128,7 +128,7 @@ def postgres_up(cmd, client, resource_group_name=None, server_name=None, locatio
_run_postgresql_commands(host, user, administrator_login_password, database_name)

return {
'connectionStrings': _create_postgresql_connection_string(
'connectionStrings': create_postgresql_connection_string(
host, user, administrator_login_password, database_name),
'host': host,
'username': user,
Expand All @@ -149,7 +149,7 @@ def server_down(cmd, client, resource_group_name=None, server_name=None, delete_
return client.delete(resource_group_name, server_name)


def _create_mysql_connection_string(host, user, password, database):
def create_mysql_connection_string(host, user, password, database):
result = {
'mysql_cmd': "mysql {database} --host {host} --user {user} --password={password}",
'ado.net': "Server={host}; Port=3306; Database={database}; Uid={user}; Pwd={password};",
Expand Down Expand Up @@ -179,7 +179,7 @@ def _create_mysql_connection_string(host, user, password, database):
return result


def _create_postgresql_connection_string(host, user, password, database):
def create_postgresql_connection_string(host, user, password, database):
result = {
'psql_cmd': "psql --host={host} --port=5432 --username={user} --dbname={database}",
'ado.net': "Server={host};Database={database};Port=5432;User Id={user};Password={password};",
Expand Down