From 80ffbad5c087d8bc78bd409396aa98b7be34d6ef Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 15:56:56 -0800 Subject: [PATCH 1/6] update azure-core version --- sdk/core/azure-core/azure/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/azure-core/azure/core/_version.py b/sdk/core/azure-core/azure/core/_version.py index 36d453c94947..041af290eafa 100644 --- a/sdk/core/azure-core/azure/core/_version.py +++ b/sdk/core/azure-core/azure/core/_version.py @@ -9,4 +9,4 @@ # regenerated. # -------------------------------------------------------------------------- -VERSION = "1.2.0" +VERSION = "1.2.1" From 2f92fd0d97445d62c0634d4ee1ec1241850b9e11 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 15:57:13 -0800 Subject: [PATCH 2/6] revert refactoring of _BearerTokenCredentialPolicyBase --- .../core/pipeline/policies/_authentication.py | 16 ++++------------ .../pipeline/policies/_authentication_async.py | 17 +++++------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py index 45245c252d87..34799814b6f6 100644 --- a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py +++ b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py @@ -23,16 +23,16 @@ # pylint:disable=too-few-public-methods class _BearerTokenCredentialPolicyBase(object): """Base class for a Bearer Token Credential Policy. - :param credential: The credential. :type credential: ~azure.core.credentials.TokenCredential :param str scopes: Lets you specify the type of access needed. """ - def __init__(self, *scopes, **kwargs): # pylint:disable=unused-argument - # type: (*str, **Any) -> None + def __init__(self, credential, *scopes, **kwargs): # pylint:disable=unused-argument + # type: (TokenCredential, *str, Mapping[str, Any]) -> None super(_BearerTokenCredentialPolicyBase, self).__init__() self._scopes = scopes + self._credential = credential self._token = None # type: Optional[AccessToken] @staticmethod @@ -47,7 +47,6 @@ def _enforce_tls(request): def _update_headers(headers, token): # type: (Dict[str, str], str) -> None """Updates the Authorization header with the bearer token. - :param dict headers: The HTTP Request headers :param str token: The OAuth token. """ @@ -61,22 +60,15 @@ def _need_new_token(self): class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy): """Adds a bearer token Authorization header to requests. - :param credential: The credential. :type credential: ~azure.core.TokenCredential :param str scopes: Lets you specify the type of access needed. :raises: :class:`~azure.core.exceptions.ServiceRequestError` """ - def __init__(self, credential, *scopes, **kwargs): - # type: (TokenCredential, *str, **Any) -> None - self._credential = credential - super(BearerTokenCredentialPolicy, self).__init__(*scopes, **kwargs) - def on_request(self, request): # type: (PipelineRequest) -> None """Adds a bearer token Authorization header to request and sends request to next policy. - :param request: The pipeline request object :type request: ~azure.core.pipeline.PipelineRequest """ @@ -84,4 +76,4 @@ def on_request(self, request): if self._need_new_token: self._token = self._credential.get_token(*self._scopes) - self._update_headers(request.http_request.headers, self._token.token) # type: ignore + self._update_headers(request.http_request.headers, self._token.token) # type: ignore \ No newline at end of file diff --git a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py index 1edac216f2d0..1c6e220d092a 100644 --- a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py +++ b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py @@ -4,33 +4,26 @@ # license information. # ------------------------------------------------------------------------- import threading -from typing import TYPE_CHECKING +from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import SansIOHTTPPolicy from azure.core.pipeline.policies._authentication import _BearerTokenCredentialPolicyBase -if TYPE_CHECKING: - # pylint:disable=unused-import - from typing import Any - from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline import PipelineRequest - class AsyncBearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy): # pylint:disable=too-few-public-methods """Adds a bearer token Authorization header to requests. :param credential: The credential. - :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :type credential: ~azure.core.credentials.TokenCredential :param str scopes: Lets you specify the type of access needed. """ - def __init__(self, credential: "AsyncTokenCredential", *scopes: str, **kwargs: "Any") -> None: - self._credential = credential + def __init__(self, credential, *scopes, **kwargs): + super().__init__(credential, *scopes, **kwargs) self._lock = threading.Lock() - super().__init__(*scopes, **kwargs) - async def on_request(self, request: "PipelineRequest"): + async def on_request(self, request: PipelineRequest): """Adds a bearer token Authorization header to request and sends request to next policy. :param request: The pipeline request object to be modified. From a84177f14739688fc0e73305b32a8c5a9e98a9a1 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 16:18:54 -0800 Subject: [PATCH 3/6] update history --- sdk/core/azure-core/HISTORY.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sdk/core/azure-core/HISTORY.md b/sdk/core/azure-core/HISTORY.md index 25a794018eb4..7f99a15e7b8b 100644 --- a/sdk/core/azure-core/HISTORY.md +++ b/sdk/core/azure-core/HISTORY.md @@ -1,6 +1,13 @@ # Release History +## 1.2.1 (2020-01-14) + +### Bug fixes + +- Revert _BearerTokenCredentialPolicyBase refactoring #9465 + + ## 1.2.0 (2020-01-14) ### Features From fd68f6fca18e71be20b8f39547b8617165c9c126 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 16:19:33 -0800 Subject: [PATCH 4/6] fix whitespace --- .../azure/core/pipeline/policies/_authentication.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py index 34799814b6f6..11e6c8cf99fe 100644 --- a/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py +++ b/sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py @@ -23,6 +23,7 @@ # pylint:disable=too-few-public-methods class _BearerTokenCredentialPolicyBase(object): """Base class for a Bearer Token Credential Policy. + :param credential: The credential. :type credential: ~azure.core.credentials.TokenCredential :param str scopes: Lets you specify the type of access needed. @@ -47,6 +48,7 @@ def _enforce_tls(request): def _update_headers(headers, token): # type: (Dict[str, str], str) -> None """Updates the Authorization header with the bearer token. + :param dict headers: The HTTP Request headers :param str token: The OAuth token. """ @@ -60,6 +62,7 @@ def _need_new_token(self): class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy): """Adds a bearer token Authorization header to requests. + :param credential: The credential. :type credential: ~azure.core.TokenCredential :param str scopes: Lets you specify the type of access needed. @@ -69,6 +72,7 @@ class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPo def on_request(self, request): # type: (PipelineRequest) -> None """Adds a bearer token Authorization header to request and sends request to next policy. + :param request: The pipeline request object :type request: ~azure.core.pipeline.PipelineRequest """ @@ -76,4 +80,4 @@ def on_request(self, request): if self._need_new_token: self._token = self._credential.get_token(*self._scopes) - self._update_headers(request.http_request.headers, self._token.token) # type: ignore \ No newline at end of file + self._update_headers(request.http_request.headers, self._token.token) # type: ignore From 3439b10d242eb6650a418a85824223a46f7d18f1 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 16:39:49 -0800 Subject: [PATCH 5/6] revert corresponding changes to keyvault-* note this doesn't revert #9457 --- .../_shared/async_challenge_auth_policy.py | 20 +++++-------------- .../_shared/challenge_auth_policy.py | 11 ++++------ .../_shared/async_challenge_auth_policy.py | 20 +++++-------------- .../keys/_shared/challenge_auth_policy.py | 11 ++++------ .../_shared/async_challenge_auth_policy.py | 20 +++++-------------- .../secrets/_shared/challenge_auth_policy.py | 11 ++++------ 6 files changed, 27 insertions(+), 66 deletions(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/async_challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/async_challenge_auth_policy.py index 9bbc30e857f0..5b9b66551daf 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/async_challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/async_challenge_auth_policy.py @@ -13,28 +13,18 @@ requirements can change. For example, a vault may move to a new tenant. In such a case the policy will attempt the protocol again. """ -from typing import TYPE_CHECKING +from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import AsyncHTTPPolicy +from azure.core.pipeline.transport import HttpResponse -from . import ChallengeAuthPolicyBase, HttpChallengeCache - -if TYPE_CHECKING: - from typing import Any - from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline import PipelineRequest - from azure.core.pipeline.transport import HttpResponse - from . import HttpChallenge +from . import ChallengeAuthPolicyBase, HttpChallenge, HttpChallengeCache class AsyncChallengeAuthPolicy(ChallengeAuthPolicyBase, AsyncHTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential: "AsyncTokenCredential", **kwargs: "Any") -> None: - self._credential = credential - super().__init__(**kwargs) - - async def send(self, request: "PipelineRequest") -> "HttpResponse": + async def send(self, request: PipelineRequest) -> HttpResponse: self._enforce_tls(request) challenge = HttpChallengeCache.get_challenge_for_url(request.http_request.url) @@ -66,7 +56,7 @@ async def send(self, request: "PipelineRequest") -> "HttpResponse": return response - async def _handle_challenge(self, request: "PipelineRequest", challenge: "HttpChallenge") -> None: + async def _handle_challenge(self, request: PipelineRequest, challenge: HttpChallenge) -> None: """authenticate according to challenge, add Authorization header to request""" if self._need_new_token: diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/challenge_auth_policy.py index 11955ed6d3bd..c1b8d5d66235 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/challenge_auth_policy.py @@ -31,14 +31,16 @@ if TYPE_CHECKING: # pylint:disable=unused-import - from typing import Any - from azure.core.credentials import TokenCredential from azure.core.pipeline.transport import HttpResponse class ChallengeAuthPolicyBase(_BearerTokenCredentialPolicyBase): """Sans I/O base for challenge authentication policies""" + # pylint:disable=useless-super-delegation + def __init__(self, credential, **kwargs): + super(ChallengeAuthPolicyBase, self).__init__(credential, **kwargs) + @staticmethod def _update_challenge(request, challenger): # type: (HttpRequest, HttpResponse) -> HttpChallenge @@ -72,11 +74,6 @@ def _get_challenge_request(request): class ChallengeAuthPolicy(ChallengeAuthPolicyBase, HTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential, **kwargs): - # type: (TokenCredential, **Any) -> None - self._credential = credential - super(ChallengeAuthPolicy, self).__init__(**kwargs) - def send(self, request): # type: (PipelineRequest) -> HttpResponse self._enforce_tls(request) diff --git a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/async_challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/async_challenge_auth_policy.py index 9bbc30e857f0..5b9b66551daf 100644 --- a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/async_challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/async_challenge_auth_policy.py @@ -13,28 +13,18 @@ requirements can change. For example, a vault may move to a new tenant. In such a case the policy will attempt the protocol again. """ -from typing import TYPE_CHECKING +from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import AsyncHTTPPolicy +from azure.core.pipeline.transport import HttpResponse -from . import ChallengeAuthPolicyBase, HttpChallengeCache - -if TYPE_CHECKING: - from typing import Any - from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline import PipelineRequest - from azure.core.pipeline.transport import HttpResponse - from . import HttpChallenge +from . import ChallengeAuthPolicyBase, HttpChallenge, HttpChallengeCache class AsyncChallengeAuthPolicy(ChallengeAuthPolicyBase, AsyncHTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential: "AsyncTokenCredential", **kwargs: "Any") -> None: - self._credential = credential - super().__init__(**kwargs) - - async def send(self, request: "PipelineRequest") -> "HttpResponse": + async def send(self, request: PipelineRequest) -> HttpResponse: self._enforce_tls(request) challenge = HttpChallengeCache.get_challenge_for_url(request.http_request.url) @@ -66,7 +56,7 @@ async def send(self, request: "PipelineRequest") -> "HttpResponse": return response - async def _handle_challenge(self, request: "PipelineRequest", challenge: "HttpChallenge") -> None: + async def _handle_challenge(self, request: PipelineRequest, challenge: HttpChallenge) -> None: """authenticate according to challenge, add Authorization header to request""" if self._need_new_token: diff --git a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/challenge_auth_policy.py index 11955ed6d3bd..c1b8d5d66235 100644 --- a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/challenge_auth_policy.py @@ -31,14 +31,16 @@ if TYPE_CHECKING: # pylint:disable=unused-import - from typing import Any - from azure.core.credentials import TokenCredential from azure.core.pipeline.transport import HttpResponse class ChallengeAuthPolicyBase(_BearerTokenCredentialPolicyBase): """Sans I/O base for challenge authentication policies""" + # pylint:disable=useless-super-delegation + def __init__(self, credential, **kwargs): + super(ChallengeAuthPolicyBase, self).__init__(credential, **kwargs) + @staticmethod def _update_challenge(request, challenger): # type: (HttpRequest, HttpResponse) -> HttpChallenge @@ -72,11 +74,6 @@ def _get_challenge_request(request): class ChallengeAuthPolicy(ChallengeAuthPolicyBase, HTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential, **kwargs): - # type: (TokenCredential, **Any) -> None - self._credential = credential - super(ChallengeAuthPolicy, self).__init__(**kwargs) - def send(self, request): # type: (PipelineRequest) -> HttpResponse self._enforce_tls(request) diff --git a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/async_challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/async_challenge_auth_policy.py index 9bbc30e857f0..5b9b66551daf 100644 --- a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/async_challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/async_challenge_auth_policy.py @@ -13,28 +13,18 @@ requirements can change. For example, a vault may move to a new tenant. In such a case the policy will attempt the protocol again. """ -from typing import TYPE_CHECKING +from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import AsyncHTTPPolicy +from azure.core.pipeline.transport import HttpResponse -from . import ChallengeAuthPolicyBase, HttpChallengeCache - -if TYPE_CHECKING: - from typing import Any - from azure.core.credentials_async import AsyncTokenCredential - from azure.core.pipeline import PipelineRequest - from azure.core.pipeline.transport import HttpResponse - from . import HttpChallenge +from . import ChallengeAuthPolicyBase, HttpChallenge, HttpChallengeCache class AsyncChallengeAuthPolicy(ChallengeAuthPolicyBase, AsyncHTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential: "AsyncTokenCredential", **kwargs: "Any") -> None: - self._credential = credential - super().__init__(**kwargs) - - async def send(self, request: "PipelineRequest") -> "HttpResponse": + async def send(self, request: PipelineRequest) -> HttpResponse: self._enforce_tls(request) challenge = HttpChallengeCache.get_challenge_for_url(request.http_request.url) @@ -66,7 +56,7 @@ async def send(self, request: "PipelineRequest") -> "HttpResponse": return response - async def _handle_challenge(self, request: "PipelineRequest", challenge: "HttpChallenge") -> None: + async def _handle_challenge(self, request: PipelineRequest, challenge: HttpChallenge) -> None: """authenticate according to challenge, add Authorization header to request""" if self._need_new_token: diff --git a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/challenge_auth_policy.py index 11955ed6d3bd..c1b8d5d66235 100644 --- a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/challenge_auth_policy.py @@ -31,14 +31,16 @@ if TYPE_CHECKING: # pylint:disable=unused-import - from typing import Any - from azure.core.credentials import TokenCredential from azure.core.pipeline.transport import HttpResponse class ChallengeAuthPolicyBase(_BearerTokenCredentialPolicyBase): """Sans I/O base for challenge authentication policies""" + # pylint:disable=useless-super-delegation + def __init__(self, credential, **kwargs): + super(ChallengeAuthPolicyBase, self).__init__(credential, **kwargs) + @staticmethod def _update_challenge(request, challenger): # type: (HttpRequest, HttpResponse) -> HttpChallenge @@ -72,11 +74,6 @@ def _get_challenge_request(request): class ChallengeAuthPolicy(ChallengeAuthPolicyBase, HTTPPolicy): """policy for handling HTTP authentication challenges""" - def __init__(self, credential, **kwargs): - # type: (TokenCredential, **Any) -> None - self._credential = credential - super(ChallengeAuthPolicy, self).__init__(**kwargs) - def send(self, request): # type: (PipelineRequest) -> HttpResponse self._enforce_tls(request) From 629e88a39e3ccbd1ce0ab165e69b42842b4640b6 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 14 Jan 2020 17:09:27 -0800 Subject: [PATCH 6/6] update history --- sdk/core/azure-core/HISTORY.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-core/HISTORY.md b/sdk/core/azure-core/HISTORY.md index 7f99a15e7b8b..903b54cbcd66 100644 --- a/sdk/core/azure-core/HISTORY.md +++ b/sdk/core/azure-core/HISTORY.md @@ -5,7 +5,8 @@ ### Bug fixes -- Revert _BearerTokenCredentialPolicyBase refactoring #9465 +- Fixed a regression in 1.2.0 that was incompatible with azure-keyvault-* 4.0.0 +[#9462](https://github.com/Azure/azure-sdk-for-python/issues/9462) ## 1.2.0 (2020-01-14)