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

[EGv2] generate with newer emitter #31962

Merged
merged 12 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"mibps",
"mgmt",
"mhsm",
"Nify",
"mipsle",
"mktime",
"mros",
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