Skip to content

Commit

Permalink
[db-up] Release db up with show-connection-string commands (Azure#539)
Browse files Browse the repository at this point in the history
* update connection string commands and readme/history

* release
  • Loading branch information
williexu authored Feb 26, 2019
1 parent 06d67f4 commit 69ac5d6
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 129 deletions.
4 changes: 4 additions & 0 deletions src/db-up/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.1.6 (2019-2-26)
+++++++++++++++++
* `az mysql/postgres show-connection-string` commands to show connection strings without server calls.

0.1.5 (2019-2-1)
++++++++++++++++
* Added Spring JDBC connection string to output.
Expand Down
18 changes: 18 additions & 0 deletions src/db-up/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ az mysql down \
--delete-group
```

Show the connection strings for a database without any server calls.
```
az mysql show-connection-string \
-s serverName \
-d databaseName \
-u adminUsername \
-p adminPassword
```

#### PostgreSQL
Ensures an Azure Database for PostgreSQL server instance is up and running and configured for immediate use with a single command.

Expand All @@ -54,3 +63,12 @@ Clean up the cache and delete the server. Use the `--delete-group` parameter to
az postgres down \
--delete-group
```

Show the connection strings for a database without any server calls.
```
az postgres show-connection-string \
-s serverName \
-d databaseName \
-u adminUsername \
-p adminPassword
```
13 changes: 7 additions & 6 deletions src/db-up/azext_db_up/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
with self.argument_context('{} up'.format(scope)) as c:
c.argument('sku_name', options_list=['--sku-name'], default='GP_Gen5_4',
help='The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.')
c.argument('backup_retention', type=int,
help='The number of days a backup is retained.')
c.argument('backup_retention', type=int, help='The number of days a backup is retained.')
c.argument('geo_redundant_backup', arg_type=get_enum_type(GeoRedundantBackup),
default=GeoRedundantBackup.disabled.value, help='Enable Geo-redundant or not for server backup.')
c.argument('storage_mb', options_list=['--storage-size'], type=int,
Expand All @@ -35,10 +34,12 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
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.')
c.argument('server_name', options_list=['--server-name', '-s'], help='Name of the server.')
c.argument('database_name', options_list=['--database-name', '-d'], help='The name of a database.')
c.argument('administrator_login', options_list=['--admin-user', '-u'],
help='The login username of the administrator.')
c.argument('administrator_login_password', options_list=['--admin-password', '-p'],
help='The login password of the administrator.')

with self.argument_context('{} down'.format(scope)) as c:
c.ignore('server_name')
Expand Down
28 changes: 22 additions & 6 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,23 @@ 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(
server_name='{server}', database_name='{database}', administrator_login='{login}',
administrator_login_password='{password}'):
user = '{}@{}'.format(administrator_login, server_name)
host = '{}.mysql.database.azure.com'.format(server_name)
return _create_mysql_connection_string(host, user, administrator_login_password, database_name)


def create_postgresql_connection_string(
server_name='{server}', database_name='{database}', administrator_login='{login}',
administrator_login_password='{password}'):
user = '{}@{}'.format(administrator_login, server_name)
host = '{}.postgres.database.azure.com'.format(server_name)
return _create_postgresql_connection_string(host, user, administrator_login_password, database_name)


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 All @@ -170,7 +186,7 @@ def create_mysql_connection_string(host, user, password, database):
connection_kwargs = {
'host': host,
'user': user,
'password': password if password is not None else '{your_password}',
'password': password if password is not None else '{password}',
'database': database
}

Expand All @@ -179,7 +195,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 All @@ -199,7 +215,7 @@ def create_postgresql_connection_string(host, user, password, database):
connection_kwargs = {
'host': host,
'user': user,
'password': password if password is not None else '{your_password}',
'password': password if password is not None else '{password}',
'database': database
}

Expand Down
2 changes: 1 addition & 1 deletion src/db-up/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from codecs import open
from setuptools import setup, find_packages

VERSION = "0.1.5"
VERSION = "0.1.6"

CLASSIFIERS = [
'Development Status :: 4 - Beta',
Expand Down
Loading

0 comments on commit 69ac5d6

Please sign in to comment.