Skip to content

Commit

Permalink
EventGrid: 2020-04-01-preview CLI Extension refresh (#1714)
Browse files Browse the repository at this point in the history
* reapply new python sdk + bug fixes in help and private endpoint update)

* Add support for destination and deadletter with identity and recored the tests

* update version

* commment test case due to weird recording error

* fix condition

* address CR comments'

* fix linter error in help

* fix test and re-record the tests and fix help

* initial parameters support and test

* Add support for customer service parameters and add check and remaining properties

* Add publisher filter

* Rerecord tests

* fix example

* fix test

* comment on test

Co-authored-by: Ashraf Hamad <[email protected]>
  • Loading branch information
ahamad-MS and Ashraf Hamad authored May 18, 2020
1 parent a2bdac4 commit 2d9abba
Show file tree
Hide file tree
Showing 20 changed files with 3,123 additions and 1,973 deletions.
3 changes: 3 additions & 0 deletions azure-cli-extensions.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,11 @@
<Compile Include="src\dns\azext_dns\_validators.py" />
<Compile Include="src\dns\azext_dns\__init__.py" />
<Compile Include="src\dns\setup.py" />
<Compile Include="src\eventgrid\azext_eventgrid\advanced_filter.py" />
<Compile Include="src\eventgrid\azext_eventgrid\commands.py" />
<Compile Include="src\eventgrid\azext_eventgrid\custom.py" />
<Compile Include="src\eventgrid\azext_eventgrid\event_channel_filter.py" />
<Compile Include="src\eventgrid\azext_eventgrid\inbound_ip_rules.py" />
<Compile Include="src\eventgrid\azext_eventgrid\mgmt\eventgrid\event_grid_management_client.py" />
<Compile Include="src\eventgrid\azext_eventgrid\mgmt\eventgrid\models\dead_letter_destination.py" />
<Compile Include="src\eventgrid\azext_eventgrid\mgmt\eventgrid\models\event_grid_management_client_enums.py" />
Expand Down
40 changes: 31 additions & 9 deletions src/eventgrid/azext_eventgrid/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
- name: Create a new partner registration with basic information.
text: az eventgrid partner registration create -g rg1 --name partnerRegistrationName1 --partner-name Contoso --resource-type-name Accounts --authorized-subscription-ids 533ad9de-25db-46e2-b94a-d00c37cf022b 05aa2228-7d34-4635-922d-2b582c422445
- name: Create a new partner registration with partner information.
text: az eventgrid partner registration create -g rg1 --name partnerRegistrationName1 --partner-name Contoso --resource-type-name Accounts --authorized-subscription-ids 533ad9de-25db-46e2-b94a-d00c37cf022b 05aa2228-7d34-4635-922d-2b582c422445 --description ExampleDescription --display-name ExampleDisplayName1 --logo-uri https://www.example.com/logo.png --setup-uri https://www.example.com
text: az eventgrid partner registration create -g rg1 --name partnerRegistrationName1 --partner-name Contoso --resource-type-name Accounts --authorized-subscription-ids 533ad9de-25db-46e2-b94a-d00c37cf022b 05aa2228-7d34-4635-922d-2b582c422445 --description ExampleDescription --display-name ExampleDisplayName1 --logo-uri \'https://www.example.com/logo.png\' --setup-uri \'https://www.example.com\' --long-description \'This is sample description}\' --customer-service-number \'+1 800 123 4567' --customer-service-extension \'125\' --customer-service-uri \'https://www.example.com/customerservice\'
"""

helps['eventgrid partner registration list'] = """
Expand Down Expand Up @@ -315,9 +315,31 @@
helps['eventgrid partner namespace event-channel create'] = """
type: command
short-summary: Create an event channel under a partner namespace.
examples:
- name: Create a specific event-channel.
parameters:
- name: --publisher-filter
short-summary: A publisher filter that is used to enable filtering of events based on a specific event property. This set of filters that are specified by the publisher in order to determine which events to be received by the subscriber.
long-summary: |
Usage: --publisher-filter KEY[.INNERKEY] FILTEROPERATOR VALUE [VALUE ...]
StringIn: --publisher-filter data.Color StringIn Blue Red Orange Yellow
StringNotIn: --publisher-filter data.Color StringNotIn Blue Red Orange Yellow
StringContains: --publisher-filter subject StringContains Blue Red
StringBeginsWith: --publisher-filter subject StringBeginsWith Blue Red
StringEndsWith: --publisher-filter subject StringEndsWith img png jpg
NumberIn: --publisher-filter data.property1 NumberIn 5 10 20
NumberNotIn: --publisher-filter data.property2 NumberNotIn 100 200 300
NumberLessThan: --publisher-filter data.property3 NumberLessThan 100
NumberLessThanOrEquals: --publisher-filter data.property2 NumberLessThanOrEquals 100
NumberGreaterThan: --publisher-filter data.property3 NumberGreaterThan 100
NumberGreaterThanOrEquals: --publisher-filter data.property2 NumberGreaterThanOrEquals 100
BoolEquals: --publisher-filter data.property3 BoolEquals true
Multiple publisher filters can be specified by using more than one `--publisher-filter` argument.
examples:
- name: Create a specific event channel.
text: az eventgrid partner namespace event-channel create -g rg1 --partner-namespace-name partnernamespace1 -n eventChannelName1 --source SourceExample1 --destination-subscription-id 61f7c265-374d-499e-866d-5f4cc302b888 --destination-resource-group rg2 --desination-topic-name topicName1
- name: Create a specific event channel with an activation expiration time and partner topic friendly description.
text: az eventgrid partner namespace event-channel create -g rg1 --partner-namespace-name partnernamespace1 -n eventChannelName1 --source SourceExample1 --destination-subscription-id 61f7c265-374d-499e-866d-5f4cc302b888 --destination-resource-group rg2 --desination-topic-name topicName1 --activation-expiration-date \'2020-05-20T10:00\' --partner-topic-description \'This topic is created by Costoco corp on user behavior.\'
- name: Create a specific event channel with publisher filters.
text: az eventgrid partner namespace event-channel create -g rg1 --partner-namespace-name partnernamespace1 -n eventChannelName1 --source SourceExample1 --destination-subscription-id 61f7c265-374d-499e-866d-5f4cc302b888 --destination-resource-group rg2 --desination-topic-name topicName1 --publisher-filter data.key1 NumberIn 2 3 4 100 200 --publisher-filter data.key2 StringIn 2 3 4 100 200
"""

