From a5a1db14d58338a00d94e61031436015d210bf94 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Fri, 17 Jul 2020 08:48:24 -0700 Subject: [PATCH] Sequence -> Iterable for scopes (#12579) --- .../identity/_credentials/authorization_code.py | 4 ++-- .../azure-identity/azure/identity/_exceptions.py | 6 +++--- .../azure/identity/_internal/aad_client.py | 10 +++++----- .../azure/identity/_internal/aad_client_base.py | 14 +++++++------- .../azure/identity/_internal/msal_credentials.py | 2 +- .../azure/identity/_internal/shared_token_cache.py | 4 ++-- .../aio/_credentials/authorization_code.py | 4 ++-- .../azure/identity/aio/_internal/aad_client.py | 10 +++++----- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/authorization_code.py b/sdk/identity/azure-identity/azure/identity/_credentials/authorization_code.py index 3568f8c921ce..6c74af19a0e9 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/authorization_code.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/authorization_code.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Optional, Sequence + from typing import Any, Iterable, Optional from azure.core.credentials import AccessToken @@ -73,7 +73,7 @@ def get_token(self, *scopes, **kwargs): return token def _redeem_refresh_token(self, scopes, **kwargs): - # type: (Sequence[str], **Any) -> Optional[AccessToken] + # type: (Iterable[str], **Any) -> Optional[AccessToken] for refresh_token in self._client.get_cached_refresh_tokens(scopes): if "secret" not in refresh_token: continue diff --git a/sdk/identity/azure-identity/azure/identity/_exceptions.py b/sdk/identity/azure-identity/azure/identity/_exceptions.py index ef1199fdf3b9..1012b2ab6667 100644 --- a/sdk/identity/azure-identity/azure/identity/_exceptions.py +++ b/sdk/identity/azure-identity/azure/identity/_exceptions.py @@ -7,7 +7,7 @@ from azure.core.exceptions import ClientAuthenticationError if TYPE_CHECKING: - from typing import Any, Optional, Sequence + from typing import Any, Iterable, Optional class CredentialUnavailableError(ClientAuthenticationError): @@ -18,7 +18,7 @@ class AuthenticationRequiredError(CredentialUnavailableError): """Interactive authentication is required to acquire a token.""" def __init__(self, scopes, message=None, error_details=None, **kwargs): - # type: (Sequence[str], Optional[str], Optional[str], **Any) -> None + # type: (Iterable[str], Optional[str], Optional[str], **Any) -> None self._scopes = scopes self._error_details = error_details if not message: @@ -27,7 +27,7 @@ def __init__(self, scopes, message=None, error_details=None, **kwargs): @property def scopes(self): - # type: () -> Sequence[str] + # type: () -> Iterable[str] """Scopes requested during the failed authentication""" return self._scopes diff --git a/sdk/identity/azure-identity/azure/identity/_internal/aad_client.py b/sdk/identity/azure-identity/azure/identity/_internal/aad_client.py index ab25736a9407..5681b930e194 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/aad_client.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/aad_client.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, List, Optional, Sequence, Union + from typing import Any, Iterable, List, Optional, Union from azure.core.credentials import AccessToken from azure.core.pipeline.policies import HTTPPolicy, SansIOHTTPPolicy from azure.core.pipeline.transport import HttpTransport @@ -32,7 +32,7 @@ class AadClient(AadClientBase): def obtain_token_by_authorization_code(self, scopes, code, redirect_uri, client_secret=None, **kwargs): - # type: (Sequence[str], str, str, Optional[str], **Any) -> AccessToken + # type: (Iterable[str], str, str, Optional[str], **Any) -> AccessToken request = self._get_auth_code_request( scopes=scopes, code=code, redirect_uri=redirect_uri, client_secret=client_secret ) @@ -41,21 +41,21 @@ def obtain_token_by_authorization_code(self, scopes, code, redirect_uri, client_ return self._process_response(response, now) def obtain_token_by_client_certificate(self, scopes, certificate, **kwargs): - # type: (Sequence[str], AadClientCertificate, **Any) -> AccessToken + # type: (Iterable[str], AadClientCertificate, **Any) -> AccessToken request = self._get_client_certificate_request(scopes, certificate) now = int(time.time()) response = self._pipeline.run(request, stream=False, **kwargs) return self._process_response(response, now) def obtain_token_by_client_secret(self, scopes, secret, **kwargs): - # type: (Sequence[str], str, **Any) -> AccessToken + # type: (Iterable[str], str, **Any) -> AccessToken request = self._get_client_secret_request(scopes, secret) now = int(time.time()) response = self._pipeline.run(request, stream=False, **kwargs) return self._process_response(response, now) def obtain_token_by_refresh_token(self, scopes, refresh_token, **kwargs): - # type: (Sequence[str], str, **Any) -> AccessToken + # type: (Iterable[str], str, **Any) -> AccessToken request = self._get_refresh_token_request(scopes, refresh_token) now = int(time.time()) response = self._pipeline.run(request, stream=False, **kwargs) diff --git a/sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py b/sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py index e1af4f949626..c20880d8a460 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py @@ -29,7 +29,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Optional, Sequence, Union + from typing import Any, Iterable, List, Optional, Union from azure.core.pipeline import AsyncPipeline, Pipeline, PipelineResponse from azure.core.pipeline.policies import AsyncHTTPPolicy, HTTPPolicy, SansIOHTTPPolicy from azure.core.pipeline.transport import AsyncHttpTransport, HttpTransport @@ -50,7 +50,7 @@ def __init__(self, tenant_id, client_id, authority=None, cache=None, **kwargs): self._pipeline = self._build_pipeline(**kwargs) def get_cached_access_token(self, scopes, query=None): - # type: (Sequence[str], Optional[dict]) -> Optional[AccessToken] + # type: (Iterable[str], Optional[dict]) -> Optional[AccessToken] tokens = self._cache.find(TokenCache.CredentialType.ACCESS_TOKEN, target=list(scopes), query=query) for token in tokens: expires_on = int(token["expires_on"]) @@ -59,7 +59,7 @@ def get_cached_access_token(self, scopes, query=None): return None def get_cached_refresh_tokens(self, scopes): - # type: (Sequence[str]) -> Sequence[dict] + # type: (Iterable[str]) -> List[dict] """Assumes all cached refresh tokens belong to the same user""" return self._cache.find(TokenCache.CredentialType.REFRESH_TOKEN, target=list(scopes)) @@ -136,7 +136,7 @@ def _process_response(self, response, request_time): return token def _get_auth_code_request(self, scopes, code, redirect_uri, client_secret=None): - # type: (Sequence[str], str, str, Optional[str]) -> HttpRequest + # type: (Iterable[str], str, str, Optional[str]) -> HttpRequest data = { "client_id": self._client_id, "code": code, @@ -153,7 +153,7 @@ def _get_auth_code_request(self, scopes, code, redirect_uri, client_secret=None) return request def _get_client_certificate_request(self, scopes, certificate): - # type: (Sequence[str], AadClientCertificate) -> HttpRequest + # type: (Iterable[str], AadClientCertificate) -> HttpRequest assertion = self._get_jwt_assertion(certificate) data = { "client_assertion": assertion, @@ -169,7 +169,7 @@ def _get_client_certificate_request(self, scopes, certificate): return request def _get_client_secret_request(self, scopes, secret): - # type: (Sequence[str], str) -> HttpRequest + # type: (Iterable[str], str) -> HttpRequest data = { "client_id": self._client_id, "client_secret": secret, @@ -207,7 +207,7 @@ def _get_jwt_assertion(self, certificate): return jwt_bytes.decode("utf-8") def _get_refresh_token_request(self, scopes, refresh_token): - # type: (Sequence[str], str) -> HttpRequest + # type: (Iterable[str], str) -> HttpRequest data = { "grant_type": "refresh_token", "refresh_token": refresh_token, diff --git a/sdk/identity/azure-identity/azure/identity/_internal/msal_credentials.py b/sdk/identity/azure-identity/azure/identity/_internal/msal_credentials.py index 826ed9ef50d2..593e026dc90d 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/msal_credentials.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/msal_credentials.py @@ -200,7 +200,7 @@ def authenticate(self, **kwargs): # type: (**Any) -> AuthenticationRecord """Interactively authenticate a user. - :keyword Sequence[str] scopes: scopes to request during authentication, such as those provided by + :keyword Iterable[str] scopes: scopes to request during authentication, such as those provided by :func:`AuthenticationRequiredError.scopes`. If provided, successful authentication will cache an access token for these scopes. :rtype: ~azure.identity.AuthenticationRecord diff --git a/sdk/identity/azure-identity/azure/identity/_internal/shared_token_cache.py b/sdk/identity/azure-identity/azure/identity/_internal/shared_token_cache.py index 414819cc4ed0..d28a7602fd5e 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/shared_token_cache.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/shared_token_cache.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Iterable, List, Mapping, Optional, Sequence + from typing import Any, Iterable, List, Mapping, Optional from .._internal import AadClientBase from azure.identity import AuthenticationRecord @@ -203,7 +203,7 @@ def _get_account(self, username=None, tenant_id=None): raise CredentialUnavailableError(message=message) def _get_cached_access_token(self, scopes, account): - # type: (Sequence[str], CacheItem) -> Optional[AccessToken] + # type: (Iterable[str], CacheItem) -> Optional[AccessToken] if "home_account_id" not in account: return None diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/authorization_code.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/authorization_code.py index 0b5fbb53dc33..09266413472d 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/authorization_code.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/authorization_code.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Optional, Sequence + from typing import Any, Iterable, Optional from azure.core.credentials import AccessToken @@ -88,7 +88,7 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken": return token - async def _redeem_refresh_token(self, scopes: "Sequence[str]", **kwargs: "Any") -> "Optional[AccessToken]": + async def _redeem_refresh_token(self, scopes: "Iterable[str]", **kwargs: "Any") -> "Optional[AccessToken]": for refresh_token in self._client.get_cached_refresh_tokens(scopes): if "secret" not in refresh_token: continue diff --git a/sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py b/sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py index db5065412ae8..24322896727c 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from typing import Any, List, Optional, Sequence, Union + from typing import Any, Iterable, List, Optional, Union from azure.core.credentials import AccessToken from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy from azure.core.pipeline.transport import AsyncHttpTransport @@ -45,7 +45,7 @@ async def close(self) -> None: async def obtain_token_by_authorization_code( self, - scopes: "Sequence[str]", + scopes: "Iterable[str]", code: str, redirect_uri: str, client_secret: "Optional[str]" = None, @@ -59,14 +59,14 @@ async def obtain_token_by_authorization_code( return self._process_response(response, now) async def obtain_token_by_client_certificate(self, scopes, certificate, **kwargs): - # type: (Sequence[str], AadClientCertificate, **Any) -> AccessToken + # type: (Iterable[str], AadClientCertificate, **Any) -> AccessToken request = self._get_client_certificate_request(scopes, certificate) now = int(time.time()) response = await self._pipeline.run(request, stream=False, **kwargs) return self._process_response(response, now) async def obtain_token_by_client_secret( - self, scopes: "Sequence[str]", secret: str, **kwargs: "Any" + self, scopes: "Iterable[str]", secret: str, **kwargs: "Any" ) -> "AccessToken": request = self._get_client_secret_request(scopes, secret) now = int(time.time()) @@ -74,7 +74,7 @@ async def obtain_token_by_client_secret( return self._process_response(response, now) async def obtain_token_by_refresh_token( - self, scopes: "Sequence[str]", refresh_token: str, **kwargs: "Any" + self, scopes: "Iterable[str]", refresh_token: str, **kwargs: "Any" ) -> "AccessToken": request = self._get_refresh_token_request(scopes, refresh_token) now = int(time.time())