Skip to content

Commit af30a10

Browse files
lmazuelt-swpillAutorestCIRakshith BhyravabhotlaKieranBrantnerMagee
authored
Event grid track 2 (#13010)
* 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 * Packaging update of azure-eventgrid * Fix Tests (#13024) * Fix Tests * other fixes * Packaging update of azure-eventgrid * tests fix (#13026) * other fixes * p2 compat * Packaging update of azure-eventgrid * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Event grid v2 (#13051) * other fixes * auto update * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_version.py * Event grid v2 (#13177) * other fixes * auto update * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_version.py * comments * Update sdk/eventgrid/azure-eventgrid/tests/_mocks.py * Event grid v2 (#13201) * other fixes * auto update * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_version.py * comments * tests fix * Update sdk/eventgrid/azure-eventgrid/tests/eventgrid_preparer.py * Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py Co-authored-by: KieranBrantnerMagee <[email protected]> * Apply suggestions from code review Co-authored-by: t-swpill <[email protected]> Co-authored-by: Azure SDK Bot <[email protected]> Co-authored-by: Rakshith Bhyravabhotla <[email protected]> Co-authored-by: KieranBrantnerMagee <[email protected]>
1 parent 5a60fbf commit af30a10

File tree

246 files changed

+4432
-8626
lines changed

Some content is hidden

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

246 files changed

+4432
-8626
lines changed

sdk/eventgrid/azure-eventgrid/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 2.0.0b1 (Unreleased)
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,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
recursive-include tests *.py *.yaml
2+
recursive-include samples *.py
23
include *.md
34
include azure/__init__.py
45

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
## Microsoft Azure SDK for Python
1+
# Microsoft Azure SDK for Python
22

33
This is the Microsoft Azure Event Grid Client Library.
4+
This package has been tested with Python 2.7, 3.5, 3.6, 3.7 and 3.8.
5+
For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
46

5-
This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7.
67

7-
For a more complete set of Azure libraries, see the
8-
[azure sdk python release](https://aka.ms/azsdk/python/all).
8+
# Usage
99

10-
## Usage
11-
12-
For code examples, see [Event
13-
Grid](https://docs.microsoft.com/python/api/overview/azure/event-grid)
10+
For code examples, see [Event Grid](https://docs.microsoft.com/python/api/overview/azure/event-grid)
1411
on docs.microsoft.com.
1512

16-
## Provide Feedback
1713

18-
If you encounter any bugs or have suggestions, please file an issue in
19-
the [Issues](https://github.com/Azure/azure-sdk-for-python/issues)
14+
# Provide Feedback
15+
16+
If you encounter any bugs or have suggestions, please file an issue in the
17+
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
2018
section of the project.
2119

22-
![image](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-eventgrid%2FREADME.png)
20+
21+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-eventgrid%2FREADME.png)
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-
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 = '~()*!.\''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
encode = kwargs.pop('encoding', 'utf-8')
40+
try:
41+
if isinstance(event, six.binary_type):
42+
event = json.loads(event.decode(encode))
43+
elif isinstance(event, six.string_types):
44+
event = json.loads(event)
45+
return DeserializedEvent(event)
46+
except Exception as err:
47+
_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.')
48+
_LOGGER.error('Your event: {}'.format(event))
49+
_LOGGER.error(err)
50+
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.')
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
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')
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)
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']
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')
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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_operations_async import EventGridPublisherClientOperationsMixin
10+
11+
__all__ = [
12+
'EventGridPublisherClientOperationsMixin',
13+
]

0 commit comments

Comments
 (0)