py2docfx 0.1.20rc2196756__py3-none-any.whl → 0.1.21__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. py2docfx/convert_prepare/get_source.py +1 -1
  2. py2docfx/convert_prepare/package_info.py +37 -27
  3. py2docfx/convert_prepare/tests/test_get_source.py +3 -1
  4. py2docfx/convert_prepare/tests/test_package_info.py +159 -1
  5. py2docfx/docfx_yaml/build_finished.py +1 -1
  6. py2docfx/docfx_yaml/logger.py +42 -28
  7. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/api.py +3 -2
  8. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/legacy.py +17 -1
  9. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/version.py +1 -1
  10. py2docfx/venv/basevenv/Lib/site-packages/requests/__version__.py +2 -2
  11. py2docfx/venv/basevenv/Lib/site-packages/requests/adapters.py +17 -40
  12. py2docfx/venv/basevenv/Lib/site-packages/requests/sessions.py +1 -1
  13. py2docfx/venv/venv1/Lib/site-packages/azure/core/_version.py +1 -1
  14. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_authentication.py +21 -9
  15. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_authentication_async.py +21 -9
  16. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_retry.py +1 -1
  17. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_bearer_token_provider.py +1 -1
  18. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
  19. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +82 -17
  20. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +28 -5
  21. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +28 -4
  22. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/broker.py +79 -0
  23. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +9 -3
  24. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +153 -53
  25. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +25 -1
  26. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/shared_cache.py +12 -5
  27. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/vscode.py +163 -144
  28. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/workload_identity.py +23 -12
  29. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +4 -0
  30. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +14 -2
  31. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/pipeline.py +4 -2
  32. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +96 -0
  33. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  34. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_bearer_token_provider.py +3 -3
  35. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/authorization_code.py +1 -1
  36. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +32 -13
  37. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +26 -5
  38. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_powershell.py +13 -2
  39. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/chained.py +1 -1
  40. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +120 -55
  41. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +27 -1
  42. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/on_behalf_of.py +1 -1
  43. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/shared_cache.py +12 -5
  44. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/vscode.py +15 -67
  45. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/workload_identity.py +17 -13
  46. py2docfx/venv/venv1/Lib/site-packages/cffi/__init__.py +2 -2
  47. py2docfx/venv/venv1/Lib/site-packages/cffi/cparser.py +1 -1
  48. py2docfx/venv/venv1/Lib/site-packages/cffi/recompiler.py +5 -5
  49. py2docfx/venv/venv1/Lib/site-packages/cffi/setuptools_ext.py +13 -0
  50. py2docfx/venv/venv1/Lib/site-packages/cffi/vengine_cpy.py +3 -0
  51. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/api.py +3 -2
  52. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/legacy.py +17 -1
  53. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/version.py +1 -1
  54. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
  55. py2docfx/venv/venv1/Lib/site-packages/cryptography/__init__.py +0 -13
  56. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/_oid.py +8 -0
  57. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/asn1/__init__.py +10 -0
  58. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/asn1/asn1.py +116 -0
  59. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/backends/openssl/backend.py +3 -9
  60. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/declarative_asn1.pyi +32 -0
  61. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi +23 -0
  62. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi +1 -13
  63. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py +16 -0
  64. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/binding.py +16 -1
  65. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py +0 -2
  66. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +8 -0
  67. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py +0 -47
  68. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py +6 -91
  69. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py +1 -3
  70. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/ssh.py +1 -1
  71. py2docfx/venv/venv1/Lib/site-packages/cryptography/utils.py +0 -2
  72. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/name.py +2 -3
  73. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/__init__.py +1 -1
  74. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/any_pb2.py +2 -2
  75. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/api_pb2.py +12 -8
  76. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/compiler/plugin_pb2.py +2 -2
  77. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor.py +398 -246
  78. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pb2.py +74 -72
  79. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pool.py +5 -4
  80. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/duration_pb2.py +2 -2
  81. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/empty_pb2.py +2 -2
  82. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/field_mask_pb2.py +2 -2
  83. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/api_implementation.py +0 -6
  84. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/extension_dict.py +3 -3
  85. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/field_mask.py +3 -3
  86. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_edition_defaults.py +1 -1
  87. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_message.py +10 -2
  88. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/type_checkers.py +47 -5
  89. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/json_format.py +55 -32
  90. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/runtime_version.py +6 -26
  91. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/source_context_pb2.py +2 -2
  92. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/struct_pb2.py +2 -2
  93. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/text_format.py +30 -19
  94. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/timestamp_pb2.py +2 -2
  95. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/type_pb2.py +2 -2
  96. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/wrappers_pb2.py +2 -2
  97. py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +39 -19
  98. py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +3 -5
  99. py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +1 -2
  100. py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +53 -78
  101. py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +55 -38
  102. py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +40 -12
  103. py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +0 -1
  104. py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +1 -2
  105. py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +33 -13
  106. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +185 -122
  107. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__main__.py +2 -3
  108. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +5 -10
  109. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +3 -4
  110. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +41 -45
  111. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +35 -38
  112. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +4 -8
  113. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +6 -12
  114. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +17 -8
  115. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +29 -17
  116. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +74 -75
  117. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +11 -13
  118. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +2 -3
  119. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sudo.py +117 -0
  120. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +21 -31
  121. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -23
  122. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +15 -8
  123. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +65 -33
  124. py2docfx/venv/venv1/Lib/site-packages/pycparser/__init__.py +1 -1
  125. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_generator.py +1 -1
  126. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_lexer.py +14 -0
  127. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_parser.py +30 -7
  128. py2docfx/venv/venv1/Lib/site-packages/pycparser/lextab.py +1 -1
  129. py2docfx/venv/venv1/Lib/site-packages/pycparser/yacctab.py +132 -127
  130. py2docfx/venv/venv1/Lib/site-packages/requests/__version__.py +2 -2
  131. py2docfx/venv/venv1/Lib/site-packages/requests/adapters.py +17 -40
  132. py2docfx/venv/venv1/Lib/site-packages/requests/sessions.py +1 -1
  133. py2docfx/venv/venv1/Lib/site-packages/typing_extensions.py +91 -18
  134. {py2docfx-0.1.20rc2196756.dist-info → py2docfx-0.1.21.dist-info}/METADATA +1 -1
  135. {py2docfx-0.1.20rc2196756.dist-info → py2docfx-0.1.21.dist-info}/RECORD +137 -135
  136. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/linux_vscode_adapter.py +0 -100
  137. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/macos_vscode_adapter.py +0 -34
  138. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/win_vscode_adapter.py +0 -77
  139. {py2docfx-0.1.20rc2196756.dist-info → py2docfx-0.1.21.dist-info}/WHEEL +0 -0
  140. {py2docfx-0.1.20rc2196756.dist-info → py2docfx-0.1.21.dist-info}/top_level.txt +0 -0
