Skip to content

Commit

Permalink
Merge from upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
KieranBrantnerMagee committed Sep 8, 2020
2 parents 8d16d19 + 3458fb9 commit eff3ee2
Show file tree
Hide file tree
Showing 59 changed files with 424 additions and 323 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/sdk/identity/ @chlowell @schaabs

# PRLabel: %Event Hubs
/sdk/eventhub/ @annatisch @yunhaoling @YijunXieMS
/sdk/eventhub/ @annatisch @yunhaoling @KieranBrantnerMagee

# PRLabel: %Storage
/sdk/storage/ @amishra-dev @zezha-msft @annatisch @rakshith91 @xiafu-msft @tasherif-msft @kasobol-msft
Expand Down Expand Up @@ -56,7 +56,7 @@
/sdk/datadatamigration/ @vchske

# PRLabel: %Event Grid
/sdk/eventgrid/ @kalyanaj
/sdk/eventgrid/ @lmazuel @rakshith91 @KieranBrantnerMagee

# PRLabel: %HDInsight
/sdk/hdinsight/ @idear1203
Expand All @@ -77,7 +77,7 @@
/sql/sql/ @jaredmoo

# PRLabel: %Service Bus
/sdk/servicebus/ @annatisch @yunhaoling @YijunXieMS @KieranBrantnerMagee
/sdk/servicebus/ @annatisch @yunhaoling @KieranBrantnerMagee

# PRLabel: %Synapse
/sdk/synapse/ @aim-for-better @idear1203
Expand Down
1 change: 0 additions & 1 deletion eng/tox/allowed_pylint_failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"azure-common",
"azure-nspkg",
"azure-servicemanagement-legacy",
"azure-eventgrid",
"azure-graphrbac",
"azure-loganalytics",
"azure-servicefabric",
Expand Down
3 changes: 3 additions & 0 deletions sdk/appconfiguration/azure-appconfiguration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

-------------------

## 1.1.1 (Unreleased)


## 1.1.0 (2020-09-08)

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "1.1.0"
VERSION = "1.1.1"
3 changes: 3 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Release History

## 1.8.2 (Unreleased)


## 1.8.1 (2020-09-08)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# regenerated.
# --------------------------------------------------------------------------

VERSION = "1.8.1"
VERSION = "1.8.2"
1 change: 1 addition & 0 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features**
- Version (2.0.0b1) is the first preview of our efforts to create a user-friendly and Pythonic client library for Azure EventGrid.
For more information about this, and preview releases of other Azure SDK libraries, please visit https://azure.github.io/azure-sdk/releases/latest/python.html.
- Added Support for `CloudEvents`.
- Implements the `EventGridPublisherClient` for the publish flow for EventGrid Events, CloudEvents and CustomEvents.
- Implements the `EventGridConsumer` for the consume flow of the events.

Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
6 changes: 3 additions & 3 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 21 additions & 22 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@
# --------------------------------------------------------------------------

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
from typing import Any

_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.
Expand All @@ -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.
Expand All @@ -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.')
14 changes: 9 additions & 5 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -82,4 +86,4 @@
"Microsoft.Web.SlotSwapWithPreviewStarted": models.WebSlotSwapWithPreviewStartedEventData,
"Microsoft.Web.SlotSwapWithPreviewCancelled": models.WebSlotSwapWithPreviewCancelledEventData,
"Microsoft.Web.AppServicePlanUpdated": models.WebAppServicePlanUpdatedEventData,
}
}
23 changes: 16 additions & 7 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# --------------------------------------------------------------------------------------------
# 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
try:
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
Expand All @@ -21,13 +23,17 @@ def generate_shared_access_signature(topic_hostname, shared_access_key, expirati
Similar to <YOUR-TOPIC-NAME>.<YOUR-REGION-NAME>-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)

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
21 changes: 9 additions & 12 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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]
"""

Expand Down
Loading

0 comments on commit eff3ee2

Please sign in to comment.