Skip to content

Commit ee0293b

Browse files
authored
Event grid track 2 (#12768)
* genereated python client for event grid * updated readme to use track2 generator * added sas key auth sample * added consume sample, not final * removing old eg * added track 2 changes needed for api view * add consumer operations * cleanup client versions for api view * remove _initialize_mapping() in BaseEventType class in models * track 2 design manual changes * added publisher wrapper in azure/eventgrid for demo * modified naming for publish sample for demo * final sample fix for demo * added response to publish_events(), still need to fix * added decoder for apiview * renamed consumer, added Deserialized/CustomEvent * final for Board Review * testing changes * added EventGridSharedAccessSignatureCredential,Policy and modified samples * added eg_client test * moving generated code out from event_grid_publisher_client nested folder * added consumption function samples * removed eg required package and removed service bus dependency in consumer * removed unnecessary functions * changed consumer deserialize_event() to take,return single event of one type of (string, bytes string, dict). changed DeserializedEvent to have to_json() method, instead of extending DictMixin * added publish tests * fixed PR, added CustomEvent, added tests/samples * updated swagger, removed unnecessary imports * removed unnecessary reqs in dev_requirements * changed async publisher import path, added type hints * modified typehints for publishers, based on apiview * added newlines * added shared_reqs file * moved shared_requirement * fixed non live test * added changelog, test fix * changed topic preparer * added samples to exclude to setup.py
1 parent c78e49c commit ee0293b

File tree

242 files changed

+4390
-8625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+4390
-8625
lines changed

sdk/eventgrid/azure-eventgrid/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 2.0.0 (2020-08-07)
4+
5+
- Placeholder - NEEDS TO BE CHANGED
6+
37
## 1.3.0 (2019-05-20)
48

59
- Event Schemas for new event types from IotHub, Media Services,
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# coding=utf-8
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
4-
# Licensed under the MIT License. See License.txt in the project root for
5-
# license information.
6-
#
7-
# Code generated by Microsoft (R) AutoRest Code Generator.
8-
# Changes may cause incorrect behavior and will be lost if the code is
9-
# regenerated.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
105
# --------------------------------------------------------------------------
116

12-
from .event_grid_client import EventGridClient
13-
from .version import VERSION
14-
15-
__all__ = ['EventGridClient']
7+
from ._publisher_client import EventGridPublisherClient
8+
from ._consumer import EventGridConsumer
9+
from ._helpers import generate_shared_access_signature
10+
from ._models import CloudEvent, CustomEvent, EventGridEvent, DeserializedEvent, StorageBlobCreatedEventData
11+
from ._shared_access_signature_credential import EventGridSharedAccessSignatureCredential
12+
from ._version import VERSION
1613

14+
__all__ = ['EventGridPublisherClient', 'EventGridConsumer',
15+
'CloudEvent', 'CustomEvent', 'DeserializedEvent', 'EventGridEvent', 'StorageBlobCreatedEventData'
16+
'generate_shared_access_signature', 'EventGridSharedAccessSignatureCredential']
1717
__version__ = VERSION
18-
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
EVENTGRID_KEY_HEADER = 'aeg-sas-key'
7+
EVENTGRID_TOKEN_HEADER = 'aeg-sas-token'
8+
DEFAULT_API_VERSION = "2018-01-01"
9+
SAFE_ENCODE = '~()*!.\''
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
import json
11+
import six
12+
import logging
13+
14+
from azure.core import PipelineClient
15+
from msrest import Deserializer, Serializer
16+
17+
if TYPE_CHECKING:
18+
# pylint: disable=unused-import,ungrouped-imports
19+
from typing import Any
20+
21+
_LOGGER = logging.getLogger(__name__)
22+
23+
from ._models import DeserializedEvent
24+
25+
class EventGridConsumer(object):
26+
"""
27+
A consumer responsible for deserializing event handler messages, to allow for access to strongly typed Event objects.
28+
"""
29+
30+
def deserialize_event(self, event, **kwargs):
31+
# type: (Union[str, dict, bytes]) -> models.DeserializedEvent
32+
"""Single event following CloudEvent/EventGridEvent schema will be parsed and returned as DeserializedEvent.
33+
:param event: The event to be deserialized.
34+
:type event: Union[str, dict, bytes]
35+
:rtype: models.DeserializedEvent
36+
37+
:raise: :class:`ValueError`, when events do not follow CloudEvent or EventGridEvent schema.
38+
"""
39+
try:
40+
if isinstance(event, six.binary_type):
41+
event = json.loads(event.decode('utf-8'))
42+
elif isinstance(event, six.string_types):
43+
event = json.loads(event)
44+
return DeserializedEvent(event)
45+
except Exception as err:
46+
_LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent/EventGridEvent schema.')
47+
_LOGGER.error('Your event: {}'.format(event))
48+
_LOGGER.error(err)
49+
raise ValueError('Error: cannot deserialize event. Event does not have a valid format. Event must be a string, dict, or bytes following the CloudEvent/EventGridEvent schema.')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._event_grid_publisher_client import EventGridPublisherClient
10+
__all__ = ['EventGridPublisherClient']
11+
12+
try:
13+
from ._patch import patch_sdk
14+
patch_sdk()
15+
except ImportError:
16+
pass
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
14+
if TYPE_CHECKING:
15+
# pylint: disable=unused-import,ungrouped-imports
16+
from typing import Any
17+
18+
VERSION = "unknown"
19+
20+
class EventGridPublisherClientConfiguration(Configuration):
21+
"""Configuration for EventGridPublisherClient.
22+
23+
Note that all parameters used to create this instance are saved as instance
24+
attributes.
25+
26+
"""
27+
28+
def __init__(
29+
self,
30+
**kwargs # type: Any
31+
):
32+
# type: (...) -> None
33+
super(EventGridPublisherClientConfiguration, self).__init__(**kwargs)
34+
35+
self.api_version = "2018-01-01"
36+
kwargs.setdefault('sdk_moniker', 'eventgridpublisherclient/{}'.format(VERSION))
37+
self._configure(**kwargs)
38+
39+
def _configure(
40+
self,
41+
**kwargs # type: Any
42+
):
43+
# type: (...) -> None
44+
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
45+
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
46+
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
47+
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
48+
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
49+
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
50+
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
51+
self.authentication_policy = kwargs.get('authentication_policy')
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
11+
from azure.core import PipelineClient
12+
from msrest import Deserializer, Serializer
13+
14+
if TYPE_CHECKING:
15+
# pylint: disable=unused-import,ungrouped-imports
16+
from typing import Any
17+
18+
from ._configuration import EventGridPublisherClientConfiguration
19+
from .operations import EventGridPublisherClientOperationsMixin
20+
from . import models
21+
22+
23+
class EventGridPublisherClient(EventGridPublisherClientOperationsMixin):
24+
"""EventGrid Python Publisher Client.
25+
26+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
27+
"""
28+
29+
def __init__(
30+
self,
31+
**kwargs # type: Any
32+
):
33+
# type: (...) -> None
34+
base_url = 'https://{topicHostname}'
35+
self._config = EventGridPublisherClientConfiguration(**kwargs)
36+
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
37+
38+
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
39+
self._serialize = Serializer(client_models)
40+
self._deserialize = Deserializer(client_models)
41+
42+
43+
def close(self):
44+
# type: () -> None
45+
self._client.close()
46+
47+
def __enter__(self):
48+
# type: () -> EventGridPublisherClient
49+
self._client.__enter__()
50+
return self
51+
52+
def __exit__(self, *exc_details):
53+
# type: (Any) -> None
54+
self._client.__exit__(*exc_details)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._event_grid_publisher_client_async import EventGridPublisherClient
10+
__all__ = ['EventGridPublisherClient']
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import Any
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
14+
VERSION = "unknown"
15+
16+
class EventGridPublisherClientConfiguration(Configuration):
17+
"""Configuration for EventGridPublisherClient.
18+
19+
Note that all parameters used to create this instance are saved as instance
20+
attributes.
21+
22+
"""
23+
24+
def __init__(
25+
self,
26+
**kwargs: Any
27+
) -> None:
28+
super(EventGridPublisherClientConfiguration, self).__init__(**kwargs)
29+
30+
self.api_version = "2018-01-01"
31+
kwargs.setdefault('sdk_moniker', 'eventgridpublisherclient/{}'.format(VERSION))
32+
self._configure(**kwargs)
33+
34+
def _configure(
35+
self,
36+
**kwargs: Any
37+
) -> None:
38+
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
39+
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
40+
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
41+
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
42+
self.retry_policy = kwargs.get('retry_policy') or policies.AsyncRetryPolicy(**kwargs)
43+
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
44+
self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs)
45+
self.authentication_policy = kwargs.get('authentication_policy')
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import Any
10+
11+
from azure.core import AsyncPipelineClient
12+
from msrest import Deserializer, Serializer
13+
14+
from ._configuration_async import EventGridPublisherClientConfiguration
15+
from .operations_async import EventGridPublisherClientOperationsMixin
16+
from .. import models
17+
18+
19+
class EventGridPublisherClient(EventGridPublisherClientOperationsMixin):
20+
"""EventGrid Python Publisher Client.
21+
22+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
23+
"""
24+
25+
def __init__(
26+
self,
27+
**kwargs: Any
28+
) -> None:
29+
base_url = 'https://{topicHostname}'
30+
self._config = EventGridPublisherClientConfiguration(**kwargs)
31+
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
32+
33+
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
34+
self._serialize = Serializer(client_models)
35+
self._deserialize = Deserializer(client_models)
36+
37+
38+
async def close(self) -> None:
39+
await self._client.close()
40+
41+
async def __aenter__(self) -> "EventGridPublisherClient":
42+
await self._client.__aenter__()
43+
return self
44+
45+
async def __aexit__(self, *exc_details) -> None:
46+
await self._client.__aexit__(*exc_details)

0 commit comments

Comments
 (0)