Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurecli classic cert auth's service url picked from endpoint #3256

Merged
merged 2 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Tasks/AzureCLI/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ export class azureclitask {
if (endpointAuth.scheme === "Certificate") {
var bytes = endpointAuth.parameters["certificate"];
var subscriptionId:string = tl.getEndpointDataParameter(connectedService, "SubscriptionId", true);
var serviceManagementUrl:string = tl.getEndpointUrl(connectedService, false);
const publishSettingFileName:string = path.join(os.tmpdir() ,"subscriptions" + new Date().getTime() + ".publishsettings");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the service endpoint URL always present - even for older endpoints which didn't allow selecting this URL? If not, see if we should fallback to the default URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a default service URL used to be present in older endpoints. so we should be fine.

this.createPublishSettingFile(subscriptionName, subscriptionId, bytes, publishSettingFileName);
this.createPublishSettingFile(subscriptionName, subscriptionId, bytes, serviceManagementUrl, publishSettingFileName);
var resultOfToolExecution = tl.execSync("azure", "account import \"" + publishSettingFileName + "\"");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTs for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

this.deleteFile(publishSettingFileName);
this.throwIfError(resultOfToolExecution);
Expand Down Expand Up @@ -198,9 +199,9 @@ export class azureclitask {
}
}

private static createPublishSettingFile(subscriptionName:string, subscriptionId:string, certificate:string, publishSettingFileName:string): void {
private static createPublishSettingFile(subscriptionName:string, subscriptionId:string, certificate:string, serviceManagementUrl:string, publishSettingFileName:string): void {
//writing the data to the publishsetting file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verify if serviceManagementUrl can have a terminal slash and if so, will it cause any issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while making a call to azure, the azurecli removes the terminal slash. Thus it is not causing any errors.
here is a screenshot of a call to azure while using a publishsetting file with serviceManagementUrl having terminal slash
image

this.createFile(publishSettingFileName, util.format('<?xml version="1.0" encoding="utf-8"?><PublishData><PublishProfile SchemaVersion="2.0" PublishMethod="AzureServiceManagementAPI"><Subscription ServiceManagementUrl="https://management.core.windows.net" Id="%s" Name="%s" ManagementCertificate="%s" /> </PublishProfile></PublishData>',subscriptionId, subscriptionName, certificate));
this.createFile(publishSettingFileName, util.format('<?xml version="1.0" encoding="utf-8"?><PublishData><PublishProfile SchemaVersion="2.0" PublishMethod="AzureServiceManagementAPI"><Subscription ServiceManagementUrl="%s" Id="%s" Name="%s" ManagementCertificate="%s" /> </PublishProfile></PublishData>',serviceManagementUrl, subscriptionId, subscriptionName, certificate));
}

private static createFile (filePath:string, data:string)
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLI/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-tasks-azurecli",
"version": "0.2.4",
"version": "0.2.6",
"description": "VSTS Azure CLI Task",
"main": "azureclitask.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLI/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 0,
"Minor": 2,
"Patch": 5
"Patch": 6
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLI/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 0,
"Minor": 2,
"Patch": 5
"Patch": 6
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
5 changes: 3 additions & 2 deletions Tests/L0/AzureCLI/azureLoginFails.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
"ENDPOINT_AUTH_AzureClassicFail": "{\"parameters\":{\"certificate\":\"cert\"},\"scheme\":\"Certificate\"}",
"ENDPOINT_DATA_AzureClassicFail_SUBSCRIPTIONNAME": "sName",
"ENDPOINT_DATA_AzureClassicFail_SUBSCRIPTIONID": "sId",
"ENDPOINT_URL_AzureClassicFail":"https://www.sampleServiceUrl.net/",
"ENDPOINT_AUTH_AzureRM": "{\"parameters\":{\"serviceprincipalid\":\"id\",\"serviceprincipalkey\":\"key\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}",
"ENDPOINT_AUTH_AzureRMFail": "{\"parameters\":{\"serviceprincipalid\":\"idf\",\"serviceprincipalkey\":\"keyf\",\"tenantid\":\"tenantf\"},\"scheme\":\"ServicePrincipal\"}",
"ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME": "sName",
"ENDPOINT_DATA_AzureRMFail_SUBSCRIPTIONNAME": "sName"
}
}
}
}
1 change: 1 addition & 0 deletions Tests/L0/AzureCLI/azureclitaskPass.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"ENDPOINT_AUTH_AzureClassic": "{\"parameters\":{\"certificate\":\"cert\"},\"scheme\":\"Certificate\"}",
"ENDPOINT_DATA_AzureClassic_SUBSCRIPTIONNAME": "sName",
"ENDPOINT_DATA_AzureClassic_SUBSCRIPTIONID": "sId",
"ENDPOINT_URL_AzureClassic":"https://www.sampleServiceUrl.net/",
"ENDPOINT_AUTH_AzureRM": "{\"parameters\":{\"serviceprincipalid\":\"id\",\"serviceprincipalkey\":\"key\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}",
"ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME": "sName"
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/L0/AzureCLI/scriptExecutionFailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"stdout":"bash execution failed",
"stderr": "bash stderr"
},
"scriptfail.bat arg1": {
"scriptfail.bat arg1": {
"code": 1,
"stdout":"cmd execution failed",
"stderr": "cmd stderr"
Expand Down Expand Up @@ -60,6 +60,7 @@
"ENDPOINT_AUTH_AzureClassic": "{\"parameters\":{\"certificate\":\"cert\"},\"scheme\":\"Certificate\"}",
"ENDPOINT_DATA_AzureClassic_SUBSCRIPTIONNAME": "sName",
"ENDPOINT_DATA_AzureClassic_SUBSCRIPTIONID": "sId",
"ENDPOINT_URL_AzureClassic":"https://www.sampleServiceUrl.net/",
"ENDPOINT_AUTH_AzureRM": "{\"parameters\":{\"serviceprincipalid\":\"id\",\"serviceprincipalkey\":\"key\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}",
"ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME": "sName"
}
Expand Down