Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError for ManagedIdentityCredential when using service principal credentials #49

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Changes from 3 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
20 changes: 14 additions & 6 deletions src/saltext/azurerm/utils/azurerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ def _determine_auth(**kwargs):
)

try:
credentials = DefaultAzureCredential(authority=authority, **kwargs)
if "client_id" in kwargs and "tenant" in kwargs and "secret" in kwargs:
credentials = get_identity_credentials(**kwargs)
else:
credentials = DefaultAzureCredential(authority=authority, **kwargs)
except ClientAuthenticationError:
raise SaltInvocationError( # pylint: disable=raise-missing-from
raise SaltInvocationError(
"Unable to determine credentials. "
"A subscription_id with username and password, "
"or client_id, secret, and tenant or a profile with the "
"required parameters populated"
)
) from None
M3GH4NN marked this conversation as resolved.
Show resolved Hide resolved

try:
subscription_id = salt.utils.stringutils.to_str(kwargs["subscription_id"])
except KeyError:
Expand Down Expand Up @@ -174,7 +178,6 @@ def get_client(client_type, **kwargs):
base_url=cloud_env.endpoints.resource_manager,
user_agent_policy=user_agent,
)

M3GH4NN marked this conversation as resolved.
Show resolved Hide resolved
return client


Expand Down Expand Up @@ -332,7 +335,6 @@ def get_identity_credentials(**kwargs):
for keyword, value in kwarg_map.items():
if kwargs.get(keyword):
os.environ[value] = kwargs[keyword]

M3GH4NN marked this conversation as resolved.
Show resolved Hide resolved
try:
if kwargs.get("cloud_environment") and kwargs.get("cloud_environment").startswith("http"):
authority = kwargs["cloud_environment"]
Expand All @@ -341,10 +343,16 @@ def get_identity_credentials(**kwargs):
KnownAuthorities, kwargs.get("cloud_environment", "AZURE_PUBLIC_CLOUD")
)
log.debug("AUTHORITY: %s", authority)
M3GH4NN marked this conversation as resolved.
Show resolved Hide resolved

M3GH4NN marked this conversation as resolved.
Show resolved Hide resolved
except AttributeError as exc:
log.error('Unknown authority presented for "cloud_environment": %s', exc)
authority = KnownAuthorities.AZURE_PUBLIC_CLOUD

credential = DefaultAzureCredential(authority=authority)
try:
credential = DefaultAzureCredential(authority=authority)
except ClientAuthenticationError:
raise SaltInvocationError( # pylint: disable=raise-missing-from
"Unable to determine credentials. "
)

return credential
Loading