Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix mypy errors
  • Loading branch information
chlowell committed Aug 5, 2019
commit 63ee04203532b26cbad84c764fcfb9a4b5c8fd4b
14 changes: 10 additions & 4 deletions sdk/identity/azure-identity/azure/identity/_authn_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
except ImportError:
TYPE_CHECKING = False
if TYPE_CHECKING:
# pylint:disable=unused-import
from time import struct_time
from typing import Any, Dict, Iterable, Mapping, Optional
from typing import Any, Dict, Iterable, Mapping, Optional, Union
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.policies import HTTPPolicy

Expand Down Expand Up @@ -60,13 +61,13 @@ def _deserialize_and_cache_token(self, response, scopes, request_time):
token = payload["access_token"]

# AccessToken wants expires_on as an int
expires_on = payload.get("expires_on") or int(payload["expires_in"]) + request_time
expires_on = payload.get("expires_on") or int(payload["expires_in"]) + request_time # type: Union[str, int]
try:
expires_on = int(expires_on)
except ValueError:
# probably an App Service MSI response, convert it to epoch seconds
try:
t = self._parse_app_service_expires_on(expires_on)
t = self._parse_app_service_expires_on(expires_on) # type: ignore
expires_on = calendar.timegm(t)
except ValueError:
# have a token but don't know when it expires -> treat it as single-use
Expand Down Expand Up @@ -120,7 +121,12 @@ class AuthnClient(AuthnClientBase):
def __init__(self, auth_url, config=None, policies=None, transport=None, **kwargs):
# type: (str, Optional[Configuration], Optional[Iterable[HTTPPolicy]], Optional[HttpTransport], Mapping[str, Any]) -> None
config = config or self._create_config(**kwargs)
policies = policies or [ContentDecodePolicy(), config.retry_policy, config.logging_policy, DistributedTracingPolicy()]
policies = policies or [
ContentDecodePolicy(),
config.retry_policy,
config.logging_policy,
DistributedTracingPolicy(),
]
if not transport:
transport = RequestsTransport(**kwargs)
self._pipeline = Pipeline(transport=transport, policies=policies)
Expand Down
6 changes: 3 additions & 3 deletions sdk/identity/azure-identity/azure/identity/aio/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ._managed_identity import ImdsCredential, MsiCredential
from .._base import ClientSecretCredentialBase, CertificateCredentialBase
from ..constants import Endpoints, EnvironmentVariables
from ..credentials import ChainedTokenCredential
from ..credentials import ChainedTokenCredential as SyncChainedTokenCredential

# pylint:disable=too-few-public-methods

Expand Down Expand Up @@ -156,7 +156,7 @@ async def get_token(self, *scopes: str) -> AccessToken:
return AccessToken()


class ChainedTokenCredential(ChainedTokenCredential):
class ChainedTokenCredential(SyncChainedTokenCredential):
"""
A sequence of credentials that is itself a credential. Its ``get_token`` method calls ``get_token`` on each
credential in the sequence, in order, returning the first valid token received.
Expand All @@ -165,7 +165,7 @@ class ChainedTokenCredential(ChainedTokenCredential):
:type credentials: :class:`azure.core.credentials.TokenCredential`
"""

async def get_token(self, *scopes: str) -> AccessToken: # type: ignore
async def get_token(self, *scopes: str) -> AccessToken:
"""
Asynchronously request a token from each credential, in order, returning the first token
received. If none provides a token, raises :class:`azure.core.exceptions.ClientAuthenticationError`
Expand Down