From 11f78188f459494922d89133f03e2525164966d4 Mon Sep 17 00:00:00 2001 From: Youn Jae Kim Date: Thu, 21 Nov 2024 17:26:05 -0800 Subject: [PATCH] Removing old test --- pkg/scalers/azure/azure_app_insights.go | 19 ++++++++--- pkg/scalers/azure/azure_app_insights_test.go | 36 -------------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/pkg/scalers/azure/azure_app_insights.go b/pkg/scalers/azure/azure_app_insights.go index 425f4eb5653..5722928be14 100644 --- a/pkg/scalers/azure/azure_app_insights.go +++ b/pkg/scalers/azure/azure_app_insights.go @@ -95,12 +95,23 @@ func queryParamsForAppInsightsRequest(info AppInsightsInfo) (map[string]interfac return queryParams, nil } +func getAuthConfig(ctx context.Context, info AppInsightsInfo, podIdentity kedav1alpha1.AuthPodIdentity) (AADToken, error) { + token := AADToken{} + var err error + + switch podIdentity.Provider { + case "", kedav1alpha1.PodIdentityProviderNone: + token, err = GetAzureADWorkloadIdentityToken(ctx, info.ClientID, info.TenantID, info.ActiveDirectoryEndpoint, info.AppInsightsResourceURL) + case kedav1alpha1.PodIdentityProviderAzureWorkload: + token, err = GetAzureADWorkloadIdentityToken(ctx, podIdentity.GetIdentityID(), podIdentity.GetIdentityTenantID(), podIdentity.GetIdentityAuthorityHost(), info.AppInsightsResourceURL) + } + + return token, err +} + // GetAzureAppInsightsMetricValue returns the value of an Azure App Insights metric, rounded to the nearest int func GetAzureAppInsightsMetricValue(ctx context.Context, info AppInsightsInfo, podIdentity kedav1alpha1.AuthPodIdentity, ignoreNullValues bool) (float64, error) { - token, err := GetAzureADWorkloadIdentityToken(ctx, podIdentity.GetIdentityID(), podIdentity.GetIdentityTenantID(), "", info.AppInsightsResourceURL) - if err != nil { - return -1, err - } + token, err := getAuthConfig(ctx, info, podIdentity) queryParams, err := queryParamsForAppInsightsRequest(info) if err != nil { diff --git a/pkg/scalers/azure/azure_app_insights_test.go b/pkg/scalers/azure/azure_app_insights_test.go index 1c470e38d77..db03c60b9b1 100644 --- a/pkg/scalers/azure/azure_app_insights_test.go +++ b/pkg/scalers/azure/azure_app_insights_test.go @@ -1,10 +1,7 @@ package azure import ( - "context" "testing" - - kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" ) type testExtractAzAppInsightsTestData struct { @@ -67,39 +64,6 @@ func TestAzGetAzureAppInsightsMetricValue(t *testing.T) { } } -type testAppInsightsAuthConfigTestData struct { - testName string - config string - info AppInsightsInfo - podIdentity kedav1alpha1.PodIdentityProvider -} - -const ( - msiConfig = "msiConfig" - clientCredentialsConfig = "clientCredentialsConfig" - workloadIdentityConfig = "workloadIdentityConfig" -) - -var testAppInsightsAuthConfigData = []testAppInsightsAuthConfigTestData{ - {"client credentials", clientCredentialsConfig, AppInsightsInfo{ClientID: "1234", ClientPassword: "pw", TenantID: "5678"}, ""}, - {"client credentials - pod id none", clientCredentialsConfig, AppInsightsInfo{ClientID: "1234", ClientPassword: "pw", TenantID: "5678"}, kedav1alpha1.PodIdentityProviderNone}, - {"azure workload identity", workloadIdentityConfig, AppInsightsInfo{}, kedav1alpha1.PodIdentityProviderAzureWorkload}, -} - -func TestAzAppInfoGetToken(t *testing.T) { - for _, testData := range testAppInsightsAuthConfigData { - authToken, err := GetAzureADWorkloadIdentityToken(context.TODO(), testData.info.ClientID, testData.info.TenantID, "", testData.info.AppInsightsResourceURL) - - if err != nil { - t.Errorf("Test %v; Expected success but got error: %v", testData.testName, err) - } - if authToken.AccessToken == "" { - t.Errorf("Test %v; Expected token but got empty token: %v", testData.testName, authToken) - } - t.Logf("Test %v; data: %v, token: %v", testData.testName, testData.info, authToken) - } -} - type toISO8601TestData struct { testName string isError bool