Skip to content

Commit 64b121c

Browse files
authored
Remove Configuration from public API (Azure#6603)
1 parent f700299 commit 64b121c

File tree

9 files changed

+25
-70
lines changed

9 files changed

+25
-70
lines changed

sdk/identity/azure-identity/azure/identity/_authn_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class AuthnClient(AuthnClientBase):
119119

120120
def __init__(self, auth_url, config=None, policies=None, transport=None, **kwargs):
121121
# type: (str, Optional[Configuration], Optional[Iterable[HTTPPolicy]], Optional[HttpTransport], Mapping[str, Any]) -> None
122-
config = config or self.create_config(**kwargs)
122+
config = config or self._create_config(**kwargs)
123123
policies = policies or [ContentDecodePolicy(), config.retry_policy, config.logging_policy, DistributedTracingPolicy()]
124124
if not transport:
125125
transport = RequestsTransport(**kwargs)
@@ -135,7 +135,7 @@ def request_token(self, scopes, method="POST", headers=None, form_data=None, par
135135
return token
136136

137137
@staticmethod
138-
def create_config(**kwargs):
138+
def _create_config(**kwargs):
139139
# type: (Mapping[str, Any]) -> Configuration
140140
config = Configuration(**kwargs)
141141
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)

sdk/identity/azure-identity/azure/identity/_internal/msal_transport_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def __init__(self, **kwargs):
5050
self._pipeline = self._build_pipeline(**kwargs)
5151

5252
@staticmethod
53-
def create_config(**kwargs):
53+
def _create_config(**kwargs):
5454
# type: (Any) -> Configuration
5555
config = Configuration(**kwargs)
5656
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)
5757
config.retry_policy = RetryPolicy(**kwargs)
5858
return config
5959

6060
def _build_pipeline(self, config=None, policies=None, transport=None, **kwargs):
61-
config = config or self.create_config(**kwargs)
61+
config = config or self._create_config(**kwargs)
6262
policies = policies or [ContentDecodePolicy(), config.retry_policy, config.logging_policy]
6363
if not transport:
6464
transport = RequestsTransport(**kwargs)

sdk/identity/azure-identity/azure/identity/_managed_identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class _ManagedIdentityBase(object):
2828
def __init__(self, endpoint, client_cls, config=None, client_id=None, **kwargs):
2929
# type: (str, Type, Optional[Configuration], Optional[str], Any) -> None
3030
self._client_id = client_id
31-
config = config or self.create_config(**kwargs)
31+
config = config or self._create_config(**kwargs)
3232
policies = [ContentDecodePolicy(), config.headers_policy, config.retry_policy, config.logging_policy]
3333
self._client = client_cls(endpoint, config, policies, **kwargs)
3434

3535
@staticmethod
36-
def create_config(**kwargs):
36+
def _create_config(**kwargs):
3737
# type: (Mapping[str, Any]) -> Configuration
3838
"""
3939
Build a default configuration for the credential's HTTP pipeline.

sdk/identity/azure-identity/azure/identity/aio/_authn_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
transport: Optional[AsyncHttpTransport] = None,
2828
**kwargs: Mapping[str, Any]
2929
) -> None:
30-
config = config or self.create_config(**kwargs)
30+
config = config or self._create_config(**kwargs)
3131
policies = policies or [
3232
ContentDecodePolicy(),
3333
config.retry_policy,
@@ -55,7 +55,7 @@ async def request_token(
5555
return token
5656

5757
@staticmethod
58-
def create_config(**kwargs: Mapping[str, Any]) -> Configuration:
58+
def _create_config(**kwargs: Mapping[str, Any]) -> Configuration:
5959
config = Configuration(**kwargs)
6060
config.logging_policy = NetworkTraceLoggingPolicy(**kwargs)
6161
config.retry_policy = AsyncRetryPolicy(**kwargs)

sdk/identity/azure-identity/azure/identity/aio/_managed_identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def __init__(self, endpoint: str, config: Optional[Configuration] = None, **kwar
2020
super().__init__(endpoint=endpoint, config=config, client_cls=AsyncAuthnClient, **kwargs)
2121

2222
@staticmethod
23-
def create_config(**kwargs: Any) -> Configuration: # type: ignore
23+
def _create_config(**kwargs: Any) -> Configuration: # type: ignore
2424
"""
2525
Build a default configuration for the credential's HTTP pipeline.
2626
2727
:rtype: :class:`azure.core.configuration`
2828
"""
29-
return _ManagedIdentityBase.create_config(retry_policy=AsyncRetryPolicy, **kwargs)
29+
return _ManagedIdentityBase._create_config(retry_policy=AsyncRetryPolicy, **kwargs)
3030

3131

3232
class ImdsCredential(_AsyncManagedIdentityBase):

sdk/identity/azure-identity/azure/identity/aio/credentials.py

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,11 @@ class ClientSecretCredential(ClientSecretCredentialBase):
2929
:param str client_id: the service principal's client ID
3030
:param str secret: one of the service principal's client secrets
3131
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
32-
:param config: optional configuration for the underlying HTTP pipeline
33-
:type config: :class:`azure.core.configuration`
3432
"""
3533

