44# Licensed under the MIT License.
55# ------------------------------------
66
7- from typing import TYPE_CHECKING , Any , Union , Optional
7+ from typing import Union , Optional
88from io import SEEK_SET , UnsupportedOperation
99
10+ from azure .core .credentials import TokenCredential
11+ from azure .core .pipeline import PipelineRequest , PipelineResponse
1012from azure .core .pipeline .policies import HTTPPolicy
1113
1214from ._anonymous_exchange_client import AnonymousACRExchangeClient
1315from ._exchange_client import ACRExchangeClient
1416from ._helpers import _enforce_https
1517
16- if TYPE_CHECKING :
17- from azure .core .credentials import TokenCredential
18- from azure .core .pipeline import PipelineRequest , PipelineResponse
19-
2018
2119class ContainerRegistryChallengePolicy (HTTPPolicy ):
2220 """Authentication policy for ACR which accepts a challenge"""
2321
24- def __init__ (self , credential , endpoint , ** kwargs ):
25- # type: (Optional[TokenCredential], str, **Any) -> None
22+ def __init__ (self , credential : Optional [TokenCredential ], endpoint : str , ** kwargs ) -> None :
2623 super (ContainerRegistryChallengePolicy , self ).__init__ ()
2724 self ._credential = credential
2825 if self ._credential is None :
2926 self ._exchange_client = AnonymousACRExchangeClient (endpoint , ** kwargs ) # type: Union[AnonymousACRExchangeClient, ACRExchangeClient] # pylint: disable=line-too-long
3027 else :
3128 self ._exchange_client = ACRExchangeClient (endpoint , self ._credential , ** kwargs )
3229
33- def on_request (self , request ):
34- # type: (PipelineRequest) -> None
30+ def on_request (self , request : PipelineRequest ) -> None :
3531 """Called before the policy sends a request.
3632 The base implementation authorizes the request with a bearer token.
33+
3734 :param ~azure.core.pipeline.PipelineRequest request: the request
3835 """
3936 # Future caching implementation will be included here
4037 pass # pylint: disable=unnecessary-pass
4138
42- def send (self , request ):
43- # type: (PipelineRequest) -> PipelineResponse
39+ def send (self , request : PipelineRequest ) -> PipelineResponse :
4440 """Authorizes a request with a bearer token, possibly handling an authentication challenge
41+
4542 :param ~azure.core.pipeline.PipelineRequest request: the request
4643 """
4744 _enforce_https (request )
@@ -65,16 +62,16 @@ def send(self, request):
6562
6663 return response
6764
68- def on_challenge (self , request , response , challenge ):
69- # type: (PipelineRequest, PipelineResponse, str) -> bool
65+ def on_challenge (self , request : PipelineRequest , response : PipelineResponse , challenge : str ) -> bool :
7066 """Authorize request according to an authentication challenge
7167 This method is called when the resource provider responds 401 with a WWW-Authenticate header.
68+
7269 :param ~azure.core.pipeline.PipelineRequest request: the request which elicited an authentication challenge
7370 :param ~azure.core.pipeline.PipelineResponse response: the resource provider's response
7471 :param str challenge: response's WWW-Authenticate header, unparsed. It may contain multiple challenges.
7572 :returns: a bool indicating whether the policy should send the request
7673 """
77- # pylint:disable=unused-argument,no-self-use
74+ # pylint:disable=unused-argument, no-self-use
7875
7976 access_token = self ._exchange_client .get_acr_access_token (challenge )
8077 if access_token is not None :
0 commit comments