From 5ac6479d183b824b81fd561a30ba843b907a2122 Mon Sep 17 00:00:00 2001 From: Suresh Prajapati Date: Sun, 1 Nov 2020 14:58:04 +0100 Subject: [PATCH 1/2] DefaultAzureCredential can take care of the authenticating the function As per Azure function docs[1] `DefaultAzureCredential` should be able to get the necessary credentials. [1] https://docs.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#defaultazurecredential --- .../GetListOfResourceGroups/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py b/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py index 944c177..cd8bd2f 100644 --- a/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py +++ b/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py @@ -14,11 +14,7 @@ async def main(req: func.HttpRequest) -> func.HttpResponse: The main entry point to the function. """ - if "MSI_ENDPOINT" in os.environ: - credentials = MSIAuthentication() - else: - credentials, *_ = get_azure_cli_credentials() - + credentials = DefaultAzureCredential() subscription_id = os.environ.get( 'AZURE_SUBSCRIPTION_ID', '11111111-1111-1111-1111-111111111111') From 45728e80d882dde59b9ba0408edd27467dfed9d6 Mon Sep 17 00:00:00 2001 From: Suresh Prajapati Date: Sun, 1 Nov 2020 15:08:15 +0100 Subject: [PATCH 2/2] removing unused imports * removed unused imports * added the `DefaultAzureCredential` --- .../GetListOfResourceGroups/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py b/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py index cd8bd2f..933a13a 100644 --- a/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py +++ b/src/get-list-of-azure-resource-groups-functionapp/GetListOfResourceGroups/__init__.py @@ -2,10 +2,7 @@ import os import azure.functions as func - -from azure.common.credentials import (ServicePrincipalCredentials, get_azure_cli_credentials) -from msrestazure.azure_active_directory import MSIAuthentication - +from azure.identity import DefaultAzureCredential from .resource_group_operations import list_rgs