Skip to content

Commit

Permalink
[EG] Beta One Client (#34973)
Browse files Browse the repository at this point in the history
* [EG] dont hardcode api_version on request (#34965)

* dont hardcode api_version on request

* pylint fixes

* revert

* api version

* Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py

* Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py

* add sync side patches

* aio patches

* update readme samples

* all samples use EGClient

* update readme samples

* fix imports

* import issue

* missing pathc

* allow sas cred

* typo

* updates

* sas

* client

* self serialize cloudevent

* add bakc in

* updates

* update ptach

* update

* update exception logic

* async w client

* aio [atch

* typo

* import

* update links

* tests

* raise error

* content type

* use more fake url

* remove content type

* mypy

* update apiversion

* content type

* unitttests

* update auth

* updates

* add level

* update readme

* update

* binary mode

* args, kwargs

* remove auth

* add sample comments

* testing

* move around readme

* content type

* update tests

* docstring

* cncf event

* add more tests

* update doc

* update inits to prevent typing errors

* ran blakc

* fix pylint patch

* changes

* add all kwargs

* indent

* reviews

* nit

* name changes

* options

* options/result rename

* Revert "options"

This reverts commit fe0623a.

* Revert "options/result rename"

This reverts commit 6d37422.

* fix tests

* remove or None

* remove EGPubClient

* remove options naming

* Revert "remove EGPubClient"

This reverts commit bf94364.

* typeerror

* update readme

* readme nit

* readme updates

* add send operation samples

* add datacontenttpye

* typo

* make Options bag models kwargs

* remove models

* import

* exception

* update changelog

* shorten operation names

* nit
  • Loading branch information
l0lawrence authored Apr 8, 2024
1 parent aa0e1cd commit cd8cf6a
Show file tree
Hide file tree
Showing 72 changed files with 2,540 additions and 2,670 deletions.
9 changes: 6 additions & 3 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

### Features Added

### Breaking Changes
- This is a Beta of the EventGridClient
- EventGridClient `send` can be used for both Event Grid Namespace Resources and Event Grid Basic Resources.
- Added a kwarg `level` in the EventGridClient constructor. The default value is `Standard` which creates a client for an Event Grid Namespace Resource.

### Bugs Fixed
### Breaking Changes
- Removed the `AcknowledgeOptions`,`ReleaseOptions`, `RejectOptions`, and `RenewLockOptions` models. `lock_tokens` can now be specified as a `kwarg` on the operation.
- Renamed `publish_cloud_events` to `send`, `receive_cloud_events` to `receive`, `release_cloud_events` to `release`, `acknowledge_cloud_events` to `acknowledge`, `reject_cloud_events` to `reject`, and `renew_cloud_event_locks` to `renew_locks`.

### Other Changes

## 4.18.0 (2024-03-12)

Expand Down
324 changes: 190 additions & 134 deletions sdk/eventgrid/azure-eventgrid/README.md

Large diffs are not rendered by default.

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__) # type: ignore
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._client import EventGridClient
from ._patch import EventGridClient
from ._version import VERSION

__version__ = VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _from_cncf_events(event): # pylint: disable=inconsistent-return-statements
raise ValueError(msg) from err


def _build_request(endpoint, content_type, events, *, channel_name=None):
def _build_request(endpoint, content_type, events, *, channel_name=None, api_version=constants.DEFAULT_API_VERSION):
serialize = Serializer()
header_parameters: Dict[str, Any] = {}
header_parameters['Content-Type'] = serialize.header("content_type", content_type, 'str')
Expand All @@ -181,7 +181,7 @@ def _build_request(endpoint, content_type, events, *, channel_name=None):
header_parameters["aeg-channel-name"] = channel_name

query_parameters: Dict[str, Any] = {}
query_parameters['api-version'] = serialize.query("api_version", "2018-01-01", 'str')
query_parameters['api-version'] = serialize.query("api_version", api_version, 'str')

body = serialize.body(events, "[object]")
if body is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
EventGridPublisherClient as EventGridPublisherClientImpl,
)
from ._policies import CloudEventDistributedTracingPolicy
from ._constants import DEFAULT_API_VERSION
from ._version import VERSION

if TYPE_CHECKING:
Expand Down Expand Up @@ -81,6 +82,9 @@ class EventGridPublisherClient(
implements SAS key authentication or SAS token authentication or a TokenCredential.
:type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.AzureSasCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: Api Version. Will default to the most recent Api Version. Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
:rtype: None
.. admonition:: Example:
Expand All @@ -100,12 +104,19 @@ class EventGridPublisherClient(
:caption: Creating the EventGridPublisherClient with an endpoint and AzureSasCredential.
"""

def __init__(self, endpoint, credential, **kwargs):
# type: (str, Union[AzureKeyCredential, AzureSasCredential, TokenCredential], Any) -> None
def __init__(
self,
endpoint: str,
credential: Union["AzureKeyCredential", "AzureSasCredential", "TokenCredential"],
*,
api_version: Optional[str] = None,
**kwargs: Any
) -> None:
self._endpoint = endpoint
self._client = EventGridPublisherClientImpl(
policies=EventGridPublisherClient._policies(credential, **kwargs), **kwargs
)
self._api_version = api_version if api_version is not None else DEFAULT_API_VERSION

@staticmethod
def _policies(credential, **kwargs):
Expand Down Expand Up @@ -217,9 +228,8 @@ def send(
_eventgrid_data_typecheck(event)
response = self._client.send_request( # pylint: disable=protected-access
_build_request(
self._endpoint, content_type, events, channel_name=channel_name
),
**kwargs
self._endpoint,content_type, events, channel_name=channel_name, api_version=self._api_version),
**kwargs
)
error_map = {
401: ClientAuthenticationError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
_get_authentication_policy,
_from_cncf_events,
)
from .._constants import DEFAULT_API_VERSION
from .._generated.aio import EventGridPublisherClient as EventGridPublisherClientAsync
from .._version import VERSION

Expand Down Expand Up @@ -73,6 +74,9 @@ class EventGridPublisherClient: # pylint: disable=client-accepts-api-version-ke
SAS key authentication or SAS token authentication or an AsyncTokenCredential.
:type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.AzureSasCredential or
~azure.core.credentials_async.AsyncTokenCredential
:keyword api_version: Api Version. Will default to the most recent Api Version. Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
:rtype: None
.. admonition:: Example:
Expand All @@ -98,12 +102,15 @@ def __init__(
credential: Union[
"AsyncTokenCredential", AzureKeyCredential, AzureSasCredential
],
*,
api_version: Optional[str] = None,
**kwargs: Any
) -> None:
self._client = EventGridPublisherClientAsync(
policies=EventGridPublisherClient._policies(credential, **kwargs), **kwargs
)
self._endpoint = endpoint
self._api_version = api_version if api_version is not None else DEFAULT_API_VERSION

@staticmethod
def _policies(
Expand Down Expand Up @@ -220,9 +227,8 @@ async def send(
for event in events:
_eventgrid_data_typecheck(event)
response = await self._client.send_request( # pylint: disable=protected-access
_build_request(
self._endpoint, content_type, events, channel_name=channel_name
),
_build_request(self._endpoint, content_type, events,
channel_name=channel_name, api_version=self._api_version),
**kwargs
)
error_map = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._operations import EventGridClientOperationsMixin
from ._patch import EventGridClientOperationsMixin

from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
Expand Down
Loading

0 comments on commit cd8cf6a

Please sign in to comment.