Skip to content

Commit 80b6d30

Browse files
l0lawrenceswathipil
andcommitted
[EGv2] generate with newer emitter (#31962)
* [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 <[email protected]> * 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 <[email protected]> * generate with newer emitter * update tsp * regen * update tests * update tspconfig * cspell * version * update serialization * update assets * update mypy --------- Co-authored-by: swathipil <[email protected]>
1 parent 8e5f0dc commit 80b6d30

32 files changed

+1243
-445
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
"mibps",
298298
"mgmt",
299299
"mhsm",
300+
"Nify",
300301
"mipsle",
301302
"mktime",
302303
"mlindex",

sdk/eventgrid/azure-eventgrid/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/eventgrid/azure-eventgrid",
5-
"Tag": "python/eventgrid/azure-eventgrid_6f56978914"
5+
"Tag": "python/eventgrid/azure-eventgrid_fce4958e09"
66
}

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# --------------------------------------------------------------------------
88

99
from copy import deepcopy
10-
from typing import Any
10+
from typing import Any, TYPE_CHECKING, Union
1111

1212
from azure.core import PipelineClient
1313
from azure.core.credentials import AzureKeyCredential
@@ -17,14 +17,20 @@
1717
from ._operations import EventGridClientOperationsMixin
1818
from ._serialization import Deserializer, Serializer
1919

20+
if TYPE_CHECKING:
21+
# pylint: disable=unused-import,ungrouped-imports
22+
from azure.core.credentials import TokenCredential
23+
2024
class EventGridClient(EventGridClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
2125
"""Azure Messaging EventGrid Client.
2226
2327
:param endpoint: The host name of the namespace, e.g.
2428
namespaceName1.westus-1.eventgrid.azure.net. Required.
2529
:type endpoint: str
26-
:param credential: Credential needed for the client to connect to Azure. Required.
27-
:type credential: ~azure.core.credentials.AzureKeyCredential
30+
:param credential: Credential needed for the client to connect to Azure. Is either a
31+
AzureKeyCredential type or a TokenCredential type. Required.
32+
:type credential: ~azure.core.credentials.AzureKeyCredential or
33+
~azure.core.credentials.TokenCredential
2834
:keyword api_version: The API version to use for this operation. Default value is
2935
"2023-06-01-preview". Note that overriding this default value may result in unsupported
3036
behavior.
@@ -34,7 +40,7 @@ class EventGridClient(EventGridClientOperationsMixin): # pylint: disable=client
3440
def __init__(
3541
self,
3642
endpoint: str,
37-
credential: AzureKeyCredential,
43+
credential: Union[AzureKeyCredential, "TokenCredential"],
3844
**kwargs: Any
3945
) -> None:
4046
_endpoint = '{endpoint}'

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_configuration.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from typing import Any
9+
from typing import Any, TYPE_CHECKING, Union
1010

1111
from azure.core.configuration import Configuration
1212
from azure.core.credentials import AzureKeyCredential
1313
from azure.core.pipeline import policies
1414

1515
from ._version import VERSION
1616

17+
if TYPE_CHECKING:
18+
# pylint: disable=unused-import,ungrouped-imports
19+
from azure.core.credentials import TokenCredential
1720

18-
class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
21+
22+
class EventGridClientConfiguration( # pylint: disable=too-many-instance-attributes,name-too-long
23+
Configuration
24+
):
1925
"""Configuration for EventGridClient.
2026
2127
Note that all parameters used to create this instance are saved as instance
@@ -24,8 +30,10 @@ class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-i
2430
:param endpoint: The host name of the namespace, e.g.
2531
namespaceName1.westus-1.eventgrid.azure.net. Required.
2632
:type endpoint: str
27-
:param credential: Credential needed for the client to connect to Azure. Required.
28-
:type credential: ~azure.core.credentials.AzureKeyCredential
33+
:param credential: Credential needed for the client to connect to Azure. Is either a
34+
AzureKeyCredential type or a TokenCredential type. Required.
35+
:type credential: ~azure.core.credentials.AzureKeyCredential or
36+
~azure.core.credentials.TokenCredential
2937
:keyword api_version: The API version to use for this operation. Default value is
3038
"2023-06-01-preview". Note that overriding this default value may result in unsupported
3139
behavior.
@@ -35,7 +43,7 @@ class EventGridClientConfiguration(Configuration): # pylint: disable=too-many-i
3543
def __init__(
3644
self,
3745
endpoint: str,
38-
credential: AzureKeyCredential,
46+
credential: Union[AzureKeyCredential, "TokenCredential"],
3947
**kwargs: Any
4048
) -> None:
4149
super(EventGridClientConfiguration, self).__init__(**kwargs)
@@ -49,9 +57,16 @@ def __init__(
4957
self.endpoint = endpoint
5058
self.credential = credential
5159
self.api_version = api_version
60+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://eventgrid.azure.net/.default'])
5261
kwargs.setdefault('sdk_moniker', 'eventgrid/{}'.format(VERSION))
5362
self._configure(**kwargs)
5463

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

5671
def _configure(
5772
self,
@@ -67,4 +82,4 @@ def _configure(
6782
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
6883
self.authentication_policy = kwargs.get('authentication_policy')
6984
if self.credential and not self.authentication_policy:
70-
self.authentication_policy = policies.AzureKeyCredentialPolicy(self.credential, "SharedAccessKey", **kwargs)
85+
self.authentication_policy = self._infer_policy(**kwargs)

0 commit comments

Comments
 (0)