Blame SOURCES/bz2010652-fence_azure_arm-fix-sovereign-cloud-msi-support.patch

33dd94
From e339f304d4423a0e661d915f72ba88553b21d74a Mon Sep 17 00:00:00 2001
33dd94
From: MSSedusch <sedusch@microsoft.com>
33dd94
Date: Tue, 28 Sep 2021 12:23:37 +0000
33dd94
Subject: [PATCH 1/2] add support for sovereign clouds and MSI
33dd94
33dd94
---
33dd94
 lib/azure_fence.py.py | 14 ++++++++------
33dd94
 1 file changed, 8 insertions(+), 6 deletions(-)
33dd94
33dd94
diff --git a/lib/azure_fence.py.py b/lib/azure_fence.py.py
33dd94
index 1f38bd4ea..75b63fdad 100644
33dd94
--- a/lib/azure_fence.py.py
33dd94
+++ b/lib/azure_fence.py.py
33dd94
@@ -286,11 +286,11 @@ def get_azure_credentials(config):
33dd94
     credentials = None
33dd94
     cloud_environment = get_azure_cloud_environment(config)
33dd94
     if config.UseMSI and cloud_environment:
33dd94
-        from msrestazure.azure_active_directory import MSIAuthentication
33dd94
-        credentials = MSIAuthentication(cloud_environment=cloud_environment)
33dd94
+        from azure.identity import ManagedIdentityCredential
33dd94
+        credentials = ManagedIdentityCredential(cloud_environment=cloud_environment)
33dd94
     elif config.UseMSI:
33dd94
-        from msrestazure.azure_active_directory import MSIAuthentication
33dd94
-        credentials = MSIAuthentication()
33dd94
+        from azure.identity import ManagedIdentityCredential
33dd94
+        credentials = ManagedIdentityCredential()
33dd94
     elif cloud_environment:
33dd94
         try:
33dd94
             # try to use new libraries ClientSecretCredential (azure.identity, based on azure.core)
33dd94
@@ -340,7 +340,8 @@ def get_azure_compute_client(config):
33dd94
         compute_client = ComputeManagementClient(
33dd94
             credentials,
33dd94
             config.SubscriptionId,
33dd94
-            base_url=cloud_environment.endpoints.resource_manager
33dd94
+            base_url=cloud_environment.endpoints.resource_manager,
33dd94
+            credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
         )
33dd94
     else:
33dd94
         compute_client = ComputeManagementClient(
33dd94
@@ -359,7 +360,8 @@ def get_azure_network_client(config):
33dd94
         network_client = NetworkManagementClient(
33dd94
             credentials,
33dd94
             config.SubscriptionId,
33dd94
-            base_url=cloud_environment.endpoints.resource_manager
33dd94
+            base_url=cloud_environment.endpoints.resource_manager,
33dd94
+            credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
         )
33dd94
     else:
33dd94
         network_client = NetworkManagementClient(
33dd94
33dd94
From f08f02a7561e78dd9c95c66ccdcf6246c5ee7d6a Mon Sep 17 00:00:00 2001
33dd94
From: MSSedusch <sedusch@microsoft.com>
33dd94
Date: Fri, 1 Oct 2021 15:28:39 +0000
33dd94
Subject: [PATCH 2/2] compatiblity fix
33dd94
33dd94
---
33dd94
 lib/azure_fence.py.py | 54 ++++++++++++++++++++++++++++++-------------
33dd94
 1 file changed, 38 insertions(+), 16 deletions(-)
33dd94
33dd94
diff --git a/lib/azure_fence.py.py b/lib/azure_fence.py.py
33dd94
index 75b63fdad..5ca71eb42 100644
33dd94
--- a/lib/azure_fence.py.py
33dd94
+++ b/lib/azure_fence.py.py
33dd94
@@ -286,11 +286,19 @@ def get_azure_credentials(config):
33dd94
     credentials = None
33dd94
     cloud_environment = get_azure_cloud_environment(config)
33dd94
     if config.UseMSI and cloud_environment:
33dd94
-        from azure.identity import ManagedIdentityCredential
33dd94
-        credentials = ManagedIdentityCredential(cloud_environment=cloud_environment)
33dd94
+        try:
33dd94
+            from azure.identity import ManagedIdentityCredential
33dd94
+            credentials = ManagedIdentityCredential(cloud_environment=cloud_environment)
33dd94
+        except ImportError:
33dd94
+            from msrestazure.azure_active_directory import MSIAuthentication
33dd94
+            credentials = MSIAuthentication(cloud_environment=cloud_environment)
33dd94
     elif config.UseMSI:
33dd94
-        from azure.identity import ManagedIdentityCredential
33dd94
-        credentials = ManagedIdentityCredential()
33dd94
+        try:
33dd94
+            from azure.identity import ManagedIdentityCredential
33dd94
+            credentials = ManagedIdentityCredential()
33dd94
+        except ImportError:
33dd94
+            from msrestazure.azure_active_directory import MSIAuthentication
33dd94
+            credentials = MSIAuthentication()
33dd94
     elif cloud_environment:
33dd94
         try:
33dd94
             # try to use new libraries ClientSecretCredential (azure.identity, based on azure.core)
33dd94
@@ -337,12 +345,19 @@ def get_azure_compute_client(config):
33dd94
     credentials = get_azure_credentials(config)
33dd94
 
33dd94
     if cloud_environment:
33dd94
-        compute_client = ComputeManagementClient(
33dd94
-            credentials,
33dd94
-            config.SubscriptionId,
33dd94
-            base_url=cloud_environment.endpoints.resource_manager,
33dd94
-            credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
-        )
33dd94
+        try:
33dd94
+            compute_client = ComputeManagementClient(
33dd94
+                credentials,
33dd94
+                config.SubscriptionId,
33dd94
+                base_url=cloud_environment.endpoints.resource_manager,
33dd94
+                credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
+            )
33dd94
+        except TypeError:
33dd94
+            compute_client = ComputeManagementClient(
33dd94
+                credentials,
33dd94
+                config.SubscriptionId,
33dd94
+                base_url=cloud_environment.endpoints.resource_manager
33dd94
+            )
33dd94
     else:
33dd94
         compute_client = ComputeManagementClient(
33dd94
             credentials,
33dd94
@@ -357,12 +372,19 @@ def get_azure_network_client(config):
33dd94
     credentials = get_azure_credentials(config)
33dd94
 
33dd94
     if cloud_environment:
33dd94
-        network_client = NetworkManagementClient(
33dd94
-            credentials,
33dd94
-            config.SubscriptionId,
33dd94
-            base_url=cloud_environment.endpoints.resource_manager,
33dd94
-            credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
-        )
33dd94
+        try:
33dd94
+            network_client = NetworkManagementClient(
33dd94
+                credentials,
33dd94
+                config.SubscriptionId,
33dd94
+                base_url=cloud_environment.endpoints.resource_manager,
33dd94
+                credential_scopes=[cloud_environment.endpoints.resource_manager + "/.default"]
33dd94
+            )
33dd94
+        except TypeError:
33dd94
+            network_client = NetworkManagementClient(
33dd94
+                credentials,
33dd94
+                config.SubscriptionId,
33dd94
+                base_url=cloud_environment.endpoints.resource_manager
33dd94
+            )
33dd94
     else:
33dd94
         network_client = NetworkManagementClient(
33dd94
             credentials,