Skip to content

Commit

Permalink
Fix multi azure environment issue. (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewholler authored and keesschollaart81 committed Sep 8, 2019
1 parent 840ac78 commit 7e30a83
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions arm-outputs/arm-outputsV2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class AzureDevOpsArmOutputsTaskHost {
let connectedServiceNameARM: string = tl.getInput("ConnectedServiceNameARM");
var endpointAuth = tl.getEndpointAuthorization(connectedServiceNameARM, true);
var authScheme = tl.getEndpointAuthorizationScheme(connectedServiceNameARM, true);
var credentials = this.getCredentials(endpointAuth, authScheme);
var environmentName = tl.getEndpointDataParameter(connectedServiceNameARM, "environment", true);
var credentials = this.getCredentials(endpointAuth, authScheme, environmentName);
var subscriptionId = tl.getEndpointDataParameter(connectedServiceNameARM, "SubscriptionId", true);

var resourceGroupName = tl.getInput("resourceGroupName", true);
Expand Down Expand Up @@ -75,7 +76,7 @@ export class AzureDevOpsArmOutputsTaskHost {
}
}

private getCredentials = (endpointAuthorization: tl.EndpointAuthorization, authScheme: string): ServiceClientCredentials => {
private getCredentials = (endpointAuthorization: tl.EndpointAuthorization, authScheme: string, environmentName: string): ServiceClientCredentials => {
if (authScheme == "ManagedServiceIdentity") {
console.log("Logging in using MSIVmTokenCredentials");
return new msrestAzure.MSIVmTokenCredentials();
Expand All @@ -86,11 +87,25 @@ export class AzureDevOpsArmOutputsTaskHost {
var servicePrincipalId: string = endpointAuthorization.parameters["serviceprincipalid"];
var servicePrincipalKey: string = endpointAuthorization.parameters["serviceprincipalkey"];
var tenantId: string = endpointAuthorization.parameters["tenantid"];
var azureEnvironment: msrestAzure.AzureEnvironment = this.getEnvironment(environmentName);
const tokenCredentialsOptions: msrestAzure.AzureTokenCredentialsOptions = {
environment: azureEnvironment
};

var credentials = new msrestAzure.ApplicationTokenCredentials(servicePrincipalId, tenantId, servicePrincipalKey);
var credentials = new msrestAzure.ApplicationTokenCredentials(servicePrincipalId, tenantId, servicePrincipalKey, tokenCredentialsOptions);

return credentials;
}

private getEnvironment = (environmentName: string): msrestAzure.AzureEnvironment => {
const azureEnvironmentMaps = {
azurechinacloud: msrestAzure.AzureEnvironment.AzureChina,
azurecloud: msrestAzure.AzureEnvironment.Azure,
azuregermancloud: msrestAzure.AzureEnvironment.AzureGermanCloud,
azureusgovernment: msrestAzure.AzureEnvironment.AzureUSGovernment,
};
return azureEnvironmentMaps[environmentName.toLowerCase()];
}
}
var azureDevOpsArmOutputsTaskHost = new AzureDevOpsArmOutputsTaskHost();

Expand Down

0 comments on commit 7e30a83

Please sign in to comment.