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

Initial PR for SignalR Service preview CLI extension #142

Merged
merged 11 commits into from
Apr 25, 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
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

/src/managementpartner/ @jeffrey-ace

/src/dns/ @muwaqar
/src/dns/ @muwaqar

/src/signalr/ @zackliu
47 changes: 47 additions & 0 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,53 @@
"version": "0.0.2"
}
}
],
"signalr": [
{
"filename": "signalr-0.1.0-py2.py3-none-any.whl",
"sha256Digest": "0cd98580aa10b660602c1b4496c9beef24cf9c8e15df8113b2642c75457772ee",
"downloadUrl": "https://azureclisignalr.blob.core.windows.net/cli-extensions/signalr-0.1.0-py2.py3-none-any.whl",
"metadata": {
"azext.minCliCoreVersion": "2.0.32.dev0",
"azext.isPreview": true,
"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": "vscsignalr@microsoft.com",
"name": "Visual Studio China SignalR Team",
"role": "author"
}
],
"document_names": {
"description": "DESCRIPTION.rst"
},
"project_urls": {
"Home": "https://github.com/Azure/azure-cli-extensions"
}
}
},
"generator": "bdist_wheel (0.30.0)",
"license": "MIT",
"metadata_version": "2.0",
"name": "signalr",
"summary": "Support for signalr management preview.",
"version": "0.1.0"
}
}
]
}
}
27 changes: 27 additions & 0 deletions src/signalr/azext_signalr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# 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_signalr._help # pylint: disable=unused-import


class SignalRCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
super(SignalRCommandsLoader, self).__init__(cli_ctx=cli_ctx,
min_profile='2017-03-10-profile')

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

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


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


def _signalr_client_factory(cli_ctx, *_):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary to have this function as the only reference is in cf_signalr. These two methods can be merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the general pattern though used in other modules. Makes it easy to add new client factories later.

from azext_signalr.signalr import SignalRManagementClient
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(cli_ctx, SignalRManagementClient)


def cf_signalr(cli_ctx, *_):
return _signalr_client_factory(cli_ctx).signal_r
9 changes: 9 additions & 0 deletions src/signalr/azext_signalr/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


SIGNALR_SKU = ['Basic_DS2']
SIGNALR_RESOURCE_TYPE = 'Microsoft.SignalRService/SignalR'
SIGNALR_KEY_TYPE = ['primary', 'secondary']
74 changes: 74 additions & 0 deletions src/signalr/azext_signalr/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


from knack.help_files import helps

helps['signalr'] = """
type: group
short-summary: Manage Azure SignalR Service.
"""

helps['signalr key'] = """
type: group
short-summary: Manage keys for Azure SignalR Service.
"""

helps['signalr list'] = """
type: command
short-summary: Lists all the SignalR Service under the current subscription.
examples:
- name: List SignalR Service and show the results in a table.
text: >
az signalr list -o table
- name: List SignalR Service in a resource group and show the results in a table.
text: >
az signalr list -g MySignalR -o table
"""

helps['signalr create'] = """
type: command
short-summary: Creates a SignalR Service.
examples:
- name: Create a SignalR Service with the Basic SKU.
text: >
az signalr create -n MySignalR -g MyResourceGroup --sku Basic_DS2 --unit-count 1
"""

helps['signalr delete'] = """
type: command
short-summary: Deletes a SignalR Service.
examples:
- name: Delete a SignalR Service.
text: >
az signalr delete -n MySignalR -g MyResourceGroup
"""

helps['signalr show'] = """
type: command
short-summary: Get the details of a SignalR Service.
examples:
- name: Get the sku for a SignalR Service.
text: >
az signalr show -n MySignalR -g MyResourceGroup --query sku
"""

helps['signalr key list'] = """
type: command
short-summary: List the access keys for a SignalR Service.
examples:
- name: Get the primary key for a SignalR Service.
text: >
az signalr key list -n MySignalR -g MyResourceGroup --query primaryKey -o tsv
"""

helps['signalr key renew'] = """
type: command
short-summary: Regenerate the access key for a SignalR Service.
examples:
- name: Renew the secondary key for a SignalR Service.
text: >
az signalr key renew -n MySignalR -g MyResourceGroup --key-type secondary
"""
45 changes: 45 additions & 0 deletions src/signalr/azext_signalr/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# pylint: disable=line-too-long
# --------------------------------------------------------------------------------------------
# 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.validators import get_default_location_from_resource_group

