Skip to content

Commit 45a1aee

Browse files
authored
azure-identity docstrings (#6004)
1 parent e067646 commit 45a1aee

File tree

8 files changed

+287
-22
lines changed

8 files changed

+287
-22
lines changed

sdk/identity/azure-identity/azure/identity/__init__.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See LICENSE.txt in the project root for
44
# license information.
5-
# --------------------------------------------------------------------------
5+
# -------------------------------------------------------------------------
66
from .credentials import (
77
CertificateCredential,
88
ClientSecretCredential,
@@ -13,7 +13,15 @@
1313

1414

1515
class DefaultAzureCredential(ChainedTokenCredential):
16-
"""default credential is environment followed by MSI/IMDS"""
16+
"""
17+
A default credential capable of handling most Azure SDK authentication scenarios.
18+
19+
When environment variable configuration is present, it authenticates as a service principal
20+
using :class:`identity.EnvironmentCredential`.
21+
22+
When environment configuration is not present, it authenticates with a managed identity
23+
using :class:`identity.ManagedIdentityCredential`.
24+
"""
1725

1826
def __init__(self, **kwargs):
1927
super(DefaultAzureCredential, self).__init__(

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ def _prepare_request(self, method="POST", headers=None, form_data=None, params=N
112112

113113

114114
class AuthnClient(AuthnClientBase):
115-
"""Synchronous authentication client"""
115+
"""
116+
Synchronous authentication client.
117+
118+
:param str auth_url:
119+
:param config: Optional configuration for the HTTP pipeline.
120+
:type config: :class:`azure.core.configuration`
121+
:param policies: Optional policies for the HTTP pipeline.
122+
:type policies:
123+
:param transport: Optional HTTP transport.
124+
:type transport:
125+
"""
116126

117127
def __init__(self, auth_url, config=None, policies=None, transport=None, **kwargs):
118128
# type: (str, Optional[Configuration], Optional[Iterable[HTTPPolicy]], Optional[HttpTransport], Mapping[str, Any]) -> None

sdk/identity/azure-identity/azure/identity/_base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See LICENSE.txt in the project root for
44
# license information.
5-
# --------------------------------------------------------------------------
5+
# -------------------------------------------------------------------------
66
import binascii
77

88
from cryptography import x509
@@ -23,6 +23,8 @@
2323

2424

2525
class ClientSecretCredentialBase(object):
26+
"""Sans I/O base for client secret credentials"""
27+
2628
def __init__(self, client_id, secret, tenant_id, **kwargs):
2729
# type: (str, str, str, Mapping[str, Any]) -> None
2830
if not client_id:
@@ -38,6 +40,8 @@ def __init__(self, client_id, secret, tenant_id, **kwargs):
3840

3941

4042
class CertificateCredentialBase(object):
43+
"""Sans I/O base for certificate credentials"""
44+
4145
def __init__(self, client_id, tenant_id, certificate_path, **kwargs):
4246
# type: (str, str, str, Mapping[str, Any]) -> None
4347
if not certificate_path:

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

+34-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
class _ManagedIdentityBase(object):
27+
"""Sans I/O base for managed identity credentials"""
28+
2729
def __init__(self, endpoint, client_cls, config=None, client_id=None, **kwargs):
2830
# type: (str, Type, Optional[Configuration], Optional[str], Any) -> None
2931
self._client_id = client_id
@@ -34,6 +36,11 @@ def __init__(self, endpoint, client_cls, config=None, client_id=None, **kwargs):
3436
@staticmethod
3537
def create_config(**kwargs):
3638
# type: (Mapping[str, Any]) -> Configuration
39+
"""
40+
Build a default configuration for the credential's HTTP pipeline.
41+
42+
:rtype: :class:`azure.core.configuration`
43+
"""
3744
timeout = kwargs.pop("connection_timeout", 2)
3845
config = Configuration(connection_timeout=timeout, **kwargs)
3946

@@ -61,7 +68,12 @@ def create_config(**kwargs):
6168

6269

6370
class ImdsCredential(_ManagedIdentityBase):
64-
"""Authenticates with a managed identity via the IMDS endpoint"""
71+
"""
72+
Authenticates with a managed identity via the IMDS endpoint.
73+
74+
:param config: optional configuration for the underlying HTTP pipeline
75+
:type config: :class:`azure.core.configuration`
76+
"""
6577

6678
def __init__(self, config=None, **kwargs):
6779
# type: (Optional[Configuration], Any) -> None
@@ -70,6 +82,13 @@ def __init__(self, config=None, **kwargs):
7082

7183
def get_token(self, *scopes):
7284
# type: (*str) -> AccessToken
85+
"""
86+
Request an access token for `scopes`.
87+
88+
:param str scopes: desired scopes for the token
89+
:rtype: :class:`azure.core.credentials.AccessToken`
90+
:raises: :class:`azure.core.exceptions.ClientAuthenticationError`
91+
"""
7392
if self._endpoint_available is None:
7493
# Lacking another way to determine whether the IMDS endpoint is listening,
7594
# we send a request it would immediately reject (missing a required header),
@@ -103,7 +122,12 @@ def get_token(self, *scopes):
103122

104123

105124
class MsiCredential(_ManagedIdentityBase):
106-
"""Authenticates via the MSI endpoint in App Service or Cloud Shell"""
125+
"""
126+
Authenticates via the MSI endpoint in an App Service or Cloud Shell environment.
127+
128+
:param config: optional configuration for the underlying HTTP pipeline
129+
:type config: :class:`azure.core.configuration`
130+
"""
107131

108132
def __init__(self, config=None, **kwargs):
109133
# type: (Optional[Configuration], Mapping[str, Any]) -> None
@@ -116,6 +140,14 @@ def __init__(self, config=None, **kwargs):
116140

117141
def get_token(self, *scopes):
118142
# type: (*str) -> AccessToken
143+
"""
144+
Request an access token for `scopes`.
145+
146+
:param str scopes: desired scopes for the token
147+
:rtype: :class:`azure.core.credentials.AccessToken`
148+
:raises: :class:`azure.core.exceptions.ClientAuthenticationError`
149+
"""
150+
119151
if not self._endpoint_available:
120152
raise ClientAuthenticationError(message="MSI endpoint unavailable")
121153

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313

1414

1515
class AsyncDefaultAzureCredential(AsyncChainedTokenCredential):
16-
"""default credential is environment followed by MSI/IMDS"""
16+
"""
17+
A default credential capable of handling most Azure SDK authentication scenarios.
18+
19+
When environment variable configuration is present, it authenticates as a service principal
20+
using :class:`identity.aio.AsyncEnvironmentCredential`.
21+
22+
When environment configuration is not present, it authenticates with a managed identity
23+
using :class:`identity.aio.AsyncManagedIdentityCredential`.
24+
"""
1725

1826
def __init__(self, **kwargs):
1927
super().__init__(AsyncEnvironmentCredential(**kwargs), AsyncManagedIdentityCredential(**kwargs))

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

+33
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,34 @@ def __init__(self, endpoint: str, config: Optional[Configuration] = None, **kwar
2222

2323
@staticmethod
2424
def create_config(**kwargs: Any) -> Configuration: # type: ignore
25+
"""
26+
Build a default configuration for the credential's HTTP pipeline.
27+
28+
:rtype: :class:`azure.core.configuration`
29+
"""
2530
return _ManagedIdentityBase.create_config(retry_policy=AsyncRetryPolicy, **kwargs)
2631

2732

2833
class AsyncImdsCredential(_AsyncManagedIdentityBase):
34+
"""
35+
Asynchronously authenticates with a managed identity via the IMDS endpoint.
36+
37+
:param config: optional configuration for the underlying HTTP pipeline
38+
:type config: :class:`azure.core.configuration`
39+
"""
40+
2941
def __init__(self, config: Optional[Configuration] = None, **kwargs: Any) -> None:
3042
super().__init__(endpoint=Endpoints.IMDS, config=config, **kwargs)
3143
self._endpoint_available = None # type: Optional[bool]
3244

3345
async def get_token(self, *scopes: str) -> AccessToken:
46+
"""
47+
Asynchronously request an access token for `scopes`.
48+
49+
:param str scopes: desired scopes for the token
50+
:rtype: :class:`azure.core.credentials.AccessToken`
51+
:raises: :class:`azure.core.exceptions.ClientAuthenticationError`
52+
"""
3453
if self._endpoint_available is None:
3554
# Lacking another way to determine whether the IMDS endpoint is listening,
3655
# we send a request it would immediately reject (missing a required header),
@@ -65,13 +84,27 @@ async def get_token(self, *scopes: str) -> AccessToken:
6584

6685

6786
class AsyncMsiCredential(_AsyncManagedIdentityBase):
87+
"""
88+
Authenticates via the MSI endpoint in an App Service or Cloud Shell environment.
89+
90+
:param config: optional configuration for the underlying HTTP pipeline
91+
:type config: :class:`azure.core.configuration`
92+
"""
93+
6894
def __init__(self, config: Optional[Configuration] = None, **kwargs: Any) -> None:
6995
endpoint = os.environ.get(EnvironmentVariables.MSI_ENDPOINT)
7096
self._endpoint_available = endpoint is not None
7197
if self._endpoint_available:
7298
super().__init__(endpoint=endpoint, config=config, **kwargs) # type: ignore
7399

74100
async def get_token(self, *scopes: str) -> AccessToken:
101+
"""
102+
Asynchronously request an access token for `scopes`.
103+
104+
:param str scopes: desired scopes for the token
105+
:rtype: :class:`azure.core.credentials.AccessToken`
106+
:raises: :class:`azure.core.exceptions.ClientAuthenticationError`
107+
"""
75108
if not self._endpoint_available:
76109
raise ClientAuthenticationError(message="MSI endpoint unavailable")
77110

0 commit comments

Comments
 (0)