Skip to content

Commit

Permalink
[EGv2] generate with newer emitter (#31962)
Browse files Browse the repository at this point in the history
* [EGv2] Build Release (#30325)

* move old sdk under legacy

* gen typespec code

* naming changes from archboard

* samples

* update patch naming

* update imports with new gen

* update samples

* update client naming on aio

* update receive op

* update async to close client

* update receive()

* update gen code

* moving around samples

* updating samples

* update samples

* update patch and samples

* patch internalmodels

* spacing

* updating model patch

* update patch models

* add both models back

* update docstring

* update docs

* updating patch for receive

* old EG models

* add reject samples

* patch

* update format

* update patch

* eventgrid_client exceptions

* update test imports

* update total sample

* receive patch fix

* add in more tests

* update test file

* remove locktoken model

* remove LockToken in patch

* remove event delivery delay

* eg client exceptions

* .8.5 generation, and deliveryCount

* rename sample

* update version for beta

* changelog

* updating for gen

* regen

* generate via commit

* publish result

* fix docstring

* publish docstring

* return type

* publish result

* return publish result -- is none

* format

* update Publish result model

* deliverycount patch

* update from main

* add copyright

* added to readme

* remove from readme

* force publish_result response

* update patch tp unindent

* cspell

* update mypy.ini

* import order

* mark livetest

* update operations init

* rename async

* mypy

* ignore mypy

* pylint

* pylint

* ignore pylint for now to avoid gen code errors

* ignore samples until ARM setup

* update patches

* remove publish result

* remove PublishResult

* remove publishresult

* comma

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update publishResult

* change to .value

* gen code " to '

* remove comment

* ran black

* update changelog

* update sample readme

* gen code without query name

* gen code

* update tsp commit

* remove publishresult

* readme disclaimer

* update changelog

---------

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* generate with newer emitter

* update tsp

* regen

* update tests

* update tspconfig

* cspell

* version

* update serialization

* update assets

* update mypy

---------

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
  • Loading branch information
l0lawrence and swathipil committed Apr 22, 2024
1 parent 1ef26b9 commit efdc1b7
Show file tree
Hide file tree
Showing 32 changed files with 1,243 additions and 445 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
"mibps",
"mgmt",
"mhsm",
"Nify",
"mipsle",
"mktime",
"mlindex",
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/eventgrid/azure-eventgrid",
"Tag": "python/eventgrid/azure-eventgrid_6f56978914"
"Tag": "python/eventgrid/azure-eventgrid_fce4958e09"
}
14 changes: 10 additions & 4 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# --------------------------------------------------------------------------

from copy import deepcopy
from typing import Any
from typing import Any, TYPE_CHECKING, Union

from azure.core import PipelineClient
from azure.core.credentials import AzureKeyCredential
Expand All @@ -17,14 +17,20 @@
from ._operations import EventGridClientOperationsMixin
from ._serialization import Deserializer, Serializer

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential

class EventGridClient(EventGridClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
"""Azure Messaging EventGrid Client.
:param endpoint: The host name of the namespace, e.g.
namespaceName1.westus-1.eventgrid.azure.net. Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:param credential: Credential needed for the client to connect to Azure. Is either a
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2023-06-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand All @@ -34,7 +40,7 @@ class EventGridClient(EventGridClientOperationsMixin): # pylint: disable=client
def __init__(
self,
endpoint: str,
credential: AzureKeyCredential,
credential: Union[AzureKeyCredential, "TokenCredential"],
**kwargs: Any
) -> None:
_endpoint = '{endpoint}'
Expand Down
27 changes: 21 additions & 6 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any
from typing import Any, TYPE_CHECKING, Union

from azure.core.configuration import Configuration
from azure.core.credentials import AzureKeyCredential
from azure.core.pipeline import policies

from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential

class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes

class EventGridClientConfiguration( # pylint: disable=too-many-instance-attributes,name-too-long
Configuration
):
"""Configuration for EventGridClient.
Note that all parameters used to create this instance are saved as instance
Expand All @@ -24,8 +30,10 @@ class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-i
:param endpoint: The host name of the namespace, e.g.
namespaceName1.westus-1.eventgrid.azure.net. Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential
:param credential: Credential needed for the client to connect to Azure. Is either a
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: The API version to use for this operation. Default value is
"2023-06-01-preview". Note that overriding this default value may result in unsupported
behavior.
Expand All @@ -35,7 +43,7 @@ class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-i
def __init__(
self,
endpoint: str,
credential: AzureKeyCredential,
credential: Union[AzureKeyCredential, "TokenCredential"],
**kwargs: Any
) -> None:
super(EventGridClientConfiguration, self).__init__(**kwargs)
Expand All @@ -49,9 +57,16 @@ def __init__(
self.endpoint = endpoint
self.credential = credential
self.api_version = api_version
self.credential_scopes = kwargs.pop('credential_scopes', ['https://eventgrid.azure.net/.default'])
kwargs.setdefault('sdk_moniker', 'eventgrid/{}'.format(VERSION))
self._configure(**kwargs)

def _infer_policy(self, **kwargs):
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "Authorization", prefix="SharedAccessKey", **kwargs)
if hasattr(self.credential, 'get_token'):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")

def _configure(
self,
Expand All @@ -67,4 +82,4 @@ def _configure(
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get('authentication_policy')
if self.credential and not self.authentication_policy:
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "SharedAccessKey", **kwargs)
self.authentication_policy = self._infer_policy(**kwargs)
Loading

0 comments on commit efdc1b7

Please sign in to comment.