diff --git a/eng/tox/allowed_pylint_failures.py b/eng/tox/allowed_pylint_failures.py index 1adcea8fcdad..e9505fee9cf9 100644 --- a/eng/tox/allowed_pylint_failures.py +++ b/eng/tox/allowed_pylint_failures.py @@ -36,7 +36,6 @@ "azure-common", "azure-nspkg", "azure-servicemanagement-legacy", - "azure-eventgrid", "azure-graphrbac", "azure-loganalytics", "azure-servicefabric", diff --git a/sdk/eventgrid/azure-eventgrid/azure/__init__.py b/sdk/eventgrid/azure-eventgrid/azure/__init__.py index 0260537a02bb..69e3be50dac4 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/__init__.py +++ b/sdk/eventgrid/azure-eventgrid/azure/__init__.py @@ -1 +1 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) \ No newline at end of file +__path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py index 0b0357a1f50d..3c4ee3a3aa72 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py @@ -7,11 +7,11 @@ from ._publisher_client import EventGridPublisherClient from ._consumer import EventGridConsumer from ._helpers import generate_shared_access_signature -from ._models import CloudEvent, CustomEvent, EventGridEvent, StorageBlobCreatedEventData +from ._models import CloudEvent, CustomEvent, EventGridEvent from ._shared_access_signature_credential import EventGridSharedAccessSignatureCredential from ._version import VERSION __all__ = ['EventGridPublisherClient', 'EventGridConsumer', - 'CloudEvent', 'CustomEvent', 'EventGridEvent', 'StorageBlobCreatedEventData', - 'generate_shared_access_signature', 'EventGridSharedAccessSignatureCredential'] + 'CloudEvent', 'CustomEvent', 'EventGridEvent', 'generate_shared_access_signature', + 'EventGridSharedAccessSignatureCredential'] __version__ = VERSION diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py index ae2d8a2aa9d9..acc80d774810 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py @@ -7,12 +7,8 @@ # -------------------------------------------------------------------------- from typing import TYPE_CHECKING -import json -import six import logging - -from azure.core import PipelineClient -from msrest import Deserializer, Serializer +from ._models import CloudEvent, EventGridEvent if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -20,13 +16,12 @@ _LOGGER = logging.getLogger(__name__) -from ._models import CloudEvent, EventGridEvent - class EventGridConsumer(object): """ - A consumer responsible for deserializing event handler messages, to allow for access to strongly typed Event objects. + A consumer responsible for deserializing event handler messages, to allow for + access to strongly typed Event objects. """ - def decode_cloud_event(self, cloud_event, **kwargs): + def decode_cloud_event(self, cloud_event, **kwargs): # pylint: disable=no-self-use # type: (Union[str, dict, bytes], Any) -> CloudEvent """Single event following CloudEvent schema will be parsed and returned as Deserialized Event. :param cloud_event: The event to be deserialized. @@ -37,17 +32,19 @@ def decode_cloud_event(self, cloud_event, **kwargs): """ encode = kwargs.pop('encoding', 'utf-8') try: - cloud_event = CloudEvent._from_json(cloud_event, encode) - deserialized_event = CloudEvent._from_generated(cloud_event) - CloudEvent._deserialize_data(deserialized_event, deserialized_event.type) - return deserialized_event + cloud_event = CloudEvent._from_json(cloud_event, encode) # pylint: disable=protected-access + deserialized_event = CloudEvent._from_generated(cloud_event) # pylint: disable=protected-access + CloudEvent._deserialize_data(deserialized_event, deserialized_event.type) # pylint: disable=protected-access + return deserialized_event except Exception as err: - _LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent schema.') - _LOGGER.error('Your event: {}'.format(cloud_event)) + _LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. \ + Event must be a string, dict, or bytes following the CloudEvent schema.') + _LOGGER.error('Your event: %s', cloud_event) _LOGGER.error(err) - raise ValueError('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent schema.') + raise ValueError('Error: cannot deserialize event. Event does not have a valid format. \ + Event must be a string, dict, or bytes following the CloudEvent schema.') - def decode_eventgrid_event(self, eventgrid_event, **kwargs): + def decode_eventgrid_event(self, eventgrid_event, **kwargs): # pylint: disable=no-self-use # type: (Union[str, dict, bytes], Any) -> EventGridEvent """Single event following EventGridEvent schema will be parsed and returned as Deserialized Event. :param eventgrid_event: The event to be deserialized. @@ -58,12 +55,14 @@ def decode_eventgrid_event(self, eventgrid_event, **kwargs): """ encode = kwargs.pop('encoding', 'utf-8') try: - eventgrid_event = EventGridEvent._from_json(eventgrid_event, encode) + eventgrid_event = EventGridEvent._from_json(eventgrid_event, encode) # pylint: disable=protected-access deserialized_event = EventGridEvent.deserialize(eventgrid_event) - EventGridEvent._deserialize_data(deserialized_event, deserialized_event.event_type) + EventGridEvent._deserialize_data(deserialized_event, deserialized_event.event_type) # pylint: disable=protected-access return deserialized_event except Exception as err: - _LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent schema.') - _LOGGER.error('Your event: {}'.format(eventgrid_event)) + _LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. \ + Event must be a string, dict, or bytes following the CloudEvent schema.') + _LOGGER.error('Your event: %s', eventgrid_event) _LOGGER.error(err) - raise ValueError('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent schema.') + raise ValueError('Error: cannot deserialize event. Event does not have a valid format. \ + Event must be a string, dict, or bytes following the CloudEvent schema.') diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py index dc14a40bfacc..55412f815a13 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py @@ -19,7 +19,8 @@ "Microsoft.EventGrid.SubscriptionValidationEvent": models.SubscriptionValidationEventData, "Microsoft.EventGrid.SubscriptionDeletedEvent": models.SubscriptionDeletedEventData, "Microsoft.EventHub.CaptureFileCreated": models.EventHubCaptureFileCreatedEventData, - "Microsoft.MachineLearningServices.DatasetDriftDetected": models.MachineLearningServicesDatasetDriftDetectedEventData, + "Microsoft.MachineLearningServices.DatasetDriftDetected": + models.MachineLearningServicesDatasetDriftDetectedEventData, "Microsoft.MachineLearningServices.ModelDeployed": models.MachineLearningServicesModelDeployedEventData, "Microsoft.MachineLearningServices.ModelRegistered": models.MachineLearningServicesModelRegisteredEventData, "Microsoft.MachineLearningServices.RunCompleted": models.MachineLearningServicesRunCompletedEventData, @@ -47,7 +48,8 @@ "Microsoft.Media.LiveEventEncoderDisconnected": models.MediaLiveEventEncoderDisconnectedEventData, "Microsoft.Media.LiveEventIncomingStreamReceived": models.MediaLiveEventIncomingStreamReceivedEventData, "Microsoft.Media.LiveEventIncomingStreamsOutOfSync": models.MediaLiveEventIncomingStreamsOutOfSyncEventData, - "Microsoft.Media.LiveEventIncomingVideoStreamsOutOfSync": models.MediaLiveEventIncomingVideoStreamsOutOfSyncEventData, + "Microsoft.Media.LiveEventIncomingVideoStreamsOutOfSync": + models.MediaLiveEventIncomingVideoStreamsOutOfSyncEventData, "Microsoft.Media.LiveEventIncomingDataChunkDropped": models.MediaLiveEventIncomingDataChunkDroppedEventData, "Microsoft.Media.LiveEventIngestHeartbeat": models.MediaLiveEventIngestHeartbeatEventData, "Microsoft.Media.LiveEventTrackDiscontinuityDetected": models.MediaLiveEventTrackDiscontinuityDetectedEventData, @@ -60,8 +62,10 @@ "Microsoft.Resources.ResourceActionSuccess": models.ResourceActionSuccessData, "Microsoft.Resources.ResourceActionFailure": models.ResourceActionFailureData, "Microsoft.Resources.ResourceActionCancel": models.ResourceActionCancelData, - "Microsoft.ServiceBus.ActiveMessagesAvailableWithNoListeners": models.ServiceBusActiveMessagesAvailableWithNoListenersEventData, - "Microsoft.ServiceBus.DeadletterMessagesAvailableWithNoListener": models.ServiceBusDeadletterMessagesAvailableWithNoListenersEventData, + "Microsoft.ServiceBus.ActiveMessagesAvailableWithNoListeners": + models.ServiceBusActiveMessagesAvailableWithNoListenersEventData, + "Microsoft.ServiceBus.DeadletterMessagesAvailableWithNoListener": + models.ServiceBusDeadletterMessagesAvailableWithNoListenersEventData, "Microsoft.Storage.BlobCreated": models.StorageBlobCreatedEventData, "Microsoft.Storage.BlobDeleted": models.StorageBlobDeletedEventData, "Microsoft.Storage.BlobRenamed": models.StorageBlobRenamedEventData, @@ -82,4 +86,4 @@ "Microsoft.Web.SlotSwapWithPreviewStarted": models.WebSlotSwapWithPreviewStartedEventData, "Microsoft.Web.SlotSwapWithPreviewCancelled": models.WebSlotSwapWithPreviewCancelledEventData, "Microsoft.Web.AppServicePlanUpdated": models.WebAppServicePlanUpdatedEventData, -} \ No newline at end of file +} diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py index 9443f7e3f698..2bd67abd56e3 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py @@ -1,3 +1,7 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- import hashlib import hmac import base64 @@ -5,14 +9,12 @@ from urllib.parse import quote except ImportError: from urllib2 import quote # type: ignore -import datetime from azure.core.pipeline.policies import AzureKeyCredentialPolicy from azure.core.credentials import AzureKeyCredential from ._shared_access_signature_credential import EventGridSharedAccessSignatureCredential from ._signature_credential_policy import EventGridSharedAccessSignatureCredentialPolicy from . import _constants as constants -from ._event_mappings import _event_mappings def generate_shared_access_signature(topic_hostname, shared_access_key, expiration_date_utc, **kwargs): # type: (str, str, datetime.Datetime, Any) -> str @@ -21,13 +23,17 @@ def generate_shared_access_signature(topic_hostname, shared_access_key, expirati Similar to .-1.eventgrid.azure.net :param str shared_access_key: The shared access key to be used for generating the token :param datetime.datetime expiration_date_utc: The expiration datetime in UTC for the signature. - :param str api_version: The API Version to include in the signature. If not provided, the default API version will be used. + :param str api_version: The API Version to include in the signature. + If not provided, the default API version will be used. :rtype: str """ full_topic_hostname = _get_full_topic_hostname(topic_hostname) - full_topic_hostname = "{}?apiVersion={}".format(full_topic_hostname, kwargs.get('api_version', None) or constants.DEFAULT_API_VERSION) + full_topic_hostname = "{}?apiVersion={}".format( + full_topic_hostname, + kwargs.get('api_version', None) or constants.DEFAULT_API_VERSION + ) encoded_resource = quote(full_topic_hostname, safe=constants.SAFE_ENCODE) encoded_expiration_utc = quote(str(expiration_date_utc), safe=constants.SAFE_ENCODE) @@ -43,7 +49,7 @@ def _get_topic_hostname_only_fqdn(topic_hostname): topic_hostname = topic_hostname.replace("https://", "") if topic_hostname.endswith("/api/events"): topic_hostname = topic_hostname.replace("/api/events", "") - + return topic_hostname def _get_full_topic_hostname(topic_hostname): @@ -53,7 +59,7 @@ def _get_full_topic_hostname(topic_hostname): topic_hostname = "https://{}".format(topic_hostname) if not topic_hostname.endswith("/api/events"): topic_hostname = "{}/api/events".format(topic_hostname) - + return topic_hostname def _generate_hmac(key, message): @@ -69,7 +75,10 @@ def _get_authentication_policy(credential): if isinstance(credential, AzureKeyCredential): authentication_policy = AzureKeyCredentialPolicy(credential=credential, name=constants.EVENTGRID_KEY_HEADER) if isinstance(credential, EventGridSharedAccessSignatureCredential): - authentication_policy = EventGridSharedAccessSignatureCredentialPolicy(credential=credential, name=constants.EVENTGRID_TOKEN_HEADER) + authentication_policy = EventGridSharedAccessSignatureCredentialPolicy( + credential=credential, + name=constants.EVENTGRID_TOKEN_HEADER + ) return authentication_policy def _is_cloud_event(event): diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py index 43d3624e672e..a304f488fa51 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py @@ -3,16 +3,12 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- # pylint:disable=protected-access -from typing import Optional -from msrest.serialization import UTC import datetime as dt import uuid import json import six -from ._generated import models -from ._generated.models import StorageBlobCreatedEventData, \ - EventGridEvent as InternalEventGridEvent, \ - CloudEvent as InternalCloudEvent +from msrest.serialization import UTC +from ._generated.models import EventGridEvent as InternalEventGridEvent, CloudEvent as InternalCloudEvent from ._shared.mixins import DictMixin from ._event_mappings import _event_mappings @@ -55,8 +51,8 @@ class CloudEvent(EventMixin): #pylint:disable=too-many-instance-attributes All required parameters must be populated in order to send to Azure. - :param source: Required. Identifies the context in which an event happened. The combination of id and source must be - unique for each distinct event. If publishing to a domain topic, source must be the domain name. + :param source: Required. Identifies the context in which an event happened. The combination of id and source must + be unique for each distinct event. If publishing to a domain topic, source must be the domain name. :type source: str :param data: Event data specific to the event type. :type data: object @@ -75,7 +71,7 @@ class CloudEvent(EventMixin): #pylint:disable=too-many-instance-attributes unique for each distinct event. :type id: Optional[str] """ - def __init__(self, source, type, **kwargs): + def __init__(self, source, type, **kwargs): # pylint: disable=redefined-builtin # type: (str, str, Any) -> None self.source = source self.type = type @@ -87,13 +83,13 @@ def __init__(self, source, type, **kwargs): self.dataschema = kwargs.pop("dataschema", None) self.subject = kwargs.pop("subject", None) self.extensions = {} - self.extensions.update({k:v for k, v in kwargs.pop('extensions', {}).items()}) + self.extensions.update(dict(kwargs.pop('extensions', {}))) @classmethod def _from_generated(cls, cloud_event, **kwargs): generated = InternalCloudEvent.deserialize(cloud_event) if generated.additional_properties: - extensions = {k:v for k, v in generated.additional_properties.items()} + extensions = dict(generated.additional_properties) kwargs.setdefault('extensions', extensions) return cls( id=generated.id, @@ -154,7 +150,8 @@ class EventGridEvent(InternalEventGridEvent, EventMixin): :param id: Optional. An identifier for the event. The combination of id and source must be unique for each distinct event. :type id: Optional[str] - :param event_time: Optional.The time (in UTC) of the event. If not provided, it will be the time (in UTC) the event was generated. + :param event_time: Optional.The time (in UTC) of the event. If not provided, + it will be the time (in UTC) the event was generated. :type event_time: Optional[~datetime.datetime] """ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py index 44b664ddc493..082f03891e78 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py @@ -5,11 +5,11 @@ # license information. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING, Sequence -import json +from typing import TYPE_CHECKING -from azure.core import PipelineClient -from msrest import Deserializer, Serializer +from ._models import CloudEvent, EventGridEvent, CustomEvent +from ._helpers import _get_topic_hostname_only_fqdn, _get_authentication_policy, _is_cloud_event +from ._generated._event_grid_publisher_client import EventGridPublisherClient as EventGridPublisherClientImpl if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -25,18 +25,14 @@ List[Dict] ] -from ._models import CloudEvent, EventGridEvent, CustomEvent -from ._helpers import _get_topic_hostname_only_fqdn, _get_authentication_policy, _is_cloud_event -from ._generated._event_grid_publisher_client import EventGridPublisherClient as EventGridPublisherClientImpl -from . import _constants as constants - class EventGridPublisherClient(object): """EventGrid Python Publisher Client. :param str topic_hostname: The topic endpoint to send the events to. - :param credential: The credential object used for authentication which implements SAS key authentication or SAS token authentication. - :type credential: Union[~azure.core.credentials.AzureKeyCredential, azure.eventgrid.EventGridSharedAccessSignatureCredential] + :param credential: The credential object used for authentication which + implements SAS key authentication or SAS token authentication. + :type credential: ~azure.core.credentials.AzureKeyCredential or EventGridSharedAccessSignatureCredential """ def __init__(self, topic_hostname, credential, **kwargs): @@ -54,7 +50,8 @@ def send(self, events, **kwargs): :param events: A list or an instance of CloudEvent/EventGridEvent/CustomEvent to be sent. :type events: SendType :keyword str content_type: The type of content to be used to send the events. - Has default value "application/json; charset=utf-8" for EventGridEvents, with "cloudevents-batch+json" for CloudEvents + Has default value "application/json; charset=utf-8" for EventGridEvents, + with "cloudevents-batch+json" for CloudEvents :rtype: None :raises: :class:`ValueError`, when events do not follow specified SendType. """ @@ -63,7 +60,7 @@ def send(self, events, **kwargs): if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): try: - events = [e._to_generated(**kwargs) for e in events] + events = [e._to_generated(**kwargs) for e in events] # pylint: disable=protected-access except AttributeError: pass # means it's a dictionary kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared/mixins.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared/mixins.py index 0b24e8edc45c..411fd236b681 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared/mixins.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared/mixins.py @@ -37,22 +37,22 @@ def __ne__(self, other): def __str__(self): return str({k: v for k, v in self.__dict__.items() if not k.startswith('_')}) - def has_key(self, k, **kwargs): + def has_key(self, k): return k in self.__dict__ def update(self, *args, **kwargs): return self.__dict__.update(*args, **kwargs) - def keys(self, **kwargs): + def keys(self): return [k for k in self.__dict__ if not k.startswith('_')] - def values(self, **kwargs): + def values(self): return [v for k, v in self.__dict__.items() if not k.startswith('_')] - def items(self, **kwargs): + def items(self): return [(k, v) for k, v in self.__dict__.items() if not k.startswith('_')] - def get(self, key, default=None, **kwargs): + def get(self, key, default=None): if key in self.__dict__: return self.__dict__[key] return default diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared_access_signature_credential.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared_access_signature_credential.py index dece8da69fe1..7c3a178c96eb 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared_access_signature_credential.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_shared_access_signature_credential.py @@ -22,7 +22,7 @@ def signature(self): :rtype: str """ return self._signature - + def update(self, signature): # type: (str) -> None """ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_signature_credential_policy.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_signature_credential_policy.py index 3370595d1d5d..3ae58fbf4a08 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_signature_credential_policy.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_signature_credential_policy.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE.txt in the project root for +# license information. +# ------------------------------------------------------------------------- + import six from azure.core.pipeline.policies import SansIOHTTPPolicy diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py index 0cfe1de4693f..786793525a26 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py @@ -7,20 +7,15 @@ # -------------------------------------------------------------------------- from typing import Any, TYPE_CHECKING - -from azure.core import AsyncPipelineClient -from msrest import Deserializer, Serializer +from azure.core.credentials import AzureKeyCredential from .._models import CloudEvent, EventGridEvent, CustomEvent from .._helpers import _get_topic_hostname_only_fqdn, _get_authentication_policy, _is_cloud_event -from azure.core.pipeline.policies import AzureKeyCredentialPolicy -from azure.core.credentials import AzureKeyCredential from .._generated.aio import EventGridPublisherClient as EventGridPublisherClientAsync -from .. import _constants as constants if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Union, Dict, List + from typing import Union, Dict, List SendType = Union[ CloudEvent, EventGridEvent, @@ -36,8 +31,9 @@ class EventGridPublisherClient(object): """Asynchronous EventGrid Python Publisher Client. :param str topic_hostname: The topic endpoint to send the events to. - :param credential: The credential object used for authentication which implements SAS key authentication or SAS token authentication. - :type credential: Union[~azure.core.credentials.AzureKeyCredential, azure.eventgrid.EventGridSharedAccessSignatureCredential] + :param credential: The credential object used for authentication which implements + SAS key authentication or SAS token authentication. + :type credential: ~azure.core.credentials.AzureKeyCredential or EventGridSharedAccessSignatureCredential """ def __init__(self, topic_hostname, credential, **kwargs): @@ -55,7 +51,8 @@ async def send(self, events, **kwargs): :param events: A list or an instance of CloudEvent/EventGridEvent/CustomEvent to be sent. :type events: SendType :keyword str content_type: The type of content to be used to send the events. - Has default value "application/json; charset=utf-8" for EventGridEvents, with "cloudevents-batch+json" for CloudEvents + Has default value "application/json; charset=utf-8" for EventGridEvents, + with "cloudevents-batch+json" for CloudEvents :rtype: None :raises: :class:`ValueError`, when events do not follow specified SendType. """ @@ -64,7 +61,7 @@ async def send(self, events, **kwargs): if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): try: - events = [e._to_generated(**kwargs) for e in events] + events = [e._to_generated(**kwargs) for e in events] # pylint: disable=protected-access except AttributeError: pass # means it's a dictionary kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") @@ -77,4 +74,3 @@ async def send(self, events, **kwargs): await self._client.publish_custom_event_events(self._topic_hostname, serialized_events, **kwargs) else: raise ValueError("Event schema is not correct.") - diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer.py index 344f5dd70634..450910d936a8 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer.py @@ -13,7 +13,8 @@ from devtools_testutils import AzureMgmtTestCase from msrest.serialization import UTC -from azure.eventgrid import EventGridConsumer, CloudEvent, EventGridEvent, StorageBlobCreatedEventData +from azure.eventgrid import EventGridConsumer, CloudEvent, EventGridEvent +from azure.eventgrid.models import StorageBlobCreatedEventData from _mocks import ( cloud_storage_dict, cloud_storage_string,