helps['eventgrid partner namespace event-channel list'] = """
Expand Down Expand Up @@ -518,8 +540,8 @@
az eventgrid system-topic event-subscription create --name es1 \\
-g rg1 --system-topic-name systemtopic1 \\
--endpoint https://contoso.azurewebsites.net/api/f1?code=code
--azure_active_directory_tenant_id azureactivedirectorytenantid
--azure_active_directory_application_id_or_uri azureactivedirectoryapplicationidoruri
--azure-active-directory-tenant-id azureactivedirectorytenantid
--azure-active-directory-application-id-or-uri azureactivedirectoryapplicationidoruri
- name: Create a new event subscription for an Event Grid system topic, using Azure Function as destination.
text: |
az eventgrid system-topic event-subscription create -n es1 \\
Expand Down Expand Up @@ -674,8 +696,8 @@
az eventgrid partner topic event-subscription create --name es1 \\
-g rg1 --partner-topic-name partnertopic1 \\
--endpoint https://contoso.azurewebsites.net/api/f1?code=code
--azure_active_directory_tenant_id azureactivedirectorytenantid
--azure_active_directory_application_id_or_uri azureactivedirectoryapplicationidoruri
--azure-active-directory-tenant-id azureactivedirectorytenantid
--azure-active-directory-application-id-or-uri azureactivedirectoryapplicationidoruri
- name: Create a new event subscription for an Event Grid partner topic, using Azure Function as destination.
text: |
az eventgrid partner topic event-subscription create -n es1 \\
Expand Down Expand Up @@ -900,8 +922,8 @@
az eventgrid event-subscription create --name es1 \\
--source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \\
--endpoint https://contoso.azurewebsites.net/api/f1?code=code
--azure_active_directory_tenant_id azureactivedirectorytenantid
--azure_active_directory_application_id_or_uri azureactivedirectoryapplicationidoruri
--azure-active-directory-tenant-id azureactivedirectorytenantid
--azure-active-directory-application-id-or-uri azureactivedirectoryapplicationidoruri
- name: Create a new event subscription for an Event Grid topic, using Azure Function as destination.
text: |
az eventgrid event-subscription create --name es1 \\
Expand Down
17 changes: 17 additions & 0 deletions src/eventgrid/azext_eventgrid/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from .advanced_filter import EventSubscriptionAddFilter
from .event_channel_filter import EventChannelAddFilter
from .inbound_ip_rules import AddInboundIpRule

included_event_types_type = CLIArgumentType(
Expand Down Expand Up @@ -150,6 +151,15 @@
arg_type=name_type,
options_list=['--partner-topic-source'])

phone_number_type = CLIArgumentType(
help='The customer service number of the publisher. The expected phone format should start with a \'+\' sign'
' followed by the country code. The remaining digits are then followed. Only digits and spaces are allowed and its'
' length cannot exceed 16 digits including country code. Examples of valid phone numbers are: +1 515 123 4567 and'
' +966 7 5115 2471. Examples of invalid phone numbers are: +1 (515) 123-4567, 1 515 123 4567 and +966 121 5115 24 7 551 1234 43.')

phone_extension_type = CLIArgumentType(
help='The extension of the customer service number of the publisher. Only digits are allowed and number of digits should not exceed 10.')


def load_arguments(self, _): # pylint: disable=too-many-statements
with self.argument_context('eventgrid') as c:
Expand Down Expand Up @@ -283,6 +293,10 @@ def load_arguments(self, _): # pylint: disable=too-many-statements

with self.argument_context('eventgrid partner registration') as c:
c.argument('partner_registration_name', arg_type=partner_registration_name_type, options_list=['--name', '-n'], id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/partnerregistrations'))
c.argument('long_description', help='Description of the custom scenarios and integration. Length of this description should not exceed 2048 characters', id_part=None)
c.argument('customer_service_number', arg_type=phone_number_type, id_part=None)
c.argument('customer_service_extension', arg_type=phone_extension_type, id_part=None)
c.argument('customer_service_uri', help='The customer service URI of the publisher.', id_part=None)

with self.argument_context('eventgrid partner registration list') as c:
c.argument('odata_query', arg_type=odata_query_type, id_part=None)
Expand All @@ -303,6 +317,9 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
c.argument('partner_namespace_name', arg_type=partner_namespace_name_type, id_part='name')
c.argument('event_channel_name', arg_type=event_channel_name_type, options_list=['--name', '-n'], id_part='name', completer=get_resource_name_completion_list('Microsoft.EventGrid/partnernamespaes/eventchannels'))
c.argument('partner_topic_source', arg_type=partner_topic_source_type, options_list=['--source'])
c.argument('activation_expiration_date', help="Date or datetime in UTC ISO 8601 format (e.g., '2022-02-17T01:59:59+00:00' or '2022-02-17') after which the event channel and corresponding partner topic would expire and get auto deleted. If this time is not specified, the expiration date is set to seven days by default.")
c.argument('partner_topic_description', help="Friendly description of the corresponding partner topic. This will be helpful to remove any ambiguity of the origin of creation of the partner topic for the customer.")
c.argument('publisher_filter', action=EventChannelAddFilter, nargs='+')

with self.argument_context('eventgrid partner namespace event-channel show') as c:
c.argument('partner_namespace_name', arg_type=partner_namespace_name_type, id_part='name')
Expand Down
51 changes: 48 additions & 3 deletions src/eventgrid/azext_eventgrid/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
ConnectionState,
EventSubscriptionIdentity,
DeliveryWithResourceIdentity,
DeadLetterWithResourceIdentity)
DeadLetterWithResourceIdentity,
EventChannelFilter)

logger = get_logger(__name__)

Expand Down Expand Up @@ -92,7 +93,12 @@
EVENTTIME = "eventtime"
EVENTTYPE = "eventtype"
DATAVERSION = "dataversion"

PHONE_NUMBER_REGEX = "^\\+(?:[0-9] ?){6,15}[0-9]$"
EXTENSION_NUMBER_REGEX = "^(?:[0-9] ?){1,8}[0-9]$"

DEFAULT_TOP = 100
MAX_LONG_DESCRIPTION_LEN = 2048


def cli_topic_list(
Expand Down Expand Up @@ -330,11 +336,34 @@ def cli_partner_registration_create_or_update(
resource_type_name,
display_name=None,
description=None,
long_description=None,
customer_service_number=None,
customer_service_extension=None,
customer_service_uri=None,
logo_uri=None,
setup_uri=None,
authorized_subscription_ids=None,
tags=None):

if long_description is not None and len(long_description) >= MAX_LONG_DESCRIPTION_LEN:
raise CLIError('The long description cannot exceed ' + str(MAX_LONG_DESCRIPTION_LEN) + ' characters.')

if customer_service_number is not None:
searchObj = re.search(PHONE_NUMBER_REGEX, customer_service_number)
if searchObj is None:
raise CLIError('Invalid customer service phone number. The expected phone format should start with'
' a \'+\' sign followed by the country code. The remaining digits are then followed.'
' Only digits and spaces are allowed and its length cannot exceed 16 digits including'
' country code. Examples of valid phone numbers are: +1 515 123 4567 and'
' +966 7 5115 2471. Examples of invalid phone numbers are: +1 (515) 123-4567,'
' 1 515 123 4567 and +966 121 5115 24 7 551 1234 43.')

if customer_service_extension is not None:
searchObj = re.search(EXTENSION_NUMBER_REGEX, customer_service_extension)
if searchObj is None:
raise CLIError('Invalid customer service extension number. Only digits are allowed'
' and number of digits should not exceed 10.')

partner_registration_info = PartnerRegistration(
location=GLOBAL,
partner_name=partner_name,
Expand All @@ -343,6 +372,10 @@ def cli_partner_registration_create_or_update(
setup_uri=setup_uri,
partner_resource_type_display_name=display_name,
partner_resource_type_description=description,
long_description=long_description,
partner_customer_service_number=customer_service_number,
partner_customer_service_extension=customer_service_extension,
customer_service_uri=customer_service_uri,
authorized_azure_subscription_ids=authorized_subscription_ids,
tags=tags)

Expand Down Expand Up @@ -425,7 +458,10 @@ def cli_event_channel_create_or_update(
partner_topic_source,
destination_subscription_id,
destination_resource_group,
desination_topic_name):
desination_topic_name,
activation_expiration_date=None,
partner_topic_description=None,
publisher_filter=None):

source_info = EventChannelSource(source=partner_topic_source)

Expand All @@ -434,7 +470,16 @@ def cli_event_channel_create_or_update(
resource_group=destination_resource_group,
partner_topic_name=desination_topic_name)

event_channel_info = EventChannel(source=source_info, destination=destination_info)
event_channel_filter = None
if publisher_filter is not None:
event_channel_filter = EventChannelFilter(advanced_filters=publisher_filter)

event_channel_info = EventChannel(
source=source_info,
destination=destination_info,
expiration_time_if_not_activated_utc=activation_expiration_date,
partner_topic_friendly_description=partner_topic_description,
filter=event_channel_filter)

return client.create_or_update(
resource_group_name,
Expand Down
Loading

0 comments on commit 2d9abba

Please sign in to comment.