def _event_subscription_create(client, resource_group_name, provider_namespace, resource_type, resource_name, event_subscription_name, endpoint, endpoint_type, included_event_types, subject_begins_with, subject_ends_with, is_subject_case_sensitive, labels): scope = _get_scope(resource_group_name, provider_namespace, resource_type, resource_name) if endpoint_type.lower() == WEBHOOK_DESTINATION.lower(): destination = WebHookEventSubscriptionDestination(endpoint) elif endpoint_type.lower() == EVENTHUB_DESTINATION.lower(): destination = EventHubEventSubscriptionDestination(endpoint) event_subscription_filter = EventSubscriptionFilter( subject_begins_with, subject_ends_with, included_event_types, is_subject_case_sensitive) event_subscription_info = EventSubscription(destination, event_subscription_filter, labels) async_event_subscription_create = client.create(scope, event_subscription_name, event_subscription_info) created_event_subscription = async_event_subscription_create.result() return created_event_subscription
def cli_eventgrid_event_subscription_create(cmd, client, event_subscription_name, endpoint, resource_id=None, resource_group_name=None, topic_name=None, endpoint_type=WEBHOOK_DESTINATION, included_event_types=None, subject_begins_with=None, subject_ends_with=None, is_subject_case_sensitive=False, labels=None): scope = _get_scope_for_event_subscription(cmd.cli_ctx, resource_id, topic_name, resource_group_name) if endpoint_type.lower() == WEBHOOK_DESTINATION.lower(): destination = WebHookEventSubscriptionDestination(endpoint) elif endpoint_type.lower() == EVENTHUB_DESTINATION.lower(): destination = EventHubEventSubscriptionDestination(endpoint) event_subscription_filter = EventSubscriptionFilter( subject_begins_with, subject_ends_with, included_event_types, is_subject_case_sensitive) event_subscription_info = EventSubscription(destination, event_subscription_filter, labels) async_event_subscription_create = client.create_or_update( scope, event_subscription_name, event_subscription_info) created_event_subscription = async_event_subscription_create.result() return created_event_subscription
def _get_endpoint_destination(endpoint_type, endpoint): if endpoint_type.lower() == WEBHOOK_DESTINATION.lower(): destination = WebHookEventSubscriptionDestination(endpoint_url=endpoint) elif endpoint_type.lower() == EVENTHUB_DESTINATION.lower(): destination = EventHubEventSubscriptionDestination(resource_id=endpoint) elif endpoint_type.lower() == HYBRIDCONNECTION_DESTINATION.lower(): destination = HybridConnectionEventSubscriptionDestination(resource_id=endpoint) elif endpoint_type.lower() == STORAGEQUEUE_DESTINATION.lower(): destination = _get_storage_queue_destination(endpoint) return destination
def update_event_subscription(instance, endpoint=None, endpoint_type=WEBHOOK_DESTINATION, subject_begins_with=None, subject_ends_with=None, included_event_types=None, labels=None): event_subscription_destination = None event_subscription_labels = instance.labels event_subscription_filter = instance.filter if endpoint is not None: if endpoint_type.lower() == WEBHOOK_DESTINATION.lower(): event_subscription_destination = WebHookEventSubscriptionDestination( endpoint) elif endpoint_type.lower() == EVENTHUB_DESTINATION.lower(): event_subscription_destination = EventHubEventSubscriptionDestination( endpoint) if subject_begins_with is not None: event_subscription_filter.subject_begins_with = subject_begins_with if subject_ends_with is not None: event_subscription_filter.subject_ends_with = subject_ends_with if included_event_types is not None: event_subscription_filter.included_event_types = included_event_types if labels is not None: event_subscription_labels = labels params = EventSubscriptionUpdateParameters( destination=event_subscription_destination, filter=event_subscription_filter, labels=event_subscription_labels) return params
def create_event_subscription(self): print("creating event subscription") event_client = EventGridManagementClient(self.credentials, self.subscription_id) scope = '/subscriptions/' + self.subscription_id + '/resourceGroups/' + self.test_storage_res_group + '/providers/microsoft.storage/storageaccounts/%s' % self.test_storageaccount_name destination = EventHubEventSubscriptionDestination( resource_id=self.get_event_hub_resource_id()) esfilter = EventSubscriptionFilter( **{ "subject_begins_with": "/blobServices/default/containers/%s/" % self.test_container_name, "subject_ends_with": "", "is_subject_case_sensitive": False, "included_event_types": ["Microsoft.Storage.BlobCreated"] }) event_subscription_info = EventSubscription(destination=destination, filter=esfilter) create_resp = event_client.event_subscriptions.create_or_update( scope, self.event_subscription_name, event_subscription_info) create_resp.wait()