@@ -1333,136 +1333,119 @@ def _update_event_subscription_internal( # pylint: disable=too-many-locals,too-
13331333 deadletter_identity ,
13341334 deadletter_endpoint )
13351335
1336- event_subscription_destination_with_resource_identity = None
1337- if instance .delivery_with_resource_identity is not None :
1338- event_subscription_destination_with_resource_identity = instance .delivery_with_resource_identity .destination
1339-
1340- deadletter_destination = None
1341- instance_delivery_with_resource_identity = instance .delivery_with_resource_identity
1342- event_subscription_destination = instance .destination
1343- event_subscription_labels = instance .labels
1344- event_subscription_filter = instance .filter
1345- event_delivery_schema = instance .event_delivery_schema
1346- retry_policy = instance .retry_policy
1347-
13481336 if endpoint_type .lower () != WEBHOOK_DESTINATION .lower () and endpoint is None :
13491337 raise CLIError ('Invalid usage: Since --endpoint-type is specified, a valid endpoint must also be specified.' )
13501338
1351- tennant_id = None
1352- application_id = None
1353-
1354- # for the update path, endpoint_type can be None but it does not mean that this is webhook,
1355- # as it can be other types too.
1356- if event_subscription_destination is not None and \
1357- hasattr (event_subscription_destination , 'azure_active_directory_tenant_id' ):
1358- tennant_id = event_subscription_destination .azure_active_directory_tenant_id
1359-
1360- if event_subscription_destination is not None and \
1361- hasattr (event_subscription_destination , 'azure_active_directory_application_id_or_uri' ):
1362- application_id = event_subscription_destination .azure_active_directory_application_id_or_uri
1363-
1364- if event_subscription_destination_with_resource_identity is not None and \
1365- hasattr (event_subscription_destination_with_resource_identity , 'azure_active_directory_tenant_id' ):
1366- tennant_id = event_subscription_destination_with_resource_identity .azure_active_directory_tenant_id
1339+ current_destination = instance .destination
1340+ current_filter = instance .filter
1341+ current_event_delivery_schema = instance .event_delivery_schema
1342+ current_retry_policy = instance .retry_policy
1343+ current_destination_with_resource_identity = None
13671344
1368- if event_subscription_destination_with_resource_identity is not None and \
1369- hasattr (event_subscription_destination_with_resource_identity , 'azure_active_directory_application_id_or_uri' ):
1370- application_id = \
1371- event_subscription_destination_with_resource_identity .azure_active_directory_application_id_or_uri
1345+ if instance .delivery_with_resource_identity is not None :
1346+ current_destination_with_resource_identity = instance .delivery_with_resource_identity .destination
13721347
1373- max_events_per_batch = 0
1374- preferred_batch_size_in_kilobytes = 0
1348+ tenant_id = _get_tenant_id ( current_destination , current_destination_with_resource_identity )
1349+ application_id = _get_application_id ( current_destination , current_destination_with_resource_identity )
13751350
1376- if event_subscription_destination is not None and \
1377- event_subscription_destination . endpoint_type is not None and ( event_subscription_destination . endpoint_type . lower () == WEBHOOK_DESTINATION . lower () or event_subscription_destination . endpoint_type . lower () == AZUREFUNCTION_DESTINATION . lower ()): # pylint: disable=line- too-long
1378- max_events_per_batch = event_subscription_destination . max_events_per_batch
1379- preferred_batch_size_in_kilobytes = event_subscription_destination . preferred_batch_size_in_kilobytes
1351+ # for the update path, endpoint_type can be None but it does not mean that this is webhook,
1352+ # as it can be other types too.
1353+ current_max_events_per_batch = 0
1354+ current_preferred_batch_size_in_kilobytes = 0
13801355
1381- if event_subscription_destination_with_resource_identity is not None and \
1382- event_subscription_destination_with_resource_identity .endpoint_type is not None and (event_subscription_destination_with_resource_identity .endpoint_type .lower () == WEBHOOK_DESTINATION .lower () or event_subscription_destination_with_resource_identity .endpoint_type .lower () == AZUREFUNCTION_DESTINATION .lower ()): # pylint: disable=line-too-long
1383- max_events_per_batch = event_subscription_destination_with_resource_identity .max_events_per_batch
1384- preferred_batch_size_in_kilobytes = event_subscription_destination_with_resource_identity .preferred_batch_size_in_kilobytes # pylint: disable=line-too-long
1356+ if current_destination is not None and (current_destination .endpoint_type .lower () == WEBHOOK_DESTINATION .lower () or current_destination .endpoint_type .lower () == AZUREFUNCTION_DESTINATION .lower ()): # pylint: disable=line-too-long
1357+ current_max_events_per_batch = current_destination .max_events_per_batch
1358+ current_preferred_batch_size_in_kilobytes = current_destination .preferred_batch_size_in_kilobytes
1359+ elif current_destination_with_resource_identity is not None and (current_destination_with_resource_identity .endpoint_type .lower () == WEBHOOK_DESTINATION .lower () or current_destination_with_resource_identity .endpoint_type .lower () == AZUREFUNCTION_DESTINATION .lower ()): # pylint: disable=line-too-long
1360+ current_max_events_per_batch = current_destination_with_resource_identity .max_events_per_batch
1361+ current_preferred_batch_size_in_kilobytes = current_destination_with_resource_identity .preferred_batch_size_in_kilobytes # pylint: disable=line-too-long
13851362
1386- delivery_with_resource_identity = None
1363+ updated_destination = None
1364+ updated_delivery_with_resource_identity = None
13871365
13881366 # if endpoint and delivery_identity_endpoint is not specified then use the instance value
13891367 if endpoint is None and delivery_identity_endpoint is None :
1390- if event_subscription_destination is not None :
1368+ if current_destination is not None :
13911369 _validate_and_update_destination (
1392- event_subscription_destination .endpoint_type ,
1393- event_subscription_destination ,
1370+ current_destination .endpoint_type ,
1371+ current_destination ,
13941372 storage_queue_msg_ttl ,
13951373 delivery_attribute_mapping )
1396- elif event_subscription_destination_with_resource_identity is not None :
1374+ updated_destination = current_destination
1375+ elif current_destination_with_resource_identity is not None :
13971376 _validate_and_update_destination (
1398- event_subscription_destination_with_resource_identity .endpoint_type ,
1399- instance_delivery_with_resource_identity .destination ,
1377+ current_destination_with_resource_identity .endpoint_type ,
1378+ current_destination_with_resource_identity .destination ,
14001379 storage_queue_msg_ttl ,
14011380 delivery_attribute_mapping )
1402- delivery_with_resource_identity = instance_delivery_with_resource_identity
1381+ updated_delivery_with_resource_identity = current_destination_with_resource_identity
14031382 elif endpoint is not None :
14041383 _validate_destination_attribute (
14051384 endpoint_type ,
14061385 storage_queue_msg_ttl ,
14071386 delivery_attribute_mapping )
1408- event_subscription_destination = _get_endpoint_destination (
1387+ updated_destination = _get_endpoint_destination (
14091388 endpoint_type ,
14101389 endpoint ,
1411- max_events_per_batch ,
1412- preferred_batch_size_in_kilobytes ,
1413- tennant_id ,
1390+ current_max_events_per_batch ,
1391+ current_preferred_batch_size_in_kilobytes ,
1392+ tenant_id ,
14141393 application_id ,
14151394 storage_queue_msg_ttl ,
14161395 delivery_attribute_mapping )
14171396 elif delivery_identity_endpoint is not None :
1418- identity_type_name = _get_event_subscription_identity_type (delivery_identity )
1419- delivery_identity_info = EventSubscriptionIdentity (type = identity_type_name )
14201397 destination_with_identity = _get_endpoint_destination (
14211398 delivery_identity_endpoint_type ,
14221399 delivery_identity_endpoint ,
14231400 0 ,
14241401 0 ,
1425- tennant_id ,
1402+ tenant_id ,
14261403 application_id ,
14271404 storage_queue_msg_ttl ,
14281405 delivery_attribute_mapping )
1429- delivery_with_resource_identity = DeliveryWithResourceIdentity (
1406+
1407+ identity_type_name = _get_event_subscription_identity_type (delivery_identity )
1408+ delivery_identity_info = EventSubscriptionIdentity (type = identity_type_name )
1409+
1410+ updated_delivery_with_resource_identity = DeliveryWithResourceIdentity (
14301411 identity = delivery_identity_info ,
14311412 destination = destination_with_identity )
14321413
1414+ updated_deadletter_destination = None
14331415 if deadletter_endpoint is not None :
1434- deadletter_destination = _get_deadletter_destination (deadletter_endpoint )
1435-
1436- deadletter_with_resource_identity = None
1416+ updated_deadletter_destination = _get_deadletter_destination (deadletter_endpoint )
14371417
1418+ updated_deadletter_with_resource_identity = None
14381419 if deadletter_identity_endpoint is not None :
14391420 deadletter_destination_with_identity = _get_deadletter_destination (deadletter_identity_endpoint )
14401421 deadletter_identity_type_name = _get_event_subscription_identity_type (deadletter_identity )
14411422 deadletter_delivery_identity_info = EventSubscriptionIdentity (type = deadletter_identity_type_name )
1442- deadletter_with_resource_identity = DeadLetterWithResourceIdentity (
1423+ updated_deadletter_with_resource_identity = DeadLetterWithResourceIdentity (
14431424 identity = deadletter_delivery_identity_info ,
14441425 dead_letter_destination = deadletter_destination_with_identity )
14451426
1446- _set_event_subscription_filter (
1447- event_subscription_filter ,
1427+ _update_event_subscription_filter (
1428+ current_filter ,
14481429 subject_begins_with ,
14491430 subject_ends_with ,
14501431 included_event_types ,
14511432 enable_advanced_filtering_on_arrays ,
14521433 advanced_filter )
1434+ updated_filter = current_filter
14531435
1436+ updated_labels = None
14541437 if labels is not None :
1455- event_subscription_labels = labels
1438+ updated_labels = labels
14561439
14571440 params = EventSubscriptionUpdateParameters (
1458- destination = event_subscription_destination ,
1459- filter = event_subscription_filter ,
1460- labels = event_subscription_labels ,
1461- retry_policy = retry_policy ,
1462- dead_letter_destination = deadletter_destination ,
1463- event_delivery_schema = event_delivery_schema ,
1464- delivery_with_resource_identity = delivery_with_resource_identity ,
1465- dead_letter_with_resource_identity = deadletter_with_resource_identity )
1441+ destination = updated_destination ,
1442+ filter = updated_filter ,
1443+ labels = updated_labels ,
1444+ retry_policy = current_retry_policy ,
1445+ dead_letter_destination = updated_deadletter_destination ,
1446+ event_delivery_schema = current_event_delivery_schema ,
1447+ delivery_with_resource_identity = updated_delivery_with_resource_identity ,
1448+ dead_letter_with_resource_identity = updated_deadletter_with_resource_identity )
14661449
14671450 return params
14681451
@@ -1655,6 +1638,27 @@ def _get_event_subscription_identity_type(identity_type_name):
16551638 return result
16561639
16571640
1641+ def _get_tenant_id (destination , destination_with_resource_identity ):
1642+ tenant_id = None
1643+
1644+ if destination is not None and hasattr (destination , 'azure_active_directory_tenant_id' ):
1645+ tenant_id = destination .azure_active_directory_tenant_id
1646+ elif destination_with_resource_identity is not None and hasattr (destination_with_resource_identity , 'azure_active_directory_tenant_id' ): # pylint: disable=line-too-long
1647+ tenant_id = destination_with_resource_identity .azure_active_directory_tenant_id
1648+
1649+ return tenant_id
1650+
1651+
1652+ def _get_application_id (destination , destination_with_resource_identity ):
1653+ application_id = None
1654+
1655+ if destination is not None and hasattr (destination , 'azure_active_directory_application_id_or_uri' ):
1656+ application_id = destination .azure_active_directory_application_id_or_uri
1657+ elif destination_with_resource_identity is not None and hasattr (destination_with_resource_identity , 'azure_active_directory_application_id_or_uri' ): # pylint: disable=line-too-long
1658+ application_id = destination_with_resource_identity .azure_active_directory_application_id_or_uri
1659+ return application_id
1660+
1661+
16581662def _get_input_schema_and_mapping (
16591663 input_schema = EVENTGRID_SCHEMA ,
16601664 input_mapping_fields = None ,
@@ -1812,7 +1816,7 @@ def _get_identity_info_only_if_not_none(identity=None):
18121816 return identity_info
18131817
18141818
1815- def _set_event_subscription_filter (
1819+ def _update_event_subscription_filter (
18161820 event_subscription_filter ,
18171821 subject_begins_with = None ,
18181822 subject_ends_with = None ,
0 commit comments