@@ -6,10 +6,18 @@ import logging
6
6
  import os
7
7
  from typing import List, Any, Optional, cast
8
8
 
9
- from azure.core.credentials import AccessToken, AccessTokenInfo, TokenRequestOptions, SupportsTokenInfo, TokenCredential
9
+ from azure.core.credentials import (
10
+ AccessToken,
11
+ AccessTokenInfo,
12
+ TokenRequestOptions,
13
+ SupportsTokenInfo,
14
+ TokenCredential,
15
+ )
16
+ from .. import CredentialUnavailableError
10
17
  from .._constants import EnvironmentVariables
11
- from .._internal import get_default_authority, normalize_authority, within_dac
18
+ from .._internal.utils import get_default_authority, normalize_authority, within_dac, process_credential_exclusions
12
19
  from .azure_powershell import AzurePowerShellCredential
20
+ from .broker import BrokerCredential
13
21
  from .browser import InteractiveBrowserCredential
14
22
  from .chained import ChainedTokenCredential
15
23
  from .environment import EnvironmentCredential
@@ -23,6 +31,32 @@ from .workload_identity import WorkloadIdentityCredential
23
31
  _LOGGER = logging.getLogger(__name__)
24
32
 
25
33
 
34
+ class FailedDACCredential:
35
+ """This acts as a substitute for a credential that has failed to initialize in the DAC chain.
36
+
37
+ This allows instantiation errors to be reported in ChainTokenCredential if all token requests fail.
38
+ """
39
+
40
+ def __init__(self, credential_name: str, error: str) -> None:
41
+ self._error = error
42
+ self._credential_name = credential_name
43
+
44
+ def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken:
45
+ raise CredentialUnavailableError(self._error)
46
+
47
+ def get_token_info(self, *scopes, options: Optional[TokenRequestOptions] = None, **kwargs: Any) -> AccessTokenInfo:
48
+ raise CredentialUnavailableError(self._error)
49
+
50
+ def __enter__(self) -> "FailedDACCredential":
51
+ return self
52
+
53
+ def __exit__(self, *args: Any) -> None:
54
+ pass
55
+
56
+ def close(self) -> None:
57
+ pass
58
+
59
+
26
60
  class DefaultAzureCredential(ChainedTokenCredential):