36-
def __init__(
37-
self,
38-
client_id: str,
39-
secret: str,
40-
tenant_id: str,
41-
config: Optional[Configuration] = None,
42-
**kwargs: Mapping[str, Any]
43-
) -> None:
34+
def __init__(self, client_id: str, secret: str, tenant_id: str, **kwargs: Mapping[str, Any]) -> None:
4435
super(ClientSecretCredential, self).__init__(client_id, secret, tenant_id, **kwargs)
45-
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
36+
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)
4637

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

73-
def __init__(
74-
self,
75-
client_id: str,
76-
tenant_id: str,
77-
certificate_path: str,
78-
config: Optional[Configuration] = None,
79-
**kwargs: Mapping[str, Any]
80-
) -> None:
62+
def __init__(self, client_id: str, tenant_id: str, certificate_path: str, **kwargs: Mapping[str, Any]) -> None:
8163
super(CertificateCredential, self).__init__(client_id, tenant_id, certificate_path, **kwargs)
82-
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
64+
self._client = AsyncAuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)
8365

8466
async def get_token(self, *scopes: str) -> AccessToken:
8567
"""
@@ -151,8 +133,6 @@ class ManagedIdentityCredential(object):
151133
Authenticates with a managed identity in an App Service, Azure VM or Cloud Shell environment.
152134
153135
:param str client_id: Optional client ID of a user-assigned identity. Leave unspecified to use a system-assigned identity.
154-
:param config: optional configuration for the underlying HTTP pipeline
155-
:type config: :class:`azure.core.configuration`
156136
"""
157137

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

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

168-
@staticmethod
169-
def create_config(**kwargs: Dict[str, Any]) -> Configuration:
170-
"""
171-
Build a default configuration for the credential's HTTP pipeline.
172-
173-
:rtype: :class:`azure.core.configuration`
174-
"""
175-
return Configuration(**kwargs)
176-
177148
async def get_token(self, *scopes: str) -> AccessToken:
178149
"""
179150
Asynchronously request an access token for `scopes`.

sdk/identity/azure-identity/azure/identity/credentials.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ class ClientSecretCredential(ClientSecretCredentialBase):
4141
:param str client_id: the service principal's client ID
4242
:param str secret: one of the service principal's client secrets
4343
:param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
44-
:param config: optional configuration for the underlying HTTP pipeline
45-
:type config: :class:`azure.core.configuration`
4644
"""
4745

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

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

80-
def __init__(self, client_id, tenant_id, certificate_path, config=None, **kwargs):
81-
# type: (str, str, str, Optional[Configuration], Mapping[str, Any]) -> None
82-
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), config, **kwargs)
76+
def __init__(self, client_id, tenant_id, certificate_path, **kwargs):
77+
# type: (str, str, str, Mapping[str, Any]) -> None
78+
self._client = AuthnClient(Endpoints.AAD_OAUTH2_V2_FORMAT.format(tenant_id), **kwargs)
8379
super(CertificateCredential, self).__init__(client_id, tenant_id, certificate_path, **kwargs)
8480

8581
def get_token(self, *scopes):
@@ -166,8 +162,6 @@ class ManagedIdentityCredential(object):
166162
Authenticates with a managed identity in an App Service, Azure VM or Cloud Shell environment.
167163
168164
:param str client_id: Optional client ID of a user-assigned identity. Leave unspecified to use a system-assigned identity.
169-
:param config: optional configuration for the underlying HTTP pipeline
170-
:type config: :class:`azure.core.configuration`
171165
"""
172166

173167
def __new__(cls, *args, **kwargs):
@@ -177,20 +171,10 @@ def __new__(cls, *args, **kwargs):
177171

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

184-
@staticmethod
185-
def create_config(**kwargs):
186-
# type: (Dict[str, str]) -> Configuration
187-
"""
188-
Build a default configuration for the credential's HTTP pipeline.
189-
190-
:rtype: :class:`azure.core.configuration`
191-
"""
192-
return Configuration(**kwargs)
193-
194178
def get_token(self, *scopes):
195179
# type (*str) -> AccessToken
196180
"""

sdk/identity/azure-identity/tests/test_identity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_imds_credential_retries():
222222
)
223223
mock_send = Mock(return_value=mock_response)
224224

225-
total_retries = ImdsCredential.create_config().retry_policy.total_retries
225+
total_retries = ImdsCredential._create_config().retry_policy.total_retries
226226

227227
for status_code in (404, 429, 500):
228228
mock_send.reset_mock()

sdk/identity/azure-identity/tests/test_identity_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async def test_imds_credential_retries():
223223
)
224224
mock_send = Mock(return_value=mock_response)
225225

226-
total_retries = ImdsCredential.create_config().retry_policy.total_retries
226+
total_retries = ImdsCredential._create_config().retry_policy.total_retries
227227

228228
for status_code in (404, 429, 500):
229229
mock_send.reset_mock()

0 commit comments

Comments
 (0)