Skip to content

Commit

Permalink
changing custom script extension links to fwd links (#6500)
Browse files Browse the repository at this point in the history
* changing custom script extension links to fwd links

* moving forward link utility to azure-arm-rest

* removing unnecessary new line
  • Loading branch information
arjgupta authored Feb 26, 2018
1 parent 7a7c194 commit 59fe6dd
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions Tasks/AzureResourceGroupDeployment/Tests/EnablePrereq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let a: ma.TaskLibAnswers = <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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureResourceGroupDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 131,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureResourceGroupDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 131,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down
23 changes: 23 additions & 0 deletions Tasks/Common/azure-arm-rest/webRequestUtility.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 59fe6dd

Please sign in to comment.