27
61
  """A credential capable of handling most Azure SDK authentication scenarios. For more information, See
28
62
  `Usage guidance for DefaultAzureCredential
@@ -42,6 +76,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
42
76
  5. The identity currently logged in to the Azure CLI.
43
77
  6. The identity currently logged in to Azure PowerShell.
44
78
  7. The identity currently logged in to the Azure Developer CLI.
79
+ 8. Brokered authentication. On Windows and WSL only, this uses the default account logged in via
80
+ Web Account Manager (WAM) if the `azure-identity-broker` package is installed.
45
81
 
46
82
  This default behavior is configurable with keyword arguments.
47
83
 
@@ -64,9 +100,13 @@ class DefaultAzureCredential(ChainedTokenCredential):
64
100
  **False**.
65
101
  :keyword bool exclude_interactive_browser_credential: Whether to exclude interactive browser authentication (see
66
102
  :class:`~azure.identity.InteractiveBrowserCredential`). Defaults to **True**.
103
+ :keyword bool exclude_broker_credential: Whether to exclude the broker credential from the credential chain.
104
+ Defaults to **False**.
67
105
  :keyword str interactive_browser_tenant_id: Tenant ID to use when authenticating a user through
68
106
  :class:`~azure.identity.InteractiveBrowserCredential`. Defaults to the value of environment variable
69
107
  AZURE_TENANT_ID, if any. If unspecified, users will authenticate in their home tenants.
108
+ :keyword str broker_tenant_id: The tenant ID to use when using brokered authentication. Defaults to the value of
109
+ environment variable AZURE_TENANT_ID, if any. If unspecified, users will authenticate in their home tenants.
70
110
  :keyword str managed_identity_client_id: The client ID of a user-assigned managed identity. Defaults to the value
71
111
  of the environment variable AZURE_CLIENT_ID, if any. If not specified, a system-assigned identity will be used.
72
112
  :keyword str workload_identity_client_id: The client ID of an identity assigned to the pod. Defaults to the value
@@ -75,16 +115,20 @@ class DefaultAzureCredential(ChainedTokenCredential):
75
115
  Defaults to the value of environment variable AZURE_TENANT_ID, if any.
76
116
  :keyword str interactive_browser_client_id: The client ID to be used in interactive browser credential. If not
77
117
  specified, users will authenticate to an Azure development application.
118
+ :keyword str broker_client_id: The client ID to be used in brokered authentication. If not specified, users will
119
+ authenticate to an Azure development application.
78
120
  :keyword str shared_cache_username: Preferred username for :class:`~azure.identity.SharedTokenCacheCredential`.
79
121
  Defaults to the value of environment variable AZURE_USERNAME, if any.
80
122
  :keyword str shared_cache_tenant_id: Preferred tenant for :class:`~azure.identity.SharedTokenCacheCredential`.
81
123
  Defaults to the value of environment variable AZURE_TENANT_ID, if any.
82
124
  :keyword str visual_studio_code_tenant_id: Tenant ID to use when authenticating with
83
- :class:`~azure.identity.VisualStudioCodeCredential`. Defaults to the "Azure: Tenant" setting in VS Code's user
84
- settings or, when that setting has no value, the "organizations" tenant, which supports only Azure Active
85
- Directory work or school accounts.
125
+ :class:`~azure.identity.VisualStudioCodeCredential`. Defaults to the tenant specified in the authentication
126
+ record file used by the Azure Resources extension.
86
127
  :keyword int process_timeout: The timeout in seconds to use for developer credentials that run
87
128
  subprocesses (e.g. AzureCliCredential, AzurePowerShellCredential). Defaults to **10** seconds.
129
+ :keyword bool require_envvar: If **True**, require that the AZURE_TOKEN_CREDENTIALS environment variable be set
130
+ to a value denoting the credential type or credential group to use. If unset or empty, DefaultAzureCredential
131
+ will raise a `ValueError`. Defaults to **False**.
88
132
 
89
133
  .. admonition:: Example:
90
134
 
@@ -101,18 +145,10 @@ class DefaultAzureCredential(ChainedTokenCredential):
101
145
  raise TypeError("'tenant_id' is not supported in DefaultAzureCredential.")
102
146
 
103
147
  authority = kwargs.pop("authority", None)
104
-
105
- vscode_tenant_id = kwargs.pop(
106
- "visual_studio_code_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
107
- )
108
- vscode_args = dict(kwargs)
109
- if authority:
110
- vscode_args["authority"] = authority
111
- if vscode_tenant_id:
112
- vscode_args["tenant_id"] = vscode_tenant_id
113
-
114
148
  authority = normalize_authority(authority) if authority else get_default_authority()
115
149
 
150
+ vscode_tenant_id = kwargs.pop("visual_studio_code_tenant_id", None)
151
+
116
152
  interactive_browser_tenant_id = kwargs.pop(
117
153
  "interactive_browser_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
118
154
  )
@@ -126,59 +162,113 @@ class DefaultAzureCredential(ChainedTokenCredential):
126
162
  )
127
163
  interactive_browser_client_id = kwargs.pop("interactive_browser_client_id", None)
128
164
 
165
+ broker_tenant_id = kwargs.pop("broker_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID))
166
+ broker_client_id = kwargs.pop("broker_client_id", None)
167
+
129
168
  shared_cache_username = kwargs.pop("shared_cache_username", os.environ.get(EnvironmentVariables.AZURE_USERNAME))
130
169
  shared_cache_tenant_id = kwargs.pop(
131
170
  "shared_cache_tenant_id", os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
132
171
  )
133
172
 
134
173
  process_timeout = kwargs.pop("process_timeout", 10)
135
-
136
- token_credentials_env = os.environ.get(EnvironmentVariables.AZURE_TOKEN_CREDENTIALS, "").strip().lower()
137
- exclude_workload_identity_credential = kwargs.pop("exclude_workload_identity_credential", False)
138
- exclude_environment_credential = kwargs.pop("exclude_environment_credential", False)
139
- exclude_managed_identity_credential = kwargs.pop("exclude_managed_identity_credential", False)
140
- exclude_shared_token_cache_credential = kwargs.pop("exclude_shared_token_cache_credential", False)
141
- exclude_visual_studio_code_credential = kwargs.pop("exclude_visual_studio_code_credential", True)
142
- exclude_developer_cli_credential = kwargs.pop("exclude_developer_cli_credential", False)
143
- exclude_cli_credential = kwargs.pop("exclude_cli_credential", False)
144
- exclude_interactive_browser_credential = kwargs.pop("exclude_interactive_browser_credential", True)
145
- exclude_powershell_credential = kwargs.pop("exclude_powershell_credential", False)
146
-
147
- if token_credentials_env == "dev":
148
- # In dev mode, use only developer credentials
149
- exclude_environment_credential = True
150
- exclude_managed_identity_credential = True
151
- exclude_workload_identity_credential = True
152
- elif token_credentials_env == "prod":
153
- # In prod mode, use only production credentials
154
- exclude_shared_token_cache_credential = True
155
- exclude_visual_studio_code_credential = True
156
- exclude_cli_credential = True
157
- exclude_developer_cli_credential = True
158
- exclude_powershell_credential = True
159
- exclude_interactive_browser_credential = True
160
- elif token_credentials_env != "":
161
- # If the environment variable is set to something other than dev or prod, raise an error
174
+ require_envvar = kwargs.pop("require_envvar", False)
175
+ if require_envvar and not os.environ.get(EnvironmentVariables.AZURE_TOKEN_CREDENTIALS):
162
176
  raise ValueError(
163
- f"Invalid value for {EnvironmentVariables.AZURE_TOKEN_CREDENTIALS}: {token_credentials_env}. "
164
- "Valid values are 'dev' or 'prod'."
177
+ "AZURE_TOKEN_CREDENTIALS environment variable is required but is not set or is empty. "
178
+ "Set it to 'dev', 'prod', or a specific credential name."
165
179
  )
166
180
 
181
+ # Define credential configuration mapping
182
+ credential_config = {
183
+ "environment": {
184
+ "exclude_param": "exclude_environment_credential",
185
+ "env_name": "environmentcredential",
186
+ "default_exclude": False,
187
+ },
188
+ "workload_identity": {
189
+ "exclude_param": "exclude_workload_identity_credential",
190
+ "env_name": "workloadidentitycredential",
191
+ "default_exclude": False,
192
+ },
193
+ "managed_identity": {
194
+ "exclude_param": "exclude_managed_identity_credential",
195
+ "env_name": "managedidentitycredential",
196
+ "default_exclude": False,
197
+ },
198
+ "shared_token_cache": {
199
+ "exclude_param": "exclude_shared_token_cache_credential",
200
+ "default_exclude": False,
201
+ },
202
+ "visual_studio_code": {
203
+ "exclude_param": "exclude_visual_studio_code_credential",
204
+ "env_name": "visualstudiocodecredential",
205
+ "default_exclude": False,
206
+ },
207
+ "cli": {
208
+ "exclude_param": "exclude_cli_credential",
209
+ "env_name": "azureclicredential",
210
+ "default_exclude": False,
211
+ },
212
+ "developer_cli": {
213
+ "exclude_param": "exclude_developer_cli_credential",
214
+ "env_name": "azuredeveloperclicredential",
215
+ "default_exclude": False,
216
+ },
217
+ "powershell": {
218
+ "exclude_param": "exclude_powershell_credential",
219
+ "env_name": "azurepowershellcredential",
220
+ "default_exclude": False,
221
+ },
222
+ "interactive_browser": {
223
+ "exclude_param": "exclude_interactive_browser_credential",
224
+ "env_name": "interactivebrowsercredential",
225
+ "default_exclude": True,
226
+ },
227
+ "broker": {
228
+ "exclude_param": "exclude_broker_credential",
229
+ "default_exclude": False,
230
+ },
231
+ }
232
+
233
+ # Extract user-provided exclude flags and set defaults
234
+ exclude_flags = {}
235
+ user_excludes = {}
236
+ for cred_key, config in credential_config.items():
237
+ param_name = cast(str, config["exclude_param"])
238
+ user_excludes[cred_key] = kwargs.pop(param_name, None)
239
+ exclude_flags[cred_key] = config["default_exclude"]
240
+
241
+ # Process AZURE_TOKEN_CREDENTIALS environment variable and apply user overrides
242
+ exclude_flags = process_credential_exclusions(credential_config, exclude_flags, user_excludes)
243
+
244
+ # Extract individual exclude flags for backward compatibility
245
+ exclude_environment_credential = exclude_flags["environment"]
246
+ exclude_workload_identity_credential = exclude_flags["workload_identity"]
247
+ exclude_managed_identity_credential = exclude_flags["managed_identity"]
248
+ exclude_shared_token_cache_credential = exclude_flags["shared_token_cache"]
249
+ exclude_visual_studio_code_credential = exclude_flags["visual_studio_code"]
250
+ exclude_cli_credential = exclude_flags["cli"]
251
+ exclude_developer_cli_credential = exclude_flags["developer_cli"]
252
+ exclude_powershell_credential = exclude_flags["powershell"]
253
+ exclude_interactive_browser_credential = exclude_flags["interactive_browser"]
254
+ exclude_broker_credential = exclude_flags["broker"]
255
+
167
256
  credentials: List[SupportsTokenInfo] = []
168
257
  within_dac.set(True)
169
258
  if not exclude_environment_credential:
170
259
  credentials.append(EnvironmentCredential(authority=authority, _within_dac=True, **kwargs))
171
260
  if not exclude_workload_identity_credential:
172
- if all(os.environ.get(var) for var in EnvironmentVariables.WORKLOAD_IDENTITY_VARS):
173
- client_id = workload_identity_client_id
261
+ try:
174
262
  credentials.append(
175
263
  WorkloadIdentityCredential(
176
- client_id=cast(str, client_id),
264
+ client_id=cast(str, workload_identity_client_id),
177
265
  tenant_id=workload_identity_tenant_id,
178
- token_file_path=os.environ[EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE],
266
+ token_file_path=os.environ.get(EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE),
179
267
  **kwargs,
180
268
  )
181
269
  )
270
+ except ValueError as ex:
271
+ credentials.append(FailedDACCredential("WorkloadIdentityCredential", error=str(ex)))
182
272
  if not exclude_managed_identity_credential:
183
273
  credentials.append(
184
274
  ManagedIdentityCredential(
@@ -197,7 +287,7 @@ class DefaultAzureCredential(ChainedTokenCredential):
197
287
  except Exception as ex: # pylint:disable=broad-except
198
288
  _LOGGER.info("Shared token cache is unavailable: '%s'", ex)
199
289
  if not exclude_visual_studio_code_credential:
200
- credentials.append(VisualStudioCodeCredential(**vscode_args))
290
+ credentials.append(VisualStudioCodeCredential(tenant_id=vscode_tenant_id))
201
291
  if not exclude_cli_credential:
202
292
  credentials.append(AzureCliCredential(process_timeout=process_timeout))
203
293
  if not exclude_powershell_credential:
@@ -213,6 +303,12 @@ class DefaultAzureCredential(ChainedTokenCredential):
213
303
  )
214
304
  else:
215
305
  credentials.append(InteractiveBrowserCredential(tenant_id=interactive_browser_tenant_id, **kwargs))
306
+ if not exclude_broker_credential:
307
+ broker_credential_args = {"tenant_id": broker_tenant_id, **kwargs}
308
+ if broker_client_id:
309
+ broker_credential_args["client_id"] = broker_client_id
310
+ credentials.append(BrokerCredential(**broker_credential_args))
311
+
216
312
  within_dac.set(False)
217
313
  super(DefaultAzureCredential, self).__init__(*credentials)
218
314
 
@@ -245,8 +341,10 @@ class DefaultAzureCredential(ChainedTokenCredential):
245
341
  )
246
342
  return token
247
343
  within_dac.set(True)
248
- token = super().get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
249
- within_dac.set(False)
344
+ try:
345
+ token = super().get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
346
+ finally:
347
+ within_dac.set(False)
250
348
  return token
251
349
 
252
350
  def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
@@ -274,6 +372,8 @@ class DefaultAzureCredential(ChainedTokenCredential):
274
372
  return token_info
275
373
 
276
374
  within_dac.set(True)
277
- token_info = cast(SupportsTokenInfo, super()).get_token_info(*scopes, options=options)
278
- within_dac.set(False)
375
+ try:
376
+ token_info = cast(SupportsTokenInfo, super()).get_token_info(*scopes, options=options)
377
+ finally:
378
+ within_dac.set(False)
279
379
  return token_info
@@ -6,9 +6,11 @@ import os
6
6
  import json
7
7
  from typing import Any, Optional, Dict
8
8
 
9
+ from azure.core.pipeline import PipelineResponse
9
10
  from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
10
11
  from azure.core.pipeline.transport import HttpRequest
11
12
  from azure.core.credentials import AccessTokenInfo
13
+ from azure.core.pipeline.policies import RetryPolicy
12
14
 
13
15
  from .. import CredentialUnavailableError
14
16
  from .._constants import EnvironmentVariables
@@ -31,6 +33,28 @@ PIPELINE_SETTINGS = {
31
33
  }
32
34
 
33
35
 
36
+ class ImdsRetryPolicy(RetryPolicy):
37
+ """Custom retry policy for IMDS credential with extended retry duration for 410 responses.
38
+
39
+ This policy ensures that specifically for 410 status codes, the total exponential backoff duration
40
+ is at least 70 seconds to handle temporary IMDS endpoint unavailability.
41
+ For other status codes, it uses the standard retry behavior.
42
+ """
43
+
44
+ def __init__(self, **kwargs: Any) -> None:
45
+ # Increased backoff factor to ensure at least 70 seconds retry duration for 410 responses.
46
+ # Five retries, with each retry sleeping for [0.0s, 5.0s, 10.0s, 20.0s, 40.0s] between attempts (75s total)
47
+ self.backoff_factor_for_410 = 2.5
48
+ super().__init__(**kwargs)
49
+
50
+ def is_retry(self, settings: Dict[str, Any], response: PipelineResponse[Any, Any]) -> bool:
51
+ if response.http_response.status_code == 410:
52
+ settings["backoff"] = self.backoff_factor_for_410
53
+ else:
54
+ settings["backoff"] = self.backoff_factor
55
+ return super().is_retry(settings, response)
56
+
57
+
34
58
  def _get_request(scope: str, identity_config: Dict) -> HttpRequest:
35
59
  url = (
36
60
  os.environ.get(EnvironmentVariables.AZURE_POD_IDENTITY_AUTHORITY_HOST, IMDS_AUTHORITY).strip("/")
@@ -58,7 +82,7 @@ def _check_forbidden_response(ex: HttpResponseError) -> None:
58
82
 
59
83
  class ImdsCredential(MsalManagedIdentityClient):
60
84
  def __init__(self, **kwargs: Any) -> None:
61
- super(ImdsCredential, self).__init__(**kwargs)
85
+ super().__init__(retry_policy_class=ImdsRetryPolicy, **dict(PIPELINE_SETTINGS, **kwargs))
62
86
  self._config = kwargs
63
87
 
64
88
  if EnvironmentVariables.AZURE_POD_IDENTITY_AUTHORITY_HOST in os.environ:
@@ -8,7 +8,7 @@ from azure.core.credentials import AccessToken, TokenRequestOptions, AccessToken
8
8
  from .silent import SilentAuthenticationCredential
9
9
  from .. import CredentialUnavailableError
10
10
  from .._constants import DEVELOPER_SIGN_ON_CLIENT_ID
11
- from .._internal import AadClient, AadClientBase
11
+ from .._internal import AadClient, AadClientBase, within_dac
12
12
  from .._internal.decorators import log_get_token
13
13
  from .._internal.shared_token_cache import NO_TOKEN, SharedTokenCacheBase
14
14
 
@@ -191,10 +191,17 @@ class _SharedTokenCacheCredential(SharedTokenCacheBase):
191
191
 
192
192
  # try each refresh token, returning the first access token acquired
193
193
  for refresh_token in self._get_refresh_tokens(account, is_cae=is_cae):
194
- token = cast(AadClient, self._client).obtain_token_by_refresh_token(
195
- scopes, refresh_token, claims=claims, tenant_id=tenant_id, enable_cae=is_cae, **kwargs
196
- )
197
- return token
194
+ try:
195
+ token = cast(AadClient, self._client).obtain_token_by_refresh_token(
196
+ scopes, refresh_token, claims=claims, tenant_id=tenant_id, enable_cae=is_cae, **kwargs
197
+ )
198
+ return token
199
+ except Exception as e: # pylint: disable=broad-except
200
+ if within_dac.get():
201
+ raise CredentialUnavailableError( # pylint: disable=raise-missing-from
202
+ message=getattr(e, "message", str(e)), response=getattr(e, "response", None)
203
+ )
204
+ raise
198
205
 
199
206
  raise CredentialUnavailableError(message=NO_TOKEN.format(account.get("username")))
200
207