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

Azure PostgreSQL and Azure MySQL CLI extension. #67

Merged
merged 9 commits into from
Feb 23, 2018
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
/src/subscription/ @wilcobmsft

/src/managementgroups/ @rajshah11

/src/rdbms/ @rohit-joy
47 changes: 46 additions & 1 deletion src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,51 @@
"version": "0.1.0"
}
}
]
],
"rdbms": [
{
"filename": "rdbms-0.0.1-py2.py3-none-any.whl",
"sha256Digest": "79ebef22a4d68f2a3f1909523357aadf6167def54d2ba4de84d1b9932fcb9eac",
"downloadUrl": "https://prodrdbmsclipackages.blob.core.windows.net/cliextensions/rdbms-0.0.1-py2.py3-none-any.whl",
"metadata": {
"classifiers": [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"License :: OSI Approved :: MIT License"
],
"extensions": {
"python.details": {
"contacts": [
{
"email": "rohitjoy@microsoft.com",
"name": "Rohit Joy",
"role": "author"
}
],
"document_names": {
"description": "DESCRIPTION.rst"
},
"project_urls": {
"Home": "https://github.com/Azure/azure-cli-extensions"
}
}
},
"generator": "bdist_wheel (0.29.0)",
"license": "MIT",
"metadata_version": "2.0",
"name": "rdbms",
"summary": "An Azure CLI extension to manage Azure MySQL and Azure PostgreSQL resources",
"version": "0.0.1"
}
}
]
}
}
32 changes: 32 additions & 0 deletions src/rdbms/azext_rdbms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

import azext_rdbms._help # pylint: disable=unused-import


class RdbmsExtCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_rdbms._util import RdbmsArgumentContext
rdbms_custom = CliCommandType(operations_tmpl='azext_rdbms.custom#{}')
super(RdbmsExtCommandsLoader, self).__init__(cli_ctx=cli_ctx,
min_profile='2017-03-10-profile',
custom_command_type=rdbms_custom,
argument_context_cls=RdbmsArgumentContext)

def load_command_table(self, args):
from azext_rdbms.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_rdbms._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = RdbmsExtCommandsLoader
112 changes: 112 additions & 0 deletions src/rdbms/azext_rdbms/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client

# CLIENT FACTORIES

RM_URI_OVERRIDE = 'AZURE_CLI_RDBMS_RM_URI'
SUB_ID_OVERRIDE = 'AZURE_CLI_RDBMS_SUB_ID'
CLIENT_ID = 'AZURE_CLIENT_ID'
TENANT_ID = 'AZURE_TENANT_ID'
CLIENT_SECRET = 'AZURE_CLIENT_SECRET'


def get_mysql_management_client(cli_ctx, **_):
from os import getenv
from azext_rdbms.mysql import MySQLManagementClient

# Allow overriding resource manager URI using environment variable
# for testing purposes. Subscription id is also determined by environment
# variable.
rm_uri_override = getenv(RM_URI_OVERRIDE)
if rm_uri_override:
client_id = getenv(CLIENT_ID)
if client_id:
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=getenv(CLIENT_SECRET),
tenant=getenv(TENANT_ID))
else:
from msrest.authentication import Authentication # pylint: disable=import-error
credentials = Authentication()

return MySQLManagementClient(
subscription_id=getenv(SUB_ID_OVERRIDE),
base_url=rm_uri_override,
credentials=credentials)
else:
# Normal production scenario.
return get_mgmt_service_client(cli_ctx, MySQLManagementClient)


def get_postgresql_management_client(cli_ctx, **_):
from os import getenv
from azext_rdbms.postgresql import PostgreSQLManagementClient

# Allow overriding resource manager URI using environment variable
# for testing purposes. Subscription id is also determined by environment
# variable.
rm_uri_override = getenv(RM_URI_OVERRIDE)
if rm_uri_override:
client_id = getenv(CLIENT_ID)
if client_id:
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=getenv(CLIENT_SECRET),
tenant=getenv(TENANT_ID))
else:
from msrest.authentication import Authentication # pylint: disable=import-error
credentials = Authentication()

return PostgreSQLManagementClient(
subscription_id=getenv(SUB_ID_OVERRIDE),
base_url=rm_uri_override,
credentials=credentials)
else:
# Normal production scenario.
return get_mgmt_service_client(cli_ctx, PostgreSQLManagementClient)


def cf_mysql_servers(cli_ctx, _):
return get_mysql_management_client(cli_ctx).servers


def cf_postgres_servers(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).servers


def cf_mysql_firewall_rules(cli_ctx, _):
return get_mysql_management_client(cli_ctx).firewall_rules


def cf_postgres_firewall_rules(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).firewall_rules


def cf_mysql_config(cli_ctx, _):
return get_mysql_management_client(cli_ctx).configurations


def cf_postgres_config(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).configurations


def cf_mysql_log(cli_ctx, _):
return get_mysql_management_client(cli_ctx).log_files


def cf_postgres_log(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).log_files


def cf_mysql_db(cli_ctx, _):
return get_mysql_management_client(cli_ctx).databases


def cf_postgres_db(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).databases
Loading