from knack.log import get_logger

from azure.cli.core.commands.parameters import (
resource_group_name_type,
get_location_type,
get_resource_name_completion_list,
tags_type
)

from ._constants import (
SIGNALR_SKU,
SIGNALR_RESOURCE_TYPE,
SIGNALR_KEY_TYPE
)


logger = get_logger(__name__)


def load_arguments(self, _):
with self.argument_context('signalr') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('location',
arg_type=get_location_type(self.cli_ctx),
validator=get_default_location_from_resource_group)
c.argument('signalr_name', options_list=['--name', '-n'],
completer=get_resource_name_completion_list(SIGNALR_RESOURCE_TYPE),
help='Name of signalr service.')
c.argument('tags', arg_type=tags_type)

with self.argument_context('signalr create') as c:
c.argument('sku', help='The sku name of the signalr service', choices=SIGNALR_SKU)
c.argument('unit_count', help='The number of signalr service unit count', type=int)

with self.argument_context('signalr key renew') as c:
c.argument('key_type', help='The name of access key to regenerate', choices=SIGNALR_KEY_TYPE)
4 changes: 4 additions & 0 deletions src/signalr/azext_signalr/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.minCliCoreVersion": "2.0.32.dev0",
"azext.isPreview": true
}
33 changes: 33 additions & 0 deletions src/signalr/azext_signalr/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# --------------------------------------------------------------------------------------------
# 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 import CliCommandType

from ._client_factory import cf_signalr
from azure.cli.core.util import empty_on_404


def load_command_table(self, _):

signalr_custom_util = CliCommandType(
operations_tmpl='azext_signalr.custom#{}',
client_factory=cf_signalr
)

signalr_key_utils = CliCommandType(
operations_tmpl='azext_signalr.key#{}',
client_factory=cf_signalr
)

with self.command_group('signalr', signalr_custom_util) as g:
g.command('create', 'signalr_create')
g.command('delete', 'signalr_delete')
g.command('list', 'signalr_list')
g.command('show', 'signalr_show', exception_handler=empty_on_404)

with self.command_group('signalr key', signalr_key_utils) as g:
g.command('list', 'signalr_key_list')
g.command('renew', 'signalr_key_renew')
33 changes: 33 additions & 0 deletions src/signalr/azext_signalr/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


from azext_signalr.signalr.models import (ResourceSku, SignalRCreateOrUpdateProperties, SignalRCreateParameters)


def signalr_create(client, signalr_name, resource_group_name, sku, unit_count=1, location=None, tags=None):
sku = ResourceSku(name=sku, capacity=unit_count)
properties = SignalRCreateOrUpdateProperties(host_name_prefix=signalr_name)

parameter = SignalRCreateParameters(tags=tags,
sku=sku,
properties=properties,
location=location)

return client.create_or_update(resource_group_name, signalr_name, parameter)


def signalr_delete(client, signalr_name, resource_group_name):
return client.delete(resource_group_name, signalr_name)


def signalr_list(client, resource_group_name=None):
if not resource_group_name:
return client.list_by_subscription()
return client.list_by_resource_group(resource_group_name)


def signalr_show(client, signalr_name, resource_group_name):
return client.get(resource_group_name, signalr_name)
19 changes: 19 additions & 0 deletions src/signalr/azext_signalr/key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


from azext_signalr.signalr.models import KeyType


def signalr_key_list(client, resource_group_name, signalr_name):
return client.list_keys(resource_group_name, signalr_name)


def signalr_key_renew(client, resource_group_name, signalr_name, key_type):
if key_type == 'primary':
key_type = KeyType.primary
else:
key_type = KeyType.secondary
return client.regenerate_key(resource_group_name, signalr_name, key_type, polling=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

sdk_no_wait(True, client.regenerate_key, resource_group_name, signalr_name, key_type)

https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/util.py#L251

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use sdk_no_wait, the output will be raw. Thus, when I run key renew, it will raise error with TypeError: <urllib3.response.HTTPResponse object at 0x0539B310> is not JSON serializable

18 changes: 18 additions & 0 deletions src/signalr/azext_signalr/signalr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .signal_rmanagement_client import SignalRManagementClient
from .version import VERSION

__all__ = ['SignalRManagementClient']

__version__ = VERSION

Loading