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

ServiceBus - cli extension #39

Merged
merged 3 commits into from
Jan 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
45 changes: 32 additions & 13 deletions src/servicebus/azext_servicebus/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,53 @@
helps['servicebus'] = """
type: group
short-summary: Manage Azure Service Bus namespace, queue, topic, subscription, rule and geo disaster recovery configuration - alias

"""
"""

helps['servicebus namespace'] = """
type: group
short-summary: Manage Azure Service Bus Namespace

"""
"""

helps['servicebus namespace authorizationrule'] = """
type: group
short-summary: Manage Azure Service Bus Namespace AuthorizationRule
"""

"""
helps['servicebus namespace authorizationrule keys'] = """
type: group
short-summary: Manage Azure AuthorizationRule connection strings for Namespace
"""

helps['servicebus queue'] = """
type: group
short-summary: Manage Azure Service Bus Queue and authorizationrule

"""
"""

helps['servicebus queue authorizationrule'] = """
type: group
short-summary: Manage Azure Service Bus Queue AuthorizationRule
"""

"""
helps['servicebus queue authorizationrule keys'] = """
type: group
short-summary: Manage Azure AuthorizationRule connection strings for Service Bus Queue
"""

helps['servicebus topic'] = """
type: group
short-summary: Manage Azure Service Bus Topic and authorizationrule

"""
"""

helps['servicebus topic authorizationrule'] = """
type: group
short-summary: Manage Azure Service Bus Topic AuthorizationRule
"""

helps['servicebus topic authorizationrule keys'] = """
type: group
short-summary: Manage Azure AuthorizationRule connection strings for Service Bus Topic
"""

helps['servicebus subscription'] = """
type: group
short-summary: Manage Azure Service Bus Subscription
Expand All @@ -61,6 +70,16 @@
short-summary: Manage Azure Service Bus Geo Disaster Recovery Configuration - Alias
"""

helps['servicebus georecovery-alias authorizationrule'] = """
type: group
short-summary: Manage Azure Service Bus AuthorizationRule for Namespace with GeoDRAlias
"""

helps['servicebus georecovery-alias authorizationrule keys'] = """
type: group
short-summary: Manage Azure AuthorizationRule connection strings for Service Bus Namespace
"""

helps['servicebus namespace exists'] = """
type: command
short-summary: check for the availability of the given name for the Namespace
Expand Down Expand Up @@ -416,7 +435,7 @@
examples:
- name: Creates Geo Disaster Recovery configuration - Alias for the give Namespace
text: az servicebus georecovery-alias create --resource-group myresourcegroup --namespace-name primarynamespace
--alias myaliasname --partner-namespace
--alias myaliasname --partner-namespace armresourceid
"""

helps['servicebus georecovery-alias show'] = """
Expand Down Expand Up @@ -459,9 +478,9 @@

helps['servicebus georecovery-alias fail-over'] = """
type: command
short-summary: Envokes Service Bus Geo Recovery Alias failover and re-configure the alias to point to the secondary namespace
short-summary: Invokes Service Bus Geo Recovery Alias failover and re-configure the alias to point to the secondary namespace
examples:
- name: Envokes Geo Disaster Recovery failover and reconfigure the alias to point to the secondary namespace
- name: Invokes Geo Disaster Recovery failover and reconfigure the alias to point to the secondary namespace
text: az servicebus georecovery-alias fail-over --resource-group myresourcegroup --namespace-name secondarynamespace
--alias myaliasname
"""
Expand Down
12 changes: 6 additions & 6 deletions src/servicebus/azext_servicebus/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def load_arguments_namespace(self, _):
c.argument('authorization_rule_name', options_list=['--name', '-n'], help='name of the Namespace AuthorizationRule')

with self.argument_context('servicebus namespace authorizationrule create') as c:
c.argument('accessrights', options_list=['--access-rights'],
c.argument('accessrights', options_list=['--access-rights'], arg_type=get_enum_type(['Send', 'Listen', 'Manage']),
help='Authorization rule rights of type list, allowed values are Send, Listen or Manage')

with self.argument_context('servicebus namespace authorizationrule keys renew') as c:
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']))
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']), help='specifies Primary or Secondary key needs to be reset')


def load_arguments_queue(self, _):
Expand Down Expand Up @@ -70,10 +70,10 @@ def load_arguments_queue(self, _):
c.argument('queue_name', options_list=['--queue-name'], help='name of the Queue')

with self.argument_context('servicebus queue authorizationrule create') as c:
c.argument('accessrights', options_list=['--access-rights'], help='Authorization rule rights of type list, allowed values are Send, Listen or Manage')
c.argument('accessrights', options_list=['--access-rights'], arg_type=get_enum_type(['Send', 'Listen', 'Manage']), help='Authorization rule rights of type list.')

with self.argument_context('servicebus queue authorizationrule keys renew') as c:
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']))
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']), help='specifies Primary or Secondary key needs to be reset')


# - Topic Region
Expand Down Expand Up @@ -101,10 +101,10 @@ def load_arguments_topic(self, _):
c.argument('topic_name', options_list=['--topic-name'], help='name of the Topic')

with self.argument_context('servicebus topic authorizationrule create') as c:
c.argument('accessrights', options_list=['--access-rights'], help='Authorization rule rights of type list, allowed values are Send, Listen or Manage')
c.argument('accessrights', options_list=['--access-rights'], arg_type=get_enum_type(['Send', 'Listen', 'Manage']), help='Authorization rule rights of type list.')

with self.argument_context('servicebus topic authorizationrule keys renew') as c:
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']))
c.argument('key_type', options_list=['--key-name'], arg_type=get_enum_type(['PrimaryKey', 'SecondaryKey']), help='specifies Primary or Secondary key needs to be reset')


# Subscription Region
Expand Down
37 changes: 19 additions & 18 deletions src/servicebus/azext_servicebus/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
subscriptions_mgmt_client_factory,
rules_mgmt_client_factory,
disaster_recovery_mgmt_client_factory,)
from .custom import empty_on_404


def load_command_table(self, _):
Expand Down Expand Up @@ -56,68 +57,68 @@ def load_command_table(self, _):
# Namespace Region
with self.command_group('servicebus namespace', sb_namespace_util, client_factory=namespaces_mgmt_client_factory) as g:
g.custom_command('create', 'cli_namespace_create')
g.command('show', 'get')
g.custom_command('list', 'cli_namespace_list')
g.command('show', 'get', exception_handler=empty_on_404)
g.custom_command('list', 'cli_namespace_list', exception_handler=empty_on_404)
g.command('delete', 'delete')
g.command('exists', 'check_name_availability_method')

with self.command_group('servicebus namespace authorizationrule', sb_namespace_util, client_factory=namespaces_mgmt_client_factory) as g:
g.custom_command('create', 'cli_namespaceautho_create',)
g.command('show', 'get_authorization_rule')
g.command('list', 'list_authorization_rules')
g.command('show', 'get_authorization_rule', exception_handler=empty_on_404)
g.command('list', 'list_authorization_rules', exception_handler=empty_on_404)
g.command('keys list', 'list_keys')
g.command('keys renew', 'regenerate_keys')
g.command('delete', 'delete_authorization_rule')

# Queue Region
with self.command_group('servicebus queue', sb_queue_util, client_factory=queues_mgmt_client_factory) as g:
g.custom_command('create', 'cli_sbqueue_create')
g.command('show', 'get')
g.command('list', 'list_by_namespace')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list_by_namespace', exception_handler=empty_on_404)
g.command('delete', 'delete')

with self.command_group('servicebus queue authorizationrule', sb_queue_util, client_factory=queues_mgmt_client_factory) as g:
g.custom_command('create', 'cli_sbqueueautho_create',)
g.command('show', 'get_authorization_rule')
g.command('list', 'list_authorization_rules')
g.command('show', 'get_authorization_rule', exception_handler=empty_on_404)
g.command('list', 'list_authorization_rules', exception_handler=empty_on_404)
g.command('keys list', 'list_keys')
g.command('keys renew', 'regenerate_keys')
g.command('delete', 'delete_authorization_rule')

# Topic Region
with self.command_group('servicebus topic', sb_topic_util, client_factory=topics_mgmt_client_factory) as g:
g.custom_command('create', 'cli_sbtopic_create')
g.command('show', 'get')
g.command('list', 'list_by_namespace')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list_by_namespace', exception_handler=empty_on_404)
g.command('delete', 'delete')

with self.command_group('servicebus topic authorizationrule', sb_topic_util, client_factory=topics_mgmt_client_factory) as g:
g.custom_command('create', 'cli_sbtopicautho_create')
g.command('show', 'get_authorization_rule')
g.command('list', 'list_authorization_rules')
g.command('show', 'get_authorization_rule', exception_handler=empty_on_404)
g.command('list', 'list_authorization_rules', exception_handler=empty_on_404)
g.command('keys list', 'list_keys')
g.command('keys renew', 'regenerate_keys')
g.command('delete', 'delete_authorization_rule')

# Subscription Region
with self.command_group('servicebus subscription', sb_subscriptions_util, client_factory=subscriptions_mgmt_client_factory) as g:
g.custom_command('create', 'cli_sbsubscription_create')
g.command('show', 'get')
g.command('list', 'list_by_topic')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list_by_topic', exception_handler=empty_on_404)
g.command('delete', 'delete')

# Rules Region
with self.command_group('servicebus rule', sb_rule_util, client_factory=rules_mgmt_client_factory) as g:
g.custom_command('create', 'cli_rules_create')
g.command('show', 'get')
g.command('list', 'list_by_subscriptions')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list_by_subscriptions', exception_handler=empty_on_404)
g.command('delete', 'delete')

# DisasterRecoveryConfigs Region
with self.command_group('servicebus georecovery-alias', sb_geodr_util, client_factory=disaster_recovery_mgmt_client_factory) as g:
g.command('create', 'create_or_update')
g.command('show', 'get')
g.command('list', 'list')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list', exception_handler=empty_on_404)
g.command('break-pair', 'break_pairing')
g.command('fail-over', 'fail_over')
g.command('exists', 'check_name_availability_method')
Expand Down
25 changes: 13 additions & 12 deletions src/servicebus/azext_servicebus/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from knack.util import CLIError

from azext_servicebus._utils import accessrights_converter

Expand All @@ -22,19 +21,13 @@ def cli_namespace_create(client, resource_group_name, namespace_name, location,
capacity)))


def cli_namespace_list(client, resource_group_name=None, namespace_name=None):
def cli_namespace_list(client, resource_group_name=None):
cmd_result = None
if resource_group_name and namespace_name:
cmd_result = client.get(resource_group_name, namespace_name)
if resource_group_name:
cmd_result = client.list_by_resource_group(resource_group_name)

if resource_group_name and not namespace_name:
cmd_result = client.list_by_resource_group(resource_group_name, namespace_name)

if not resource_group_name and not namespace_name:
cmd_result = client.list(resource_group_name, namespace_name)

if not cmd_result:
raise CLIError('--resource-group name required when namespace name is provided')
if not resource_group_name:
cmd_result = client.list()

return cmd_result

Expand Down Expand Up @@ -164,3 +157,11 @@ def cli_alias_create(client, resource_group_name, namespace_name, alias, partner
alternate_name=alternate_name
)
return client.create_or_update(resource_group_name, namespace_name, alias, dr_params)


# pylint: disable=inconsistent-return-statements
def empty_on_404(ex):
from azext_servicebus.servicebus.models import ErrorResponseException
if isinstance(ex, ErrorResponseException) and ex.response.status_code == 404:
return None
raise ex
Loading