Skip to content

Commit

Permalink
[EventGrid] Add commands for partner and event-subscription customer …
Browse files Browse the repository at this point in the history
…facing features (#23162)

* Bump Event Grid package version to latest preview

* Add nested event subscriptions for Event Grid topics

* Add nested event subscriptions for Event Grid domains and domain topics

* Add verified partner commands

* Add all new factories and command groups

* Implement all commands

* Add more documentation

* Change parameter names

* Fix pylint and flake8 issues

* Findings from design review

* Resolve linter issues

* test update

* Fix linter errors for update parameters

* Implement and record tests

* Multiple fixes and record tests. fixes include, add missing parameters to channel create, fix resource name parameter for partner channel commands, add tests for partner destination and fix tests for secured webhook scenarios, add try/finally to ensure proper cleanup, remove preview tags for ga'ed featured, add deprecation info for publisher_info and optional partner registration, and others

* remve secrets

* cleanup: fix style and linter error

* cleanup

* fix param lengths

* fix help

* rerecord network test1

* rerecord network test2

* rerecord network test3

* fix help

Co-authored-by: Brandon Neff <brandonneff@microsoft.com>
Co-authored-by: Ashraf Hamad <ahamad@ntdev.microsoft.com>
  • Loading branch information
3 people committed Jul 20, 2022
1 parent a931eff commit 2463aa8
Show file tree
Hide file tree
Showing 32 changed files with 19,874 additions and 4,108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ def topics_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).topics


def topic_event_subscriptions_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).topic_event_subscriptions


def domain_topic_event_subscriptions_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).domain_topic_event_subscriptions


def domain_event_subscriptions_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).domain_event_subscriptions


def domains_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).domains

Expand Down Expand Up @@ -46,6 +58,10 @@ def event_channels_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).event_channels


def channels_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).channels


def partner_topics_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).partner_topics

Expand All @@ -54,6 +70,18 @@ def partner_topic_event_subscriptions_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).partner_topic_event_subscriptions


def partner_configurations_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).partner_configurations


def partner_destinations_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).partner_destinations


def verified_partners_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).verified_partners


def event_subscriptions_factory(cli_ctx, _):
return cf_eventgrid(cli_ctx).event_subscriptions

Expand Down
1,136 changes: 1,028 additions & 108 deletions src/azure-cli/azure/cli/command_modules/eventgrid/_help.py

Large diffs are not rendered by default.

264 changes: 238 additions & 26 deletions src/azure-cli/azure/cli/command_modules/eventgrid/_params.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import argparse
from knack.util import CLIError
from dateutil.parser import parse # pylint: disable=import-error,relative-import
from azure.mgmt.eventgrid.models import (
Partner
)

PARTNER_NAME = "partner-name"
PARTNER_ID = "partner-registration-immutable-id"
EXPIRATION_TIME = "expiration-time"


# pylint: disable=protected-access
# pylint: disable=too-few-public-methods
class AddAuthorizedPartner(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
valuesLen = len(values)
usage_error_msg = ("usage error: --authorized-partner [partner-name=<name>] "
"[partner-registration-immutable-id=<id>] [expiration-time=<timestamp>]")
if valuesLen < 1 or valuesLen > 3:
raise CLIError(usage_error_msg)

partner_name = None
partner_id = None
expiration_time = None
for item in values:
try:
key, value = item.split('=', 1)
if key.lower() == PARTNER_NAME:
partner_name = value
elif key.lower() == PARTNER_ID:
partner_id = value
elif key.lower() == EXPIRATION_TIME:
expiration_time = value
else:
raise ValueError()
except ValueError:
raise CLIError(usage_error_msg)

if expiration_time is not None:
expiration_time = parse(expiration_time)

partner_info = Partner(
partner_registration_immutable_id=partner_id,
partner_name=partner_name,
authorization_expiration_time_in_utc=expiration_time)

if namespace.authorized_partner is None:
namespace.authorized_partner = []
namespace.authorized_partner.append(partner_info)
112 changes: 105 additions & 7 deletions src/azure-cli/azure/cli/command_modules/eventgrid/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from azure.cli.core.commands import CliCommandType
from ._client_factory import (
topics_factory,
topic_event_subscriptions_factory,
domain_event_subscriptions_factory,
domain_topic_event_subscriptions_factory,
domains_factory,
domain_topics_factory,
system_topics_factory,
Expand All @@ -19,8 +22,12 @@
partner_registrations_factory,
partner_namespaces_factory,
event_channels_factory,
channels_factory,
partner_topics_factory,
partner_topic_event_subscriptions_factory
partner_topic_event_subscriptions_factory,
partner_configurations_factory,
partner_destinations_factory,
verified_partners_factory
)


Expand All @@ -31,12 +38,24 @@ def load_command_table(self, _):
client_arg_name='self'
)

topic_event_subscriptions_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#TopicEventSubscriptionsOperations.{}',
client_factory=topic_event_subscriptions_factory,
client_arg_name='self'
)

extension_topics_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#ExtensionTopicsOperations.{}',
client_factory=extension_topics_factory,
client_arg_name='self'
)

domain_event_subscriptions_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#DomainEventSubscriptionsOperations.{}',
client_factory=domain_event_subscriptions_factory,
client_arg_name='self'
)

domains_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#DomainsOperations.{}',
client_factory=domains_factory,
Expand All @@ -49,6 +68,12 @@ def load_command_table(self, _):
client_arg_name='self'
)

domain_topic_event_subscriptions_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#DomainTopicEventSubscriptionsOperations.{}',
client_factory=domain_topic_event_subscriptions_factory,
client_arg_name='self'
)

system_topics_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#SystemTopicsOperations.{}',
client_factory=system_topics_factory,
Expand Down Expand Up @@ -79,6 +104,12 @@ def load_command_table(self, _):
client_arg_name='self'
)

channels_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#ChannelsOperations.{}',
client_factory=channels_factory,
client_arg_name='self'
)

partner_topics_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerTopicsOperations.{}',
client_factory=partner_topics_factory,
Expand All @@ -91,6 +122,24 @@ def load_command_table(self, _):
client_arg_name='self'
)

partner_configurations_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerConfigurationsOperations.{}',
client_factory=partner_configurations_factory,
client_arg_name='self'
)

partner_destinations_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerDestinationsOperations.{}',
client_factory=partner_destinations_factory,
client_arg_name='self'
)

verified_partners_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#VerifiedPartnersOperations.{}',
client_factory=verified_partners_factory,
client_arg_name='self'
)

topic_type_mgmt_util = CliCommandType(
operations_tmpl='azure.mgmt.eventgrid.operations#TopicTypesOperations.{}',
client_factory=topic_types_factory,
Expand All @@ -106,6 +155,13 @@ def load_command_table(self, _):
g.custom_command('create', 'cli_topic_create_or_update')
g.custom_command('update', 'cli_topic_update')

with self.command_group('eventgrid topic event-subscription', topic_event_subscriptions_mgmt_util, client_factory=topic_event_subscriptions_factory) as g:
g.custom_show_command('show', 'cli_topic_event_subscription_get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_topic_event_subscription_list')
g.custom_command('create', 'cli_topic_event_subscription_create_or_update')
g.custom_command('update', 'cli_topic_event_subscription_update')

with self.command_group('eventgrid extension-topic', extension_topics_mgmt_util, client_factory=extension_topics_factory) as g:
g.show_command('show', 'get')

Expand All @@ -115,6 +171,13 @@ def load_command_table(self, _):
g.custom_command('delete', 'cli_domain_topic_delete')
g.custom_command('create', 'cli_domain_topic_create_or_update')

with self.command_group('eventgrid domain topic event-subscription', domain_topic_event_subscriptions_mgmt_util, client_factory=domain_topic_event_subscriptions_factory) as g:
g.custom_show_command('show', 'cli_domain_topic_event_subscription_get')
g.custom_command('delete', 'cli_domain_topic_event_subscription_delete', confirmation=True)
g.custom_command('list', 'cli_domain_topic_event_subscription_list')
g.custom_command('create', 'cli_domain_topic_event_subscription_create_or_update')
g.custom_command('update', 'cli_domain_topic_event_subscription_update')

with self.command_group('eventgrid domain', domains_mgmt_util, client_factory=domains_factory) as g:
g.show_command('show', 'get')
g.command('key list', 'list_shared_access_keys')
Expand All @@ -124,6 +187,13 @@ def load_command_table(self, _):
g.command('delete', 'begin_delete')
g.custom_command('update', 'cli_domain_update')

with self.command_group('eventgrid domain event-subscription', domain_event_subscriptions_mgmt_util, client_factory=domain_event_subscriptions_factory) as g:
g.custom_show_command('show', 'cli_domain_event_subscription_get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_domain_event_subscription_list')
g.custom_command('create', 'cli_domain_event_subscription_create_or_update')
g.custom_command('update', 'cli_domain_event_subscription_update')

with self.command_group('eventgrid system-topic', system_topics_mgmt_util, client_factory=system_topics_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
Expand All @@ -138,14 +208,14 @@ def load_command_table(self, _):
g.custom_command('create', 'cli_system_topic_event_subscription_create_or_update')
g.custom_command('update', 'cli_system_topic_event_subscription_update')

with self.command_group('eventgrid partner registration', partner_registrations_mgmt_util, client_factory=partner_registrations_factory, is_preview=True) as g:
with self.command_group('eventgrid partner registration', partner_registrations_mgmt_util, client_factory=partner_registrations_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'delete', confirmation=True)
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_partner_registration_list')
g.custom_command('create', 'cli_partner_registration_create_or_update')
# g.custom_command('update', 'cli_partner_registration_update')

with self.command_group('eventgrid partner namespace', partner_namespaces_mgmt_util, client_factory=partner_namespaces_factory, is_preview=True) as g:
with self.command_group('eventgrid partner namespace', partner_namespaces_mgmt_util, client_factory=partner_namespaces_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_partner_namespace_list')
Expand All @@ -154,14 +224,21 @@ def load_command_table(self, _):
g.custom_command('key regenerate', 'cli_partner_namespace_regenerate_key')
# g.custom_command('update', 'cli_partner_namespace_update')

with self.command_group('eventgrid partner namespace event-channel', event_channels_mgmt_util, client_factory=event_channels_factory, is_preview=True) as g:
with self.command_group('eventgrid partner namespace event-channel', event_channels_mgmt_util, client_factory=event_channels_factory, deprecate_info=self.deprecate(hide=False)) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_event_channel_list')
# g.custom_command('update', 'cli_event_channel_update')
g.custom_command('create', 'cli_event_channel_create_or_update')

with self.command_group('eventgrid partner topic', partner_topics_mgmt_util, client_factory=partner_topics_factory, is_preview=True) as g:
with self.command_group('eventgrid partner namespace channel', channels_mgmt_util, client_factory=channels_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_channel_list')
g.custom_command('update', 'cli_channel_update')
g.custom_command('create', 'cli_channel_create_or_update')

with self.command_group('eventgrid partner topic', partner_topics_mgmt_util, client_factory=partner_topics_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.command('activate', 'activate')
Expand All @@ -170,13 +247,34 @@ def load_command_table(self, _):
# g.custom_command('create', 'cli_partner_topic_create_or_update')
# g.custom_command('update', 'cli_partner_topic_update')

with self.command_group('eventgrid partner topic event-subscription', partner_topic_event_subscriptions_mgmt_util, client_factory=partner_topic_event_subscriptions_factory, is_preview=True) as g:
with self.command_group('eventgrid partner topic event-subscription', partner_topic_event_subscriptions_mgmt_util, client_factory=partner_topic_event_subscriptions_factory) as g:
g.custom_show_command('show', 'cli_partner_topic_event_subscription_get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('list', 'cli_partner_topic_event_subscription_list')
g.custom_command('create', 'cli_partner_topic_event_subscription_create_or_update')
g.custom_command('update', 'cli_partner_topic_event_subscription_update')

with self.command_group('eventgrid partner configuration', partner_configurations_mgmt_util, client_factory=partner_configurations_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('authorize', 'cli_partner_configuration_authorize')
g.custom_command('unauthorize', 'cli_partner_configuration_unauthorize')
g.custom_command('list', 'cli_partner_configuration_list')
g.custom_command('create', 'cli_partner_configuration_create_or_update')
g.custom_command('update', 'cli_partner_configuration_update')

with self.command_group('eventgrid partner destination', partner_destinations_mgmt_util, client_factory=partner_destinations_factory) as g:
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.command('activate', 'activate')
g.custom_command('list', 'cli_partner_destination_list')
g.custom_command('create', 'cli_partner_destination_create_or_update')
g.custom_command('update', 'cli_partner_destination_update')

with self.command_group('eventgrid partner verified-partner', verified_partners_mgmt_util, client_factory=verified_partners_factory) as g:
g.show_command('show', 'get')
g.custom_command('list', 'cli_verified_partner_list')

custom_tmpl = 'azure.cli.command_modules.eventgrid.custom#{}'
eventgrid_custom = CliCommandType(operations_tmpl=custom_tmpl)

Expand Down
Loading

0 comments on commit 2463aa8

Please sign in to comment.