From 59fe6dd129d8e1462dcd6361a417acbaccb8b1f0 Mon Sep 17 00:00:00 2001 From: Arjun Gupta Date: Mon, 26 Feb 2018 19:35:38 +0530 Subject: [PATCH] changing custom script extension links to fwd links (#6500) * changing custom script extension links to fwd links * moving forward link utility to azure-arm-rest * removing unnecessary new line --- .../Tests/EnablePrereq.ts | 1 + .../Tests/addVSTSExtension.ts | 1 + .../mock_node_modules/webRequestUtility.ts | 12 ++++++++++ .../operations/WinRMExtensionHelper.ts | 9 ++++++-- Tasks/AzureResourceGroupDeployment/task.json | 2 +- .../task.loc.json | 2 +- .../azure-arm-rest/webRequestUtility.ts | 23 +++++++++++++++++++ 7 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 Tasks/AzureResourceGroupDeployment/Tests/mock_node_modules/webRequestUtility.ts create mode 100644 Tasks/Common/azure-arm-rest/webRequestUtility.ts diff --git a/Tasks/AzureResourceGroupDeployment/Tests/EnablePrereq.ts b/Tasks/AzureResourceGroupDeployment/Tests/EnablePrereq.ts index df8a1d610525..3ae281822e89 100644 --- a/Tasks/AzureResourceGroupDeployment/Tests/EnablePrereq.ts +++ b/Tasks/AzureResourceGroupDeployment/Tests/EnablePrereq.ts @@ -43,6 +43,7 @@ let a: ma.TaskLibAnswers = { tr.setAnswers(a); tr.registerMock('vsts-task-lib/toolrunner', require('vsts-task-lib/mock-toolrunner')); +tr.registerMock('azure-arm-rest/webRequestUtility', require('./mock_node_modules/webRequestUtility')); tr.registerMock('azure-arm-rest/azure-arm-compute', require('./mock_node_modules/azure-arm-compute')); tr.registerMock('azure-arm-rest/azure-arm-network', require('./mock_node_modules/azure-arm-network')); tr.registerMock('azure-arm-rest/azure-arm-resource', require('./mock_node_modules/azure-arm-resource')); diff --git a/Tasks/AzureResourceGroupDeployment/Tests/addVSTSExtension.ts b/Tasks/AzureResourceGroupDeployment/Tests/addVSTSExtension.ts index c4753e204dea..f1976d51a22a 100644 --- a/Tasks/AzureResourceGroupDeployment/Tests/addVSTSExtension.ts +++ b/Tasks/AzureResourceGroupDeployment/Tests/addVSTSExtension.ts @@ -51,6 +51,7 @@ process.env["MOCK_NORMALIZE_SLASHES"] = "true"; tr.setAnswers(a); tr.registerMock('vsts-task-lib/toolrunner', require('vsts-task-lib/mock-toolrunner')); +tr.registerMock('azure-arm-rest/webRequestUtility', require('./mock_node_modules/webRequestUtility')); tr.registerMock('azure-arm-rest/azure-arm-network', require('./mock_node_modules/azure-arm-network')); tr.registerMock('azure-arm-rest/azure-arm-resource', require('./mock_node_modules/azure-arm-resource')); tr.registerMock('azure-arm-rest/azure-arm-compute', require('./mock_node_modules/azure-arm-compute')); diff --git a/Tasks/AzureResourceGroupDeployment/Tests/mock_node_modules/webRequestUtility.ts b/Tasks/AzureResourceGroupDeployment/Tests/mock_node_modules/webRequestUtility.ts new file mode 100644 index 000000000000..d42a23b63691 --- /dev/null +++ b/Tasks/AzureResourceGroupDeployment/Tests/mock_node_modules/webRequestUtility.ts @@ -0,0 +1,12 @@ +class WebRequestUtility { + public static async getTargetUriFromFwdLink(fwdLink: string) { + if(fwdLink == "https://aka.ms/vstsconfigurewinrm") { + return "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/501dc7d24537e820df7c80bce51aba9674233b2b/201-vm-winrm-windows/ConfigureWinRM.ps1" + } + if(fwdLink == "https://aka.ms/vstsmakecertexe") { + return "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/501dc7d24537e820df7c80bce51aba9674233b2b/201-vm-winrm-windows/makecert.exe" + } + } +} + +export = WebRequestUtility; \ No newline at end of file diff --git a/Tasks/AzureResourceGroupDeployment/operations/WinRMExtensionHelper.ts b/Tasks/AzureResourceGroupDeployment/operations/WinRMExtensionHelper.ts index 3a74cf1aac02..2b9409048c3d 100644 --- a/Tasks/AzureResourceGroupDeployment/operations/WinRMExtensionHelper.ts +++ b/Tasks/AzureResourceGroupDeployment/operations/WinRMExtensionHelper.ts @@ -6,6 +6,7 @@ import azure_utils = require("./AzureUtil"); import deployAzureRG = require("../models/DeployAzureRG"); import az = require("azure-arm-rest/azureModels"); import utils = require("./Utils"); +import webRequestUtility = require("azure-arm-rest/webRequestUtility"); export class WinRMExtensionHelper { private taskParameters: deployAzureRG.AzureRGTaskParameters; @@ -289,8 +290,12 @@ export class WinRMExtensionHelper { private async AddWinRMExtension(vmId: string, vmName: string, dnsName: string, location: string) { var extensionName: string = "WinRMCustomScriptExtension"; - var configWinRMScriptFile: string = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/501dc7d24537e820df7c80bce51aba9674233b2b/201-vm-winrm-windows/ConfigureWinRM.ps1"; - var makeCertFile: string = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/501dc7d24537e820df7c80bce51aba9674233b2b/201-vm-winrm-windows/makecert.exe"; + var configWinRMScriptFileFwdLink: string = "https://aka.ms/vstsconfigurewinrm"; + var makeCertFileFwdLink: string = "https://aka.ms/vstsmakecertexe"; + + var configWinRMScriptFile: string = await webRequestUtility.getTargetUriFromFwdLink(configWinRMScriptFileFwdLink); + var makeCertFile: string = await webRequestUtility.getTargetUriFromFwdLink(makeCertFileFwdLink); + var fileUris = [configWinRMScriptFile, makeCertFile]; tl.debug("Adding custom script extension for virtual machine " + vmName); diff --git a/Tasks/AzureResourceGroupDeployment/task.json b/Tasks/AzureResourceGroupDeployment/task.json index bcc6e5b8f6a7..d3ec60d3ecf8 100644 --- a/Tasks/AzureResourceGroupDeployment/task.json +++ b/Tasks/AzureResourceGroupDeployment/task.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 131, - "Patch": 0 + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.119.1", diff --git a/Tasks/AzureResourceGroupDeployment/task.loc.json b/Tasks/AzureResourceGroupDeployment/task.loc.json index 58cf91d02819..04f44ed87f63 100644 --- a/Tasks/AzureResourceGroupDeployment/task.loc.json +++ b/Tasks/AzureResourceGroupDeployment/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 131, - "Patch": 0 + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.119.1", diff --git a/Tasks/Common/azure-arm-rest/webRequestUtility.ts b/Tasks/Common/azure-arm-rest/webRequestUtility.ts new file mode 100644 index 000000000000..94bb278c883e --- /dev/null +++ b/Tasks/Common/azure-arm-rest/webRequestUtility.ts @@ -0,0 +1,23 @@ +import tl = require("vsts-task-lib/task"); +import webClient = require("./webClient"); +const HttpRedirectCodes: number[] = [301, 302, 307, 308]; +class WebRequestUtility { + public static async getTargetUriFromFwdLink(fwdLink: string) { + tl.debug("Trying to fetch target link from the fwdlink: " + fwdLink); + var httpRequest = new webClient.WebRequest(); + httpRequest.method = 'GET'; + httpRequest.uri = fwdLink; + var httpResponse = await webClient.sendRequest(httpRequest); + if(HttpRedirectCodes.indexOf(httpResponse.statusCode) == -1) { + throw new Error(`HttpResponse statuscode: ${httpResponse.statusCode} is not a valid HTTP redirect code.`); + } + var targetLink: string = httpResponse.headers["location"]; + if(!targetLink) { + throw new Error(`Unable to find location header after HTTP ${httpResponse.statusCode} redirect.`); + } + tl.debug("the target link is : " + targetLink); + return targetLink; + } +} + +export = WebRequestUtility; \ No newline at end of file