From 4f3153d4d7086aaefce6c6bef2f85cb6bd7f20f5 Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 10:32:42 +0530 Subject: [PATCH 1/8] Changes for AzureKEyvault --- .../operations/azure-arm-keyvault.ts | 67 +++++++++++++++---- Tasks/AzureKeyVaultV1/task.json | 4 +- Tasks/AzureKeyVaultV1/task.loc.json | 4 +- _generated/AzureKeyVaultV1.versionmap.txt | 4 +- .../operations/azure-arm-keyvault.ts | 67 +++++++++++++++---- _generated/AzureKeyVaultV1/task.json | 8 +-- _generated/AzureKeyVaultV1/task.loc.json | 8 +-- .../operations/azure-arm-keyvault.ts | 67 +++++++++++++++---- _generated/AzureKeyVaultV1_Node20/task.json | 8 +-- .../AzureKeyVaultV1_Node20/task.loc.json | 8 +-- 10 files changed, 184 insertions(+), 61 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index e3c973cd35a7..4473e1443077 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,13 +5,18 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); +let retrysCount: number; +let retryWait: number; + export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; contentType: string; + } + export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; @@ -178,19 +183,55 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); - this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - if (response.statusCode == 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } - else if (response.statusCode == 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } - else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - (error) => callback(error)); + // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // if (response.statusCode == 200) { + // var result = response.body.value; + // return new azureServiceClientBase.ApiResult(null, result); + // } + // else if (response.statusCode == 400) { + // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + // } + // else { + // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + // } + // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), + // (error) => callback(error)); + this.invokeRequestWithRetry(httpRequest,secretName) + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); + } + + async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // Retry logic + //const maxAttempts = 3; + let attempts = 0; + + // Check response status code + if (retrysCount > 0) { + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); + attempts++; + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + + } + } + throw new Error(`Failed after ${retrysCount} attempts`); + + }); + } private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { diff --git a/Tasks/AzureKeyVaultV1/task.json b/Tasks/AzureKeyVaultV1/task.json index 5891927ed1d8..58a812e77b4a 100644 --- a/Tasks/AzureKeyVaultV1/task.json +++ b/Tasks/AzureKeyVaultV1/task.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 2 + "Minor": 238, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.0.0", diff --git a/Tasks/AzureKeyVaultV1/task.loc.json b/Tasks/AzureKeyVaultV1/task.loc.json index cc497046ba72..945d15a6aa7b 100644 --- a/Tasks/AzureKeyVaultV1/task.loc.json +++ b/Tasks/AzureKeyVaultV1/task.loc.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 2 + "Minor": 238, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.0.0", diff --git a/_generated/AzureKeyVaultV1.versionmap.txt b/_generated/AzureKeyVaultV1.versionmap.txt index 88ca1a3e4499..06be14f9a274 100644 --- a/_generated/AzureKeyVaultV1.versionmap.txt +++ b/_generated/AzureKeyVaultV1.versionmap.txt @@ -1,2 +1,2 @@ -Default|1.237.2 -Node20_229_2|1.237.3 +Default|1.238.0 +Node20_229_2|1.238.1 diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index e3c973cd35a7..4473e1443077 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,13 +5,18 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); +let retrysCount: number; +let retryWait: number; + export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; contentType: string; + } + export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; @@ -178,19 +183,55 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); - this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - if (response.statusCode == 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } - else if (response.statusCode == 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } - else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - (error) => callback(error)); + // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // if (response.statusCode == 200) { + // var result = response.body.value; + // return new azureServiceClientBase.ApiResult(null, result); + // } + // else if (response.statusCode == 400) { + // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + // } + // else { + // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + // } + // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), + // (error) => callback(error)); + this.invokeRequestWithRetry(httpRequest,secretName) + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); + } + + async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // Retry logic + //const maxAttempts = 3; + let attempts = 0; + + // Check response status code + if (retrysCount > 0) { + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); + attempts++; + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + + } + } + throw new Error(`Failed after ${retrysCount} attempts`); + + }); + } private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { diff --git a/_generated/AzureKeyVaultV1/task.json b/_generated/AzureKeyVaultV1/task.json index 9b82b53a0409..421653c7481b 100644 --- a/_generated/AzureKeyVaultV1/task.json +++ b/_generated/AzureKeyVaultV1/task.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 2 + "Minor": 238, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.0.0", @@ -129,7 +129,7 @@ "ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired." }, "_buildConfigMapping": { - "Default": "1.237.2", - "Node20_229_2": "1.237.3" + "Default": "1.238.0", + "Node20_229_2": "1.238.1" } } \ No newline at end of file diff --git a/_generated/AzureKeyVaultV1/task.loc.json b/_generated/AzureKeyVaultV1/task.loc.json index cdc4a9df4f28..f08b93ee8fef 100644 --- a/_generated/AzureKeyVaultV1/task.loc.json +++ b/_generated/AzureKeyVaultV1/task.loc.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 2 + "Minor": 238, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.0.0", @@ -129,7 +129,7 @@ "ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal" }, "_buildConfigMapping": { - "Default": "1.237.2", - "Node20_229_2": "1.237.3" + "Default": "1.238.0", + "Node20_229_2": "1.238.1" } } \ No newline at end of file diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index e3c973cd35a7..4473e1443077 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -5,13 +5,18 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); +let retrysCount: number; +let retryWait: number; + export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; contentType: string; + } + export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; @@ -178,19 +183,55 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); - this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - if (response.statusCode == 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } - else if (response.statusCode == 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } - else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - (error) => callback(error)); + // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // if (response.statusCode == 200) { + // var result = response.body.value; + // return new azureServiceClientBase.ApiResult(null, result); + // } + // else if (response.statusCode == 400) { + // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + // } + // else { + // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + // } + // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), + // (error) => callback(error)); + this.invokeRequestWithRetry(httpRequest,secretName) + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); + } + + async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { + // Retry logic + //const maxAttempts = 3; + let attempts = 0; + + // Check response status code + if (retrysCount > 0) { + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); + attempts++; + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + + } + } + throw new Error(`Failed after ${retrysCount} attempts`); + + }); + } private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { diff --git a/_generated/AzureKeyVaultV1_Node20/task.json b/_generated/AzureKeyVaultV1_Node20/task.json index 801e47035af8..b283bf847538 100644 --- a/_generated/AzureKeyVaultV1_Node20/task.json +++ b/_generated/AzureKeyVaultV1_Node20/task.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 3 + "Minor": 238, + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.0.0", @@ -137,7 +137,7 @@ "ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired." }, "_buildConfigMapping": { - "Default": "1.237.2", - "Node20_229_2": "1.237.3" + "Default": "1.238.0", + "Node20_229_2": "1.238.1" } } \ No newline at end of file diff --git a/_generated/AzureKeyVaultV1_Node20/task.loc.json b/_generated/AzureKeyVaultV1_Node20/task.loc.json index 3fa942a6c171..d8bfbb0867f9 100644 --- a/_generated/AzureKeyVaultV1_Node20/task.loc.json +++ b/_generated/AzureKeyVaultV1_Node20/task.loc.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 237, - "Patch": 3 + "Minor": 238, + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.0.0", @@ -137,7 +137,7 @@ "ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal" }, "_buildConfigMapping": { - "Default": "1.237.2", - "Node20_229_2": "1.237.3" + "Default": "1.238.0", + "Node20_229_2": "1.238.1" } } \ No newline at end of file From 994b1d80776447631a6a50a34202e16d63c7497b Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 14:12:08 +0530 Subject: [PATCH 2/8] Chnages for AzureKeyVault Retry logic --- .../operations/azure-arm-keyvault.ts | 26 ++++--------------- .../operations/azure-arm-keyvault.ts | 26 ++++--------------- .../operations/azure-arm-keyvault.ts | 26 ++++--------------- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 4473e1443077..dc735759c0fc 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -181,33 +181,17 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { '{secretName}': secretName } ); - console.log(tl.loc("DownloadingSecretValue", secretName)); - // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // if (response.statusCode == 200) { - // var result = response.body.value; - // return new azureServiceClientBase.ApiResult(null, result); - // } - // else if (response.statusCode == 400) { - // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - // } - // else { - // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - // } - // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - // (error) => callback(error)); this.invokeRequestWithRetry(httpRequest,secretName) .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) .catch(error => callback(error)); + } async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { // Retry logic - //const maxAttempts = 3; let attempts = 0; - - // Check response status code if (retrysCount > 0) { try { // Check response status code @@ -217,18 +201,18 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { } else if (response.statusCode === 400) { return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); } else { - throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); } } catch (error) { console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); attempts++; - console.log(tl.loc(`Retrying ...`)); + console.log(tl.loc(`Retrying ...`)); await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) } } - throw new Error(`Failed after ${retrysCount} attempts`); + throw new Error(`Failed after ${attempts} attempts`); }); diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 4473e1443077..dc735759c0fc 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -181,33 +181,17 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { '{secretName}': secretName } ); - console.log(tl.loc("DownloadingSecretValue", secretName)); - // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // if (response.statusCode == 200) { - // var result = response.body.value; - // return new azureServiceClientBase.ApiResult(null, result); - // } - // else if (response.statusCode == 400) { - // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - // } - // else { - // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - // } - // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - // (error) => callback(error)); this.invokeRequestWithRetry(httpRequest,secretName) .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) .catch(error => callback(error)); + } async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { // Retry logic - //const maxAttempts = 3; let attempts = 0; - - // Check response status code if (retrysCount > 0) { try { // Check response status code @@ -217,18 +201,18 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { } else if (response.statusCode === 400) { return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); } else { - throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); } } catch (error) { console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); attempts++; - console.log(tl.loc(`Retrying ...`)); + console.log(tl.loc(`Retrying ...`)); await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) } } - throw new Error(`Failed after ${retrysCount} attempts`); + throw new Error(`Failed after ${attempts} attempts`); }); diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index 4473e1443077..dc735759c0fc 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -181,33 +181,17 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { '{secretName}': secretName } ); - console.log(tl.loc("DownloadingSecretValue", secretName)); - // this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // if (response.statusCode == 200) { - // var result = response.body.value; - // return new azureServiceClientBase.ApiResult(null, result); - // } - // else if (response.statusCode == 400) { - // return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - // } - // else { - // return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - // } - // }).then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result), - // (error) => callback(error)); this.invokeRequestWithRetry(httpRequest,secretName) .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) .catch(error => callback(error)); + } async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { // Retry logic - //const maxAttempts = 3; let attempts = 0; - - // Check response status code if (retrysCount > 0) { try { // Check response status code @@ -217,18 +201,18 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { } else if (response.statusCode === 400) { return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); } else { - throw new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); } } catch (error) { console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); attempts++; - console.log(tl.loc(`Retrying ...`)); + console.log(tl.loc(`Retrying ...`)); await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1) + return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) } } - throw new Error(`Failed after ${retrysCount} attempts`); + throw new Error(`Failed after ${attempts} attempts`); }); From 414d848c3c68d0aa14e2f2ee130ecba0bae461f3 Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 14:16:33 +0530 Subject: [PATCH 3/8] Changes for Azure KeyVault --- Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 4 +--- _generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 4 +--- .../AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index dc735759c0fc..127b13dc39bc 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -12,11 +12,9 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; - + contentType: string; } - export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index dc735759c0fc..127b13dc39bc 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -12,11 +12,9 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; - + contentType: string; } - export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index dc735759c0fc..127b13dc39bc 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -12,11 +12,9 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; - + contentType: string; } - export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; From 60eb9c60bf8baa4edcdce256150907d0ba2b4a3f Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 14:22:58 +0530 Subject: [PATCH 4/8] Changes for AzureKeyVault --- Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 2 +- _generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 2 +- .../AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 127b13dc39bc..9cd689ae53c0 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -12,7 +12,7 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; + contentType: string; } export class KeyVaultClient extends azureServiceClient.ServiceClient { diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 127b13dc39bc..9cd689ae53c0 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -12,7 +12,7 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; + contentType: string; } export class KeyVaultClient extends azureServiceClient.ServiceClient { diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index 127b13dc39bc..9cd689ae53c0 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -12,7 +12,7 @@ export class AzureKeyVaultSecret { name: string; enabled: boolean; expires: Date; - contentType: string; + contentType: string; } export class KeyVaultClient extends azureServiceClient.ServiceClient { From 5bf64c95be7bd88dd33c15e4c9f98247340be4be Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 15:49:09 +0530 Subject: [PATCH 5/8] changes for AzureKeyVault --- .../operations/azure-arm-keyvault.ts | 55 +++++++++---------- .../operations/azure-arm-keyvault.ts | 55 +++++++++---------- .../operations/azure-arm-keyvault.ts | 55 +++++++++---------- 3 files changed, 75 insertions(+), 90 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 9cd689ae53c0..40e6e9061fc9 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,7 +5,7 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retrysCount: number; +let retriesCount: number; let retryWait: number; export class AzureKeyVaultSecret { @@ -181,41 +181,36 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); this.invokeRequestWithRetry(httpRequest,secretName) - .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) - .catch(error => callback(error)); + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); } - async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + async invokeRequestWithRetry(httpRequest, secretName, retriesCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // Retry logic - let attempts = 0; - if (retrysCount > 0) { - try { - // Check response status code - if (response.statusCode === 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } else if (response.statusCode === 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - } catch (error) { - console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); - attempts++; - console.log(tl.loc(`Retrying ...`)); - await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) - - } + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + // Retry logic + if (retriesCount > 0) { + console.error(tl.loc(`failed with error: ${error} - remaining attempts: ${retriesCount}`)); + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest, secretName, retriesCount - 1, retryWait) } - throw new Error(`Failed after ${attempts} attempts`); - - }); - + } + throw new Error(tl.loc(`Failed after ${4 - retriesCount} attempts`)); + }); } - + private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { var listOfSecrets: AzureKeyVaultSecret[] = []; result.forEach((value: any, index: number) => { diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 9cd689ae53c0..40e6e9061fc9 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,7 +5,7 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retrysCount: number; +let retriesCount: number; let retryWait: number; export class AzureKeyVaultSecret { @@ -181,41 +181,36 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); this.invokeRequestWithRetry(httpRequest,secretName) - .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) - .catch(error => callback(error)); + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); } - async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + async invokeRequestWithRetry(httpRequest, secretName, retriesCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // Retry logic - let attempts = 0; - if (retrysCount > 0) { - try { - // Check response status code - if (response.statusCode === 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } else if (response.statusCode === 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - } catch (error) { - console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); - attempts++; - console.log(tl.loc(`Retrying ...`)); - await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) - - } + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + // Retry logic + if (retriesCount > 0) { + console.error(tl.loc(`failed with error: ${error} - remaining attempts: ${retriesCount}`)); + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest, secretName, retriesCount - 1, retryWait) } - throw new Error(`Failed after ${attempts} attempts`); - - }); - + } + throw new Error(tl.loc(`Failed after ${4 - retriesCount} attempts`)); + }); } - + private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { var listOfSecrets: AzureKeyVaultSecret[] = []; result.forEach((value: any, index: number) => { diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index 9cd689ae53c0..40e6e9061fc9 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -5,7 +5,7 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retrysCount: number; +let retriesCount: number; let retryWait: number; export class AzureKeyVaultSecret { @@ -181,41 +181,36 @@ export class KeyVaultClient extends azureServiceClient.ServiceClient { ); console.log(tl.loc("DownloadingSecretValue", secretName)); this.invokeRequestWithRetry(httpRequest,secretName) - .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) - .catch(error => callback(error)); + .then((apiResult: azureServiceClientBase.ApiResult) => callback(apiResult.error, apiResult.result)) + .catch(error => callback(error)); } - async invokeRequestWithRetry(httpRequest, secretName, retrysCount: number = 3, retryWait: number = 2000) { + async invokeRequestWithRetry(httpRequest, secretName, retriesCount: number = 3, retryWait: number = 2000) { return this.invokeRequest(httpRequest).then(async (response: webClient.WebResponse) => { - // Retry logic - let attempts = 0; - if (retrysCount > 0) { - try { - // Check response status code - if (response.statusCode === 200) { - var result = response.body.value; - return new azureServiceClientBase.ApiResult(null, result); - } else if (response.statusCode === 400) { - return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); - } else { - return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); - } - } catch (error) { - console.error(tl.loc(`Attempt ${attempts + 1} failed with error: ${error}`)); - attempts++; - console.log(tl.loc(`Retrying ...`)); - await new Promise(r => setTimeout(r, retryWait)); - return await this.invokeRequestWithRetry(httpRequest,secretName, retrysCount-1, retryWait) - - } + try { + // Check response status code + if (response.statusCode === 200) { + var result = response.body.value; + return new azureServiceClientBase.ApiResult(null, result); + } else if (response.statusCode === 400) { + return new azureServiceClientBase.ApiResult(tl.loc('GetSecretFailedBecauseOfInvalidCharacters', secretName)); + } else { + return new azureServiceClientBase.ApiResult(azureServiceClientBase.ToError(response)); + } + } catch (error) { + // Retry logic + if (retriesCount > 0) { + console.error(tl.loc(`failed with error: ${error} - remaining attempts: ${retriesCount}`)); + console.log(tl.loc(`Retrying ...`)); + await new Promise(r => setTimeout(r, retryWait)); + return await this.invokeRequestWithRetry(httpRequest, secretName, retriesCount - 1, retryWait) } - throw new Error(`Failed after ${attempts} attempts`); - - }); - + } + throw new Error(tl.loc(`Failed after ${4 - retriesCount} attempts`)); + }); } - + private convertToAzureKeyVaults(result: any[]): AzureKeyVaultSecret[] { var listOfSecrets: AzureKeyVaultSecret[] = []; result.forEach((value: any, index: number) => { From 37e33fca8561a842600d74519d9e6e6686417e26 Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 16:52:50 +0530 Subject: [PATCH 6/8] Changes for AzureKeyvault --- Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 40e6e9061fc9..08125a377032 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,9 +5,6 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retriesCount: number; -let retryWait: number; - export class AzureKeyVaultSecret { name: string; enabled: boolean; @@ -15,6 +12,7 @@ export class AzureKeyVaultSecret { contentType: string; } + export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; From 3d294eab7428d5cbd28e2f79f5c870fa934f2b9e Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 16:54:08 +0530 Subject: [PATCH 7/8] Changes for AzureKeyVault --- Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 08125a377032..f4cb13478023 100644 --- a/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/Tasks/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -12,7 +12,6 @@ export class AzureKeyVaultSecret { contentType: string; } - export class KeyVaultClient extends azureServiceClient.ServiceClient { private keyVaultName; private keyVaultUrl; From 9b34d0fe77d2c502ea58f91b913ff416a18fbe37 Mon Sep 17 00:00:00 2001 From: v-dmerugu Date: Thu, 28 Mar 2024 17:05:12 +0530 Subject: [PATCH 8/8] changes for AzureKeyvault removing global variable --- _generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts | 3 --- .../AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts | 3 --- 2 files changed, 6 deletions(-) diff --git a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts index 40e6e9061fc9..f4cb13478023 100644 --- a/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1/operations/azure-arm-keyvault.ts @@ -5,9 +5,6 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retriesCount: number; -let retryWait: number; - export class AzureKeyVaultSecret { name: string; enabled: boolean; diff --git a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts index 40e6e9061fc9..f4cb13478023 100644 --- a/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts +++ b/_generated/AzureKeyVaultV1_Node20/operations/azure-arm-keyvault.ts @@ -5,9 +5,6 @@ import util = require("util"); import tl = require('azure-pipelines-task-lib/task'); import webClient = require("azure-pipelines-tasks-azure-arm-rest/webClient"); -let retriesCount: number; -let retryWait: number; - export class AzureKeyVaultSecret { name: string; enabled: boolean;