Skip to content

Commit

Permalink
Merge branch 'release-1.31.1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rayluo committed Nov 21, 2024
2 parents 7826ea8 + 69a96fe commit ec3c500
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


# The __init__.py will import this. Not the other way around.
__version__ = "1.31.0" # When releasing, also check and bump our dependencies's versions if needed
__version__ = "1.31.1" # When releasing, also check and bump our dependencies's versions if needed

logger = logging.getLogger(__name__)
_AUTHORITY_TYPE_CLOUDSHELL = "CLOUDSHELL"
Expand Down
8 changes: 5 additions & 3 deletions msal/managed_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,12 @@ def _scope_to_resource(scope): # This is an experimental reasonable-effort appr
def _get_arc_endpoint():
if "IDENTITY_ENDPOINT" in os.environ and "IMDS_ENDPOINT" in os.environ:
return os.environ["IDENTITY_ENDPOINT"]
if ( # Defined in https://msazure.visualstudio.com/One/_wiki/wikis/One.wiki/233012/VM-Extension-Authoring-for-Arc?anchor=determining-which-endpoint-to-use
sys.platform == "linux" and os.path.exists("/var/opt/azcmagent/bin/himds")
if ( # Defined in https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/hybrid-resource-provider/azure-arc-for-servers/specs/extension_authoring
sys.platform == "linux" and os.path.exists("/opt/azcmagent/bin/himds")
or sys.platform == "win32" and os.path.exists(os.path.expandvars(
r"%ProgramFiles%\AzureConnectedMachineAgent\himds.exe"))
# Avoid Windows-only "%EnvVar%" syntax so that tests can be run on Linux
r"${ProgramFiles}\AzureConnectedMachineAgent\himds.exe"
))
):
return "http://localhost:40342/metadata/identity/oauth2/token"

Expand Down
16 changes: 15 additions & 1 deletion tests/test_mi.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,23 @@ def test_machine_learning(self):
"IDENTITY_ENDPOINT": "http://localhost",
"IMDS_ENDPOINT": "http://localhost",
})
def test_arc(self):
def test_arc_by_env_var(self):
self.assertEqual(get_managed_identity_source(), AZURE_ARC)

@patch("msal.managed_identity.os.path.exists", return_value=True)
@patch("msal.managed_identity.sys.platform", new="linux")
def test_arc_by_file_existence_on_linux(self, mocked_exists):
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
mocked_exists.assert_called_with("/opt/azcmagent/bin/himds")

@patch("msal.managed_identity.os.path.exists", return_value=True)
@patch("msal.managed_identity.sys.platform", new="win32")
@patch.dict(os.environ, {"ProgramFiles": "C:\Program Files"})
def test_arc_by_file_existence_on_windows(self, mocked_exists):
self.assertEqual(get_managed_identity_source(), AZURE_ARC)
mocked_exists.assert_called_with(
r"C:\Program Files\AzureConnectedMachineAgent\himds.exe")

@patch.dict(os.environ, {
"AZUREPS_HOST_ENVIRONMENT": "cloud-shell-foo",
})
Expand Down

0 comments on commit ec3c500

Please sign in to comment.