Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EG] dont hardcode api_version on request #34965

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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 @@ -175,7 +175,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 @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING, cast, Dict, List, Any, Union, Optional

from azure.core.credentials import AzureKeyCredential, AzureSasCredential
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline.policies import (
RequestIdPolicy,
Expand Down Expand Up @@ -49,8 +49,6 @@
if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import (
AzureKeyCredential,
AzureSasCredential,
TokenCredential,
kashifkhan marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down Expand Up @@ -79,6 +77,9 @@ class EventGridPublisherClient(object): # pylint: disable=client-accepts-api-ver
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. Default value is "2018-01-01". Note that overriding this
l0lawrence marked this conversation as resolved.
Show resolved Hide resolved
default value may result in unsupported behavior.
:paramtype api_version: str
:rtype: None

.. admonition:: Example:
Expand All @@ -98,12 +99,19 @@ class EventGridPublisherClient(object): # pylint: disable=client-accepts-api-ver
: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: str ="2018-01-01",
**kwargs: Any
) -> None:
self._endpoint = endpoint
self._client = EventGridPublisherClientImpl(
policies=EventGridPublisherClient._policies(credential, **kwargs), **kwargs
)
self._api_version = api_version

@staticmethod
def _policies(credential, **kwargs):
Expand Down Expand Up @@ -221,7 +229,9 @@ def send(
for event in events:
_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
_build_request(
self._endpoint,content_type, events, channel_name=channel_name, api_version=self._api_version),
**kwargs
)
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
if response.status_code != 200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class EventGridPublisherClient: # pylint: disable=client-accepts-api-version-key
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. Default value is "2018-01-01". Note that overriding this
l0lawrence marked this conversation as resolved.
Show resolved Hide resolved
default value may result in unsupported behavior.
:paramtype api_version: str
:rtype: None

.. admonition:: Example:
Expand All @@ -98,12 +101,15 @@ def __init__(
credential: Union[
"AsyncTokenCredential", AzureKeyCredential, AzureSasCredential
],
*,
api_version: str = "2018-01-01",
**kwargs: Any
) -> None:
self._client = EventGridPublisherClientAsync(
policies=EventGridPublisherClient._policies(credential, **kwargs), **kwargs
)
self._endpoint = endpoint
self._api_version = api_version

@staticmethod
def _policies(
Expand Down Expand Up @@ -221,7 +227,9 @@ async def send(self, events: SendType, *, channel_name: Optional[str] = None, **
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), **kwargs
_build_request(self._endpoint, content_type, events,
channel_name=channel_name, api_version=self._api_version),
**kwargs
)
error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError}
if response.status_code != 200:
Expand Down
Loading