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 Event Grid 0.4.1 #633

Merged
merged 24 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 12 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: 1 addition & 1 deletion src/eventgrid/azext_eventgrid/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def cf_eventgrid(cli_ctx, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_eventgrid.mgmt.eventgrid import EventGridManagementClient
from azext_eventgrid.vendored_sdks.mgmt.eventgrid import EventGridManagementClient
return get_mgmt_service_client(cli_ctx, EventGridManagementClient)


Expand Down
28 changes: 25 additions & 3 deletions src/eventgrid/azext_eventgrid/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

helps['eventgrid'] = """
type: group
short-summary: Manage Azure Event Grid topics, event subscriptions and domains.
short-summary: Manage Azure Event Grid topics, event subscriptions, domains and domain topics.
"""
helps['eventgrid topic'] = """
type: group
Expand Down Expand Up @@ -123,7 +123,21 @@
"""
helps['eventgrid domain topic'] = """
type: group
short-summary: View information about topics in a domain.
short-summary: Manage event domain topics.
"""
helps['eventgrid domain topic create'] = """
type: command
short-summary: Create a domain topic under a domain.
examples:
- name: Create a new domain topic under domain.
text: az eventgrid domain topic create -g rg1 --domain-name domain1 --name domaintopic1
"""
helps['eventgrid domain topic delete'] = """
type: command
short-summary: Delete a domain topic under a domain.
examples:
- name: Delete a domain topic.
text: az eventgrid domain topic delete -g rg1 --domain-name domain1 --name domaintopic1
"""
helps['eventgrid domain key list'] = """
type: command
Expand Down Expand Up @@ -188,7 +202,8 @@
long-summary: |
Example: --deadletter-endpoint /subscriptions/{SubID}/resourceGroups/rg1/providers/Microsoft.Storage/storageAccounts/sa1/blobServices/default/containers/containerName
- name: --endpoint-type
short-summary: The type of the destination endpoint.
short-summary: The type of the destination endpoint. It is expected that the destination endpoint be created and available for use before executing any Event Grid command.

examples:
- name: Create a new event subscription for an Event Grid topic, using default filters.
text: |
Expand Down Expand Up @@ -241,6 +256,13 @@
--source-resource-id /subscriptions/{SubID} \\
--endpoint-type storagequeue \\
--endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/sa1/queueservices/default/queues/q1
- name: Create a new event subscription for an Azure subscription, using default filters, and an Azure ServiceBusQueue as a destination.
text: |
az eventgrid event-subscription create --name es2 \\
--source-resource-id /subscriptions/{SubID} \\
--endpoint-type servicebusqueue \\
--endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1

- name: Create a new event subscription for an Event Grid domain, using default filters, and CloudEventV01 as the delivery schema.
text: |
az eventgrid event-subscription create --name es2 \\
Expand Down
63 changes: 52 additions & 11 deletions src/eventgrid/azext_eventgrid/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .advanced_filter import EventSubscriptionAddFilter

included_event_types_type = CLIArgumentType(
help="A space-separated list of event types. Example: Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted. To subscribe to all event types, the string \"All\" should be specified.",
help="A space-separated list of event types. Example: Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted. To subscribe to all default event types, do not specify any value for this argument.",
nargs='+'
)

Expand All @@ -44,15 +44,20 @@
arg_type=tags_type
)

odata_query_type = CLIArgumentType(
help="The query used to filter the results using OData syntax.",
options_list=['--odata-query']
)


def load_arguments(self, _):
def load_arguments(self, _): # pylint: disable=too-many-statements
with self.argument_context('eventgrid') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('tags', arg_type=tags_type)
c.argument('included_event_types', arg_type=included_event_types_type)
c.argument('labels', arg_type=labels_type)
c.argument('endpoint_type', arg_type=get_enum_type(['webhook', 'eventhub', 'storagequeue', 'hybridconnection'], default='webhook'))
c.argument('endpoint_type', arg_type=get_enum_type(['webhook', 'eventhub', 'storagequeue', 'hybridconnection', 'servicebusqueue'], default='webhook'))
c.argument('source_resource_id', help="Fully qualified identifier of the source Azure resource.")
c.argument('resource_id', deprecate_info=c.deprecate(redirect="--source-resource-id", expiration='2.1.0', hide=True), help="Fully qualified identifier of the Azure resource.")
c.argument('endpoint', help="Endpoint where EventGrid should deliver events matching this event subscription. For webhook endpoint type, this should be the corresponding webhook URL. For other endpoint types, this should be the Azure resource identifier of the endpoint.")
Expand All @@ -64,25 +69,58 @@ def load_arguments(self, _):
c.argument('input_mapping_fields', arg_type=input_mapping_fields_type)
c.argument('input_mapping_default_values', arg_type=input_mapping_default_values_type)
c.argument('input_schema', arg_type=input_schema_type)
c.argument('odata_query', arg_type=odata_query_type)

with self.argument_context('eventgrid topic') as c:
c.argument('topic_name', arg_type=name_type, help='Name of the topic', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))
c.argument('topic_name', arg_type=name_type, help='Name of the topic.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))

with self.argument_context('eventgrid topic list') as c:
c.argument('topic_name', arg_type=name_type, help='Name of the topic.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))
c.argument('odata_query', arg_type=odata_query_type, id_part=None)

with self.argument_context('eventgrid topic key list') as c:
c.argument('topic_name', arg_type=name_type, help='Name of the topic', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))
c.argument('topic_name', arg_type=name_type, help='Name of the topic.', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))

with self.argument_context('eventgrid domain create') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain delete') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain update') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
Copy link
Member

Choose a reason for hiding this comment

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

Instead of repeating this code three times, just use a scope of eventgrid domain, which will apply it to all commands and subgroups under the domain subgroup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per our discussion, we needed to do this for domain to allow us to use different arguments and related names in domain topic scope. In specific, using --name for domain-topic-name (rather than domain-name which is used at domain scope) and domain-name for specifying the domain name (which is --name is domain scope).

Copy link
Member

@tjprescott tjprescott Apr 10, 2019

Choose a reason for hiding this comment

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

So a couple techniques to reduce the duplication:

domain_name_type = CLIArgumentType(help='Name of the domain.', options_list='--domain-name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain') as c:
  c.argument('domain_name', domain_name_type, options_list=['--name', '-n'], id_part=name)

with self.argument_context('eventgrid domain topic') as c:
  c.argument('domain_name', domain_name_type, id_part=None)

And if you really needed to override per command (which is usually not the case):

for scope in ['create', 'update', 'delete']:
   with self.argument_context('eventgrid domain {}'.format(scope)) as c:
      c.argument('domain_name', …)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx for the suggestion. Makes sense. Fixed.


with self.argument_context('eventgrid domain') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
with self.argument_context('eventgrid domain show') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain list') as c:
c.argument('odata_query_type', arg_type=odata_query_type, id_part=None)

with self.argument_context('eventgrid domain key regenerate') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain key list') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))

with self.argument_context('eventgrid domain topic create') as c:
c.argument('domain_name', help='Name of the domain.', id_part='domains', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('domain_topic_name', arg_type=name_type, help='Name of the domain topic.', id_part='topics', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains/topics'))

with self.argument_context('eventgrid domain topic delete') as c:
c.argument('domain_name', help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('domain_topic_name', arg_type=name_type, help='Name of the domain topic.', id_part='child_name_1', options_list=['--name', '-n'], completer=get_resource_name_completion_list('Microsoft.EventGrid/domains/topics'))

with self.argument_context('eventgrid domain topic show') as c:
c.argument('domain_name', help='Name of the domain.', id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('domain_topic_name', arg_type=name_type, help='Name of the domain topic.', id_part='child_name_1', options_list=['--name', '-n'], completer=get_resource_name_completion_list('Microsoft.EventGrid/domains/topics'))

with self.argument_context('eventgrid domain topic list') as c:
c.argument('domain_name', arg_type=name_type, help='Name of the domain', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('domain_name', arg_type=name_type, help='Name of the domain.', id_part=None, completer=get_resource_name_completion_list('Microsoft.EventGrid/domains'))
c.argument('odata_query_type', arg_type=odata_query_type, id_part=None)

with self.argument_context('eventgrid event-subscription') as c:
c.argument('topic_name', deprecate_info=c.deprecate(expiration='2.1.0', hide=True), help='Name of Event Grid topic', options_list=['--topic-name'], completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))
c.argument('event_subscription_name', arg_type=name_type, help='Name of the event subscription')
c.argument('topic_name', deprecate_info=c.deprecate(expiration='2.1.0', hide=True), help='Name of Event Grid topic.', options_list=['--topic-name'], completer=get_resource_name_completion_list('Microsoft.EventGrid/topics'))
c.argument('event_subscription_name', arg_type=name_type, help='Name of the event subscription.')
c.argument('event_delivery_schema', arg_type=get_enum_type(['eventgridschema', 'custominputschema', 'cloudeventv01schema']), help='The schema in which events should be delivered for this event subscription. By default, events will be delivered in the same schema in which they are published (based on the corresponding topic\'s input schema).')
c.argument('max_delivery_attempts', help="Maximum number of delivery attempts. Must be a number between 1 and 30.")
c.argument('event_ttl', help="Event time to live (in minutes). Must be a number between 1 and 1440.")
Expand All @@ -99,6 +137,9 @@ def load_arguments(self, _):
with self.argument_context('eventgrid event-subscription update') as c:
c.argument('resource_group_name', deprecate_info=c.deprecate(expiration='2.1.0', hide=True), arg_type=resource_group_name_type)

with self.argument_context('eventgrid event-subscription list') as c:
c.argument('odata_query_type', arg_type=odata_query_type, id_part=None)

with self.argument_context('eventgrid event-subscription show') as c:
c.argument('resource_group_name', deprecate_info=c.deprecate(expiration='2.1.0', hide=True), arg_type=resource_group_name_type)
c.argument('include_full_endpoint_url', arg_type=get_three_state_flag(), options_list=['--include-full-endpoint-url'], help="Specify to indicate whether the full endpoint URL should be returned. True if flag present.", )
Expand Down
2 changes: 1 addition & 1 deletion src/eventgrid/azext_eventgrid/advanced_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import argparse
from knack.util import CLIError

from azext_eventgrid.mgmt.eventgrid.models import (
from azext_eventgrid.vendored_sdks.mgmt.eventgrid.models import (
NumberGreaterThanAdvancedFilter,
NumberGreaterThanOrEqualsAdvancedFilter,
NumberInAdvancedFilter,
Expand Down
14 changes: 8 additions & 6 deletions src/eventgrid/azext_eventgrid/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@

def load_command_table(self, _):
topics_mgmt_util = CliCommandType(
operations_tmpl='azext_eventgrid.mgmt.eventgrid.operations.topics_operations#TopicsOperations.{}',
operations_tmpl='azext_eventgrid.vendored_sdks.mgmt.eventgrid.operations.topics_operations#TopicsOperations.{}',
client_factory=topics_factory,
client_arg_name='self'
)

domains_mgmt_util = CliCommandType(
operations_tmpl='azext_eventgrid.mgmt.eventgrid.operations.domains_operations#DomainsOperations.{}',
operations_tmpl='azext_eventgrid.vendored_sdks.mgmt.eventgrid.operations.domains_operations#DomainsOperations.{}',
client_factory=domains_factory,
client_arg_name='self'
)

domain_topics_mgmt_util = CliCommandType(
operations_tmpl='azext_eventgrid.mgmt.eventgrid.operations.domain_topics_operations#DomainTopicsOperations.{}',
operations_tmpl='azext_eventgrid.vendored_sdks.mgmt.eventgrid.operations.domain_topics_operations#DomainTopicsOperations.{}',
client_factory=domain_topics_factory,
client_arg_name='self'
)

topic_type_mgmt_util = CliCommandType(
operations_tmpl='azext_eventgrid.mgmt.eventgrid.operations.topic_types_operations#TopicTypesOperations.{}',
operations_tmpl='azext_eventgrid.vendored_sdks.mgmt.eventgrid.operations.topic_types_operations#TopicTypesOperations.{}',
client_factory=topic_types_factory,
client_arg_name='self'
)
Expand All @@ -48,15 +48,17 @@ def load_command_table(self, _):

with self.command_group('eventgrid domain topic', domain_topics_mgmt_util, client_factory=domain_topics_factory) as g:
g.command('show', 'get')
g.command('list', 'list_by_domain')
g.custom_command('list', 'cli_domain_topic_list')
g.custom_command('delete', 'cli_domain_topic_delete')
g.custom_command('create', 'cli_domain_topic_create_or_update')

with self.command_group('eventgrid domain', domains_mgmt_util, client_factory=domains_factory) as g:
g.command('show', 'get')
g.command('key list', 'list_shared_access_keys')
g.command('key regenerate', 'regenerate_key')
g.command('delete', 'delete')
g.custom_command('list', 'cli_domain_list')
g.custom_command('create', 'cli_domain_create_or_update')
g.command('delete', 'delete')
g.generic_update_command('update',
getter_name='get',
setter_name='update',
Expand Down
Loading