Skip to content

Commit 2463aa8

Browse files
Brandon411Brandon NeffAshraf Hamad
authored
[EventGrid] Add commands for partner and event-subscription customer 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>
1 parent a931eff commit 2463aa8

32 files changed

+19874
-4108
lines changed

src/azure-cli/azure/cli/command_modules/eventgrid/_client_factory.py

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def topics_factory(cli_ctx, _):
1414
return cf_eventgrid(cli_ctx).topics
1515

1616

17+
def topic_event_subscriptions_factory(cli_ctx, _):
18+
return cf_eventgrid(cli_ctx).topic_event_subscriptions
19+
20+
21+
def domain_topic_event_subscriptions_factory(cli_ctx, _):
22+
return cf_eventgrid(cli_ctx).domain_topic_event_subscriptions
23+
24+
25+
def domain_event_subscriptions_factory(cli_ctx, _):
26+
return cf_eventgrid(cli_ctx).domain_event_subscriptions
27+
28+
1729
def domains_factory(cli_ctx, _):
1830
return cf_eventgrid(cli_ctx).domains
1931

@@ -46,6 +58,10 @@ def event_channels_factory(cli_ctx, _):
4658
return cf_eventgrid(cli_ctx).event_channels
4759

4860

61+
def channels_factory(cli_ctx, _):
62+
return cf_eventgrid(cli_ctx).channels
63+
64+
4965
def partner_topics_factory(cli_ctx, _):
5066
return cf_eventgrid(cli_ctx).partner_topics
5167

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

5672

73+
def partner_configurations_factory(cli_ctx, _):
74+
return cf_eventgrid(cli_ctx).partner_configurations
75+
76+
77+
def partner_destinations_factory(cli_ctx, _):
78+
return cf_eventgrid(cli_ctx).partner_destinations
79+
80+
81+
def verified_partners_factory(cli_ctx, _):
82+
return cf_eventgrid(cli_ctx).verified_partners
83+
84+
5785
def event_subscriptions_factory(cli_ctx, _):
5886
return cf_eventgrid(cli_ctx).event_subscriptions
5987

src/azure-cli/azure/cli/command_modules/eventgrid/_help.py

+1,028-108
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/eventgrid/_params.py

+238-26
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import argparse
7+
from knack.util import CLIError
8+
from dateutil.parser import parse # pylint: disable=import-error,relative-import
9+
from azure.mgmt.eventgrid.models import (
10+
Partner
11+
)
12+
13+
PARTNER_NAME = "partner-name"
14+
PARTNER_ID = "partner-registration-immutable-id"
15+
EXPIRATION_TIME = "expiration-time"
16+
17+
18+
# pylint: disable=protected-access
19+
# pylint: disable=too-few-public-methods
20+
class AddAuthorizedPartner(argparse._AppendAction):
21+
def __call__(self, parser, namespace, values, option_string=None):
22+
valuesLen = len(values)
23+
usage_error_msg = ("usage error: --authorized-partner [partner-name=<name>] "
24+
"[partner-registration-immutable-id=<id>] [expiration-time=<timestamp>]")
25+
if valuesLen < 1 or valuesLen > 3:
26+
raise CLIError(usage_error_msg)
27+
28+
partner_name = None
29+
partner_id = None
30+
expiration_time = None
31+
for item in values:
32+
try:
33+
key, value = item.split('=', 1)
34+
if key.lower() == PARTNER_NAME:
35+
partner_name = value
36+
elif key.lower() == PARTNER_ID:
37+
partner_id = value
38+
elif key.lower() == EXPIRATION_TIME:
39+
expiration_time = value
40+
else:
41+
raise ValueError()
42+
except ValueError:
43+
raise CLIError(usage_error_msg)
44+
45+
if expiration_time is not None:
46+
expiration_time = parse(expiration_time)
47+
48+
partner_info = Partner(
49+
partner_registration_immutable_id=partner_id,
50+
partner_name=partner_name,
51+
authorization_expiration_time_in_utc=expiration_time)
52+
53+
if namespace.authorized_partner is None:
54+
namespace.authorized_partner = []
55+
namespace.authorized_partner.append(partner_info)

src/azure-cli/azure/cli/command_modules/eventgrid/commands.py

+105-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from azure.cli.core.commands import CliCommandType
1010
from ._client_factory import (
1111
topics_factory,
12+
topic_event_subscriptions_factory,
13+
domain_event_subscriptions_factory,
14+
domain_topic_event_subscriptions_factory,
1215
domains_factory,
1316
domain_topics_factory,
1417
system_topics_factory,
@@ -19,8 +22,12 @@
1922
partner_registrations_factory,
2023
partner_namespaces_factory,
2124
event_channels_factory,
25+
channels_factory,
2226
partner_topics_factory,
23-
partner_topic_event_subscriptions_factory
27+
partner_topic_event_subscriptions_factory,
28+
partner_configurations_factory,
29+
partner_destinations_factory,
30+
verified_partners_factory
2431
)
2532

2633

@@ -31,12 +38,24 @@ def load_command_table(self, _):
3138
client_arg_name='self'
3239
)
3340

41+
topic_event_subscriptions_mgmt_util = CliCommandType(
42+
operations_tmpl='azure.mgmt.eventgrid.operations#TopicEventSubscriptionsOperations.{}',
43+
client_factory=topic_event_subscriptions_factory,
44+
client_arg_name='self'
45+
)
46+
3447
extension_topics_mgmt_util = CliCommandType(
3548
operations_tmpl='azure.mgmt.eventgrid.operations#ExtensionTopicsOperations.{}',
3649
client_factory=extension_topics_factory,
3750
client_arg_name='self'
3851
)
3952

53+
domain_event_subscriptions_mgmt_util = CliCommandType(
54+
operations_tmpl='azure.mgmt.eventgrid.operations#DomainEventSubscriptionsOperations.{}',
55+
client_factory=domain_event_subscriptions_factory,
56+
client_arg_name='self'
57+
)
58+
4059
domains_mgmt_util = CliCommandType(
4160
operations_tmpl='azure.mgmt.eventgrid.operations#DomainsOperations.{}',
4261
client_factory=domains_factory,
@@ -49,6 +68,12 @@ def load_command_table(self, _):
4968
client_arg_name='self'
5069
)
5170

71+
domain_topic_event_subscriptions_mgmt_util = CliCommandType(
72+
operations_tmpl='azure.mgmt.eventgrid.operations#DomainTopicEventSubscriptionsOperations.{}',
73+
client_factory=domain_topic_event_subscriptions_factory,
74+
client_arg_name='self'
75+
)
76+
5277
system_topics_mgmt_util = CliCommandType(
5378
operations_tmpl='azure.mgmt.eventgrid.operations#SystemTopicsOperations.{}',
5479
client_factory=system_topics_factory,
@@ -79,6 +104,12 @@ def load_command_table(self, _):
79104
client_arg_name='self'
80105
)
81106

107+
channels_mgmt_util = CliCommandType(
108+
operations_tmpl='azure.mgmt.eventgrid.operations#ChannelsOperations.{}',
109+
client_factory=channels_factory,
110+
client_arg_name='self'
111+
)
112+
82113
partner_topics_mgmt_util = CliCommandType(
83114
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerTopicsOperations.{}',
84115
client_factory=partner_topics_factory,
@@ -91,6 +122,24 @@ def load_command_table(self, _):
91122
client_arg_name='self'
92123
)
93124

125+
partner_configurations_mgmt_util = CliCommandType(
126+
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerConfigurationsOperations.{}',
127+
client_factory=partner_configurations_factory,
128+
client_arg_name='self'
129+
)
130+
131+
partner_destinations_mgmt_util = CliCommandType(
132+
operations_tmpl='azure.mgmt.eventgrid.operations#PartnerDestinationsOperations.{}',
133+
client_factory=partner_destinations_factory,
134+
client_arg_name='self'
135+
)
136+
137+
verified_partners_mgmt_util = CliCommandType(
138+
operations_tmpl='azure.mgmt.eventgrid.operations#VerifiedPartnersOperations.{}',
139+
client_factory=verified_partners_factory,
140+
client_arg_name='self'
141+
)
142+
94143
topic_type_mgmt_util = CliCommandType(
95144
operations_tmpl='azure.mgmt.eventgrid.operations#TopicTypesOperations.{}',
96145
client_factory=topic_types_factory,
@@ -106,6 +155,13 @@ def load_command_table(self, _):
106155
g.custom_command('create', 'cli_topic_create_or_update')
107156
g.custom_command('update', 'cli_topic_update')
108157

158+
with self.command_group('eventgrid topic event-subscription', topic_event_subscriptions_mgmt_util, client_factory=topic_event_subscriptions_factory) as g:
159+
g.custom_show_command('show', 'cli_topic_event_subscription_get')
160+
g.command('delete', 'begin_delete', confirmation=True)
161+
g.custom_command('list', 'cli_topic_event_subscription_list')
162+
g.custom_command('create', 'cli_topic_event_subscription_create_or_update')
163+
g.custom_command('update', 'cli_topic_event_subscription_update')
164+
109165
with self.command_group('eventgrid extension-topic', extension_topics_mgmt_util, client_factory=extension_topics_factory) as g:
110166
g.show_command('show', 'get')
111167

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

174+
with self.command_group('eventgrid domain topic event-subscription', domain_topic_event_subscriptions_mgmt_util, client_factory=domain_topic_event_subscriptions_factory) as g:
175+
g.custom_show_command('show', 'cli_domain_topic_event_subscription_get')
176+
g.custom_command('delete', 'cli_domain_topic_event_subscription_delete', confirmation=True)
177+
g.custom_command('list', 'cli_domain_topic_event_subscription_list')
178+
g.custom_command('create', 'cli_domain_topic_event_subscription_create_or_update')
179+
g.custom_command('update', 'cli_domain_topic_event_subscription_update')
180+
118181
with self.command_group('eventgrid domain', domains_mgmt_util, client_factory=domains_factory) as g:
119182
g.show_command('show', 'get')
120183
g.command('key list', 'list_shared_access_keys')
@@ -124,6 +187,13 @@ def load_command_table(self, _):
124187
g.command('delete', 'begin_delete')
125188
g.custom_command('update', 'cli_domain_update')
126189

190+
with self.command_group('eventgrid domain event-subscription', domain_event_subscriptions_mgmt_util, client_factory=domain_event_subscriptions_factory) as g:
191+
g.custom_show_command('show', 'cli_domain_event_subscription_get')
192+
g.command('delete', 'begin_delete', confirmation=True)
193+
g.custom_command('list', 'cli_domain_event_subscription_list')
194+
g.custom_command('create', 'cli_domain_event_subscription_create_or_update')
195+
g.custom_command('update', 'cli_domain_event_subscription_update')
196+
127197
with self.command_group('eventgrid system-topic', system_topics_mgmt_util, client_factory=system_topics_factory) as g:
128198
g.show_command('show', 'get')
129199
g.command('delete', 'begin_delete', confirmation=True)
@@ -138,14 +208,14 @@ def load_command_table(self, _):
138208
g.custom_command('create', 'cli_system_topic_event_subscription_create_or_update')
139209
g.custom_command('update', 'cli_system_topic_event_subscription_update')
140210

141-
with self.command_group('eventgrid partner registration', partner_registrations_mgmt_util, client_factory=partner_registrations_factory, is_preview=True) as g:
211+
with self.command_group('eventgrid partner registration', partner_registrations_mgmt_util, client_factory=partner_registrations_factory) as g:
142212
g.show_command('show', 'get')
143-
g.command('delete', 'delete', confirmation=True)
213+
g.command('delete', 'begin_delete', confirmation=True)
144214
g.custom_command('list', 'cli_partner_registration_list')
145215
g.custom_command('create', 'cli_partner_registration_create_or_update')
146216
# g.custom_command('update', 'cli_partner_registration_update')
147217

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

157-
with self.command_group('eventgrid partner namespace event-channel', event_channels_mgmt_util, client_factory=event_channels_factory, is_preview=True) as g:
227+
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:
158228
g.show_command('show', 'get')
159229
g.command('delete', 'begin_delete', confirmation=True)
160230
g.custom_command('list', 'cli_event_channel_list')
161231
# g.custom_command('update', 'cli_event_channel_update')
162232
g.custom_command('create', 'cli_event_channel_create_or_update')
163233

164-
with self.command_group('eventgrid partner topic', partner_topics_mgmt_util, client_factory=partner_topics_factory, is_preview=True) as g:
234+
with self.command_group('eventgrid partner namespace channel', channels_mgmt_util, client_factory=channels_factory) as g:
235+
g.show_command('show', 'get')
236+
g.command('delete', 'begin_delete', confirmation=True)
237+
g.custom_command('list', 'cli_channel_list')
238+
g.custom_command('update', 'cli_channel_update')
239+
g.custom_command('create', 'cli_channel_create_or_update')
240+
241+
with self.command_group('eventgrid partner topic', partner_topics_mgmt_util, client_factory=partner_topics_factory) as g:
165242
g.show_command('show', 'get')
166243
g.command('delete', 'begin_delete', confirmation=True)
167244
g.command('activate', 'activate')
@@ -170,13 +247,34 @@ def load_command_table(self, _):
170247
# g.custom_command('create', 'cli_partner_topic_create_or_update')
171248
# g.custom_command('update', 'cli_partner_topic_update')
172249

173-
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:
250+
with self.command_group('eventgrid partner topic event-subscription', partner_topic_event_subscriptions_mgmt_util, client_factory=partner_topic_event_subscriptions_factory) as g:
174251
g.custom_show_command('show', 'cli_partner_topic_event_subscription_get')
175252
g.command('delete', 'begin_delete', confirmation=True)
176253
g.custom_command('list', 'cli_partner_topic_event_subscription_list')
177254
g.custom_command('create', 'cli_partner_topic_event_subscription_create_or_update')
178255
g.custom_command('update', 'cli_partner_topic_event_subscription_update')
179256

257+
with self.command_group('eventgrid partner configuration', partner_configurations_mgmt_util, client_factory=partner_configurations_factory) as g:
258+
g.show_command('show', 'get')
259+
g.command('delete', 'begin_delete', confirmation=True)
260+
g.custom_command('authorize', 'cli_partner_configuration_authorize')
261+
g.custom_command('unauthorize', 'cli_partner_configuration_unauthorize')
262+
g.custom_command('list', 'cli_partner_configuration_list')
263+
g.custom_command('create', 'cli_partner_configuration_create_or_update')
264+
g.custom_command('update', 'cli_partner_configuration_update')
265+
266+
with self.command_group('eventgrid partner destination', partner_destinations_mgmt_util, client_factory=partner_destinations_factory) as g:
267+
g.show_command('show', 'get')
268+
g.command('delete', 'begin_delete', confirmation=True)
269+
g.command('activate', 'activate')
270+
g.custom_command('list', 'cli_partner_destination_list')
271+
g.custom_command('create', 'cli_partner_destination_create_or_update')
272+
g.custom_command('update', 'cli_partner_destination_update')
273+
274+
with self.command_group('eventgrid partner verified-partner', verified_partners_mgmt_util, client_factory=verified_partners_factory) as g:
275+
g.show_command('show', 'get')
276+
g.custom_command('list', 'cli_verified_partner_list')
277+
180278
custom_tmpl = 'azure.cli.command_modules.eventgrid.custom#{}'
181279
eventgrid_custom = CliCommandType(operations_tmpl=custom_tmpl)
182280

0 commit comments

Comments
 (0)