diff --git a/sdk/identity/azure-identity/azure/identity/_authn_client.py b/sdk/identity/azure-identity/azure/identity/_authn_client.py index 09fc166d917e..65f61f090ccd 100644 --- a/sdk/identity/azure-identity/azure/identity/_authn_client.py +++ b/sdk/identity/azure-identity/azure/identity/_authn_client.py @@ -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) @@ -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) diff --git a/sdk/identity/azure-identity/azure/identity/_internal/msal_transport_adapter.py b/sdk/identity/azure-identity/azure/identity/_internal/msal_transport_adapter.py index adcd12a33f09..8cdc72a4193c 100644 --- a/sdk/identity/azure-identity/azure/identity/_internal/msal_transport_adapter.py +++ b/sdk/identity/azure-identity/azure/identity/_internal/msal_transport_adapter.py @@ -50,7 +50,7 @@ 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) @@ -58,7 +58,7 @@ def create_config(**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) diff --git a/sdk/identity/azure-identity/azure/identity/_managed_identity.py b/sdk/identity/azure-identity/azure/identity/_managed_identity.py index 65fc42479101..9c3c0cd7d982 100644 --- a/sdk/identity/azure-identity/azure/identity/_managed_identity.py +++ b/sdk/identity/azure-identity/azure/identity/_managed_identity.py @@ -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. diff --git a/sdk/identity/azure-identity/azure/identity/aio/_authn_client.py b/sdk/identity/azure-identity/azure/identity/aio/_authn_client.py index 4d75cd07b1a3..9c3e6c7bbc1f 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_authn_client.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_authn_client.py @@ -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, @@ -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) diff --git a/sdk/identity/azure-identity/azure/identity/aio/_managed_identity.py b/sdk/identity/azure-identity/azure/identity/aio/_managed_identity.py index ec698b52c98b..9d8eeb46a67c 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_managed_identity.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_managed_identity.py @@ -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): diff --git a/sdk/identity/azure-identity/azure/identity/aio/credentials.py b/sdk/identity/azure-identity/azure/identity/aio/credentials.py index c43dc917e518..fd80e2bc1051 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/credentials.py +++ b/sdk/identity/azure-identity/azure/identity/aio/credentials.py @@ -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: """ @@ -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: """ @@ -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): @@ -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`. diff --git a/sdk/identity/azure-identity/azure/identity/credentials.py b/sdk/identity/azure-identity/azure/identity/credentials.py index 2e09a306aa71..e79bda9174cf 100644 --- a/sdk/identity/azure-identity/azure/identity/credentials.py +++ b/sdk/identity/azure-identity/azure/identity/credentials.py @@ -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 @@ -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): @@ -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): @@ -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 """ diff --git a/sdk/identity/azure-identity/tests/test_identity.py b/sdk/identity/azure-identity/tests/test_identity.py index 3aaa54a1f28f..9a92188a6c17 100644 --- a/sdk/identity/azure-identity/tests/test_identity.py +++ b/sdk/identity/azure-identity/tests/test_identity.py @@ -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() diff --git a/sdk/identity/azure-identity/tests/test_identity_async.py b/sdk/identity/azure-identity/tests/test_identity_async.py index 03b53db9eccd..f19339c8275e 100644 --- a/sdk/identity/azure-identity/tests/test_identity_async.py +++ b/sdk/identity/azure-identity/tests/test_identity_async.py @@ -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()