Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions sdk/identity/azure-identity/azure/identity/_authn_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ 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)
config = config or self._create_config(**kwargs)
policies = policies or [ContentDecodePolicy(), config.retry_policy, config.logging_policy, DistributedTracingPolicy()]
if not transport:
transport = RequestsTransport(**kwargs)
Expand All @@ -135,7 +135,7 @@ def request_token(self, scopes, method="POST", headers=None, form_data=None, par
return token

@staticmethod
def create_config(**kwargs):
def _create_config(**kwargs):
# type: (Mapping[str, Any]) -> Configuration
config = Configuration(**kwargs)
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def __init__(self, **kwargs):
self._pipeline = self._build_pipeline(**kwargs)

@staticmethod
def create_config(**kwargs):
def _create_config(**kwargs):
# type: (Any) -> Configuration
config = Configuration(**kwargs)
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)
config.retry_policy = RetryPolicy(**kwargs)
return config

def _build_pipeline(self, config=None, policies=None, transport=None, **kwargs):
config = config or self.create_config(**kwargs)
config = config or self._create_config(**kwargs)
policies = policies or [ContentDecodePolicy(), config.retry_policy, config.logging_policy]
if not transport:
transport = RequestsTransport(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class _ManagedIdentityBase(object):
def __init__(self, endpoint, client_cls, config=None, client_id=None, **kwargs):
# type: (str, Type, Optional[Configuration], Optional[str], Any) -> None
self._client_id = client_id
config = config or self.create_config(**kwargs)
config = config or self._create_config(**kwargs)
policies = [ContentDecodePolicy(), config.headers_policy, config.retry_policy, config.logging_policy]
self._client = client_cls(endpoint, config, policies, **kwargs)

@staticmethod
def create_config(**kwargs):
def _create_config(**kwargs):
# type: (Mapping[str, Any]) -> Configuration
"""
Build a default configuration for the credential's HTTP pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
transport: Optional[AsyncHttpTransport] = None,
**kwargs: Mapping[str, Any]
) -> None:
config = config or self.create_config(**kwargs)
config = config or self._create_config(**kwargs)
policies = policies or [
ContentDecodePolicy(),
config.retry_policy,
Expand Down Expand Up @@ -55,7 +55,7 @@ async def request_token(
return token

@staticmethod
def create_config(**kwargs: Mapping[str, Any]) -> Configuration:
def _create_config(**kwargs: Mapping[str, Any]) -> Configuration:
config = Configuration(**kwargs)
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)
config.retry_policy = AsyncRetryPolicy(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def __init__(self, endpoint: str, config: Optional[Configuration] = None, **kwar
super().__init__(endpoint=endpoint, config=config, client_cls=AsyncAuthnClient, **kwargs)

@staticmethod
def create_config(**kwargs: Any) -> Configuration: # type: ignore
def _create_config(**kwargs: Any) -> Configuration: # type: ignore
"""
Build a default configuration for the credential's HTTP pipeline.

:rtype: :class:`azure.core.configuration`
"""
return _ManagedIdentityBase.create_config(retry_policy=AsyncRetryPolicy, **kwargs)
return _ManagedIdentityBase._create_config(retry_policy=AsyncRetryPolicy, **kwargs)


class ImdsCredential(_AsyncManagedIdentityBase):
Expand Down
39 changes: 5 additions & 34 deletions sdk/identity/azure-identity/azure/identity/aio/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,11 @@ class ClientSecretCredential(ClientSecretCredentialBase):
:param str client_id: the service principal's client ID
:param str secret: one of the service principal's client secrets
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __init__(
self,
client_id: str,
secret: str,
tenant_id: str,
config: Optional[Configuration] = None,
**kwargs: Mapping[str, Any]
) -> None:
def __init__(self, client_id: str, secret: str, tenant_id: str, **kwargs: Mapping[str, Any]) -> None:
super(ClientSecretCredential, self).__init__(client_id, secret, tenant_id, **kwargs)
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)

async def get_token(self, *scopes: str) -> AccessToken:
"""
Expand All @@ -66,20 +57,11 @@ class CertificateCredential(CertificateCredentialBase):
:param str client_id: the service principal's client ID
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
:param str certificate_path: path to a PEM-encoded certificate file including the private key
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __init__(
self,
client_id: str,
tenant_id: str,
certificate_path: str,
config: Optional[Configuration] = None,
**kwargs: Mapping[str, Any]
) -> None:
def __init__(self, client_id: str, tenant_id: str, certificate_path: str, **kwargs: Mapping[str, Any]) -> None:
super(CertificateCredential, self).__init__(client_id, tenant_id, certificate_path, **kwargs)
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)

async def get_token(self, *scopes: str) -> AccessToken:
"""
Expand Down Expand Up @@ -151,8 +133,6 @@ class ManagedIdentityCredential(object):
Authenticates with a managed identity in an App Service, Azure VM or Cloud Shell environment.

:param str client_id: Optional client ID of a user-assigned identity. Leave unspecified to use a system-assigned identity.
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __new__(cls, *args, **kwargs):
Expand All @@ -162,18 +142,9 @@ def __new__(cls, *args, **kwargs):

# the below methods are never called, because ManagedIdentityCredential can't be instantiated;
# they exist so tooling gets accurate signatures for Imds- and MsiCredential
def __init__(self, client_id: Optional[str] = None, config: Optional[Configuration] = None, **kwargs: Any) -> None:
def __init__(self, client_id: Optional[str] = None, **kwargs: Any) -> None:
pass

@staticmethod
def create_config(**kwargs: Dict[str, Any]) -> Configuration:
"""
Build a default configuration for the credential's HTTP pipeline.

:rtype: :class:`azure.core.configuration`
"""
return Configuration(**kwargs)

async def get_token(self, *scopes: str) -> AccessToken:
"""
Asynchronously request an access token for `scopes`.
Expand Down
32 changes: 8 additions & 24 deletions sdk/identity/azure-identity/azure/identity/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ class ClientSecretCredential(ClientSecretCredentialBase):
:param str client_id: the service principal's client ID
:param str secret: one of the service principal's client secrets
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __init__(self, client_id, secret, tenant_id, config=None, **kwargs):
# type: (str, str, str, Optional[Configuration], Mapping[str, Any]) -> None
def __init__(self, client_id, secret, tenant_id, **kwargs):
# type: (str, str, str, Mapping[str, Any]) -> None
super(ClientSecretCredential, self).__init__(client_id, secret, tenant_id, **kwargs)
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)

def get_token(self, *scopes):
# type (*str) -> AccessToken
Expand All @@ -72,13 +70,11 @@ class CertificateCredential(CertificateCredentialBase):
:param str client_id: the service principal's client ID
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
:param str certificate_path: path to a PEM-encoded certificate file including the private key
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __init__(self, client_id, tenant_id, certificate_path, config=None, **kwargs):
# type: (str, str, str, Optional[Configuration], Mapping[str, Any]) -> None
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
def __init__(self, client_id, tenant_id, certificate_path, **kwargs):
# type: (str, str, str, Mapping[str, Any]) -> None
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)
super(CertificateCredential, self).__init__(client_id, tenant_id, certificate_path, **kwargs)

def get_token(self, *scopes):
Expand Down Expand Up @@ -165,8 +161,6 @@ class ManagedIdentityCredential(object):
Authenticates with a managed identity in an App Service, Azure VM or Cloud Shell environment.

:param str client_id: Optional client ID of a user-assigned identity. Leave unspecified to use a system-assigned identity.
:param config: optional configuration for the underlying HTTP pipeline
:type config: :class:`azure.core.configuration`
"""

def __new__(cls, *args, **kwargs):
Expand All @@ -176,20 +170,10 @@ def __new__(cls, *args, **kwargs):

# the below methods are never called, because ManagedIdentityCredential can't be instantiated;
# they exist so tooling gets accurate signatures for Imds- and MsiCredential
def __init__(self, client_id=None, config=None, **kwargs):
# type: (Optional[str], Optional[Configuration], Any) -> None
def __init__(self, client_id=None, **kwargs):
# type: (Optional[str], Any) -> None
pass

@staticmethod
def create_config(**kwargs):
# type: (Dict[str, str]) -> Configuration
"""
Build a default configuration for the credential's HTTP pipeline.

:rtype: :class:`azure.core.configuration`
"""
return Configuration(**kwargs)

def get_token(self, *scopes):
# type (*str) -> AccessToken
"""
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/azure-identity/tests/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_imds_credential_retries():
)
mock_send = Mock(return_value=mock_response)

total_retries = ImdsCredential.create_config().retry_policy.total_retries
total_retries = ImdsCredential._create_config().retry_policy.total_retries

for status_code in (404, 429, 500):
mock_send.reset_mock()
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/azure-identity/tests/test_identity_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ async def test_imds_credential_retries():
)
mock_send = Mock(return_value=mock_response)

total_retries = ImdsCredential.create_config().retry_policy.total_retries
total_retries = ImdsCredential._create_config().retry_policy.total_retries

for status_code in (404, 429, 500):
mock_send.reset_mock()
Expand Down