diff --git a/.vscode/launch.json b/.vscode/launch.json index 8f32b117..4af35c57 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,7 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", + "version": "0.2.0", "configurations": [ { "name": "Extension", @@ -51,7 +51,9 @@ "request": "attach", "port": 6009, "restart": true, - "outFiles": ["${workspaceRoot}/node_modules/azure-pipelines-language-server/**/*.js"] + "outFiles": [ + "${workspaceRoot}/node_modules/azure-pipelines-language-server/**/*.js" + ] } ] -} +} \ No newline at end of file diff --git a/src/configure/configure.ts b/src/configure/configure.ts index 3f25933d..61c75763 100644 --- a/src/configure/configure.ts +++ b/src/configure/configure.ts @@ -20,6 +20,7 @@ import * as vscode from 'vscode'; import { Result, telemetryHelper } from './helper/telemetryHelper'; import { ControlProvider } from './helper/controlProvider'; import { GitHubProvider } from './helper/gitHubHelper'; +import { getSubscriptionSession } from './helper/azureSessionHelper'; const Layer: string = 'configure'; @@ -73,9 +74,6 @@ class PipelineConfigurer { public constructor() { this.inputs = new WizardInputs(); - this.inputs.azureSession = extensionVariables.azureAccountExtensionApi.sessions[0]; - this.azureDevOpsClient = new AzureDevOpsClient(this.inputs.azureSession.credentials); - this.azureDevOpsHelper = new AzureDevOpsHelper(this.azureDevOpsClient); this.uniqueResourceNameSuffix = uuid().substr(0, 5); this.controlProvider = new ControlProvider(); } @@ -122,11 +120,11 @@ class PipelineConfigurer { this.inputs.githubPATToken = await this.getGitHubPATToken(); } - await this.getAzureDevOpsDetails(); - if (!this.inputs.targetResource.resource) { await this.getAzureResourceDetails(); } + + await this.getAzureDevOpsDetails(); } private async createPreRequisites(): Promise { @@ -322,6 +320,7 @@ class PipelineConfigurer { private async extractAzureResourceFromNode(node: any): Promise { this.inputs.targetResource.subscriptionId = node.root.subscriptionId; + this.inputs.azureSession = getSubscriptionSession(this.inputs.targetResource.subscriptionId); this.appServiceClient = new AppServiceClient(this.inputs.azureSession.credentials, this.inputs.targetResource.subscriptionId); try { @@ -352,6 +351,7 @@ class PipelineConfigurer { private async getAzureDevOpsDetails(): Promise { try { + this.createAzureDevOpsClient(); if (this.inputs.sourceRepository.repositoryProvider === RepositoryProvider.AzureRepos) { let repoDetails = AzureDevOpsHelper.getRepositoryDetailsFromRemoteUrl(this.inputs.sourceRepository.remoteUrl); this.inputs.organizationName = repoDetails.orgnizationName; @@ -434,14 +434,17 @@ class PipelineConfigurer { // show available subscriptions and get the chosen one let subscriptionList = extensionVariables.azureAccountExtensionApi.filters.map((subscriptionObject) => { return { - label: subscriptionObject.subscription.displayName, - data: subscriptionObject + label: `${subscriptionObject.subscription.displayName}`, + data: subscriptionObject, + description: `${subscriptionObject.subscription.subscriptionId}` }; }); let selectedSubscription: QuickPickItemWithData = await this.controlProvider.showQuickPick(constants.SelectSubscription, subscriptionList, { placeHolder: Messages.selectSubscription }); this.inputs.targetResource.subscriptionId = selectedSubscription.data.subscription.subscriptionId; + this.inputs.azureSession = getSubscriptionSession(this.inputs.targetResource.subscriptionId); + // show available resources and get the chosen one - this.appServiceClient = new AppServiceClient(extensionVariables.azureAccountExtensionApi.sessions[0].credentials, this.inputs.targetResource.subscriptionId); + this.appServiceClient = new AppServiceClient(this.inputs.azureSession.credentials, this.inputs.targetResource.subscriptionId); let selectedResource: QuickPickItemWithData = await this.controlProvider.showQuickPick( constants.SelectWebApp, this.appServiceClient.GetAppServices(WebAppKind.WindowsApp) @@ -539,6 +542,11 @@ class PipelineConfigurer { throw error; } } + + private createAzureDevOpsClient(): void { + this.azureDevOpsClient = new AzureDevOpsClient(this.inputs.azureSession.credentials); + this.azureDevOpsHelper = new AzureDevOpsHelper(this.azureDevOpsClient); + } } // this method is called when your extension is deactivated diff --git a/src/configure/helper/azureSessionHelper.ts b/src/configure/helper/azureSessionHelper.ts new file mode 100644 index 00000000..7f3868d2 --- /dev/null +++ b/src/configure/helper/azureSessionHelper.ts @@ -0,0 +1,15 @@ +import { extensionVariables, AzureSession } from "../model/models"; +import { SubscriptionModels } from "azure-arm-resource"; + +export function getSubscriptionSession(subscriptionId: string): AzureSession { + let currentSubscription: { session: AzureSession, subscription: SubscriptionModels.Subscription } = extensionVariables.azureAccountExtensionApi.subscriptions + .find((subscription) => + subscription.subscription.subscriptionId.toLowerCase() === subscriptionId.toLowerCase()); + + // Fallback to first element + if (!currentSubscription) { + currentSubscription = extensionVariables.azureAccountExtensionApi.subscriptions[0]; + } + + return currentSubscription.session; +} \ No newline at end of file diff --git a/src/configure/helper/telemetryHelper.ts b/src/configure/helper/telemetryHelper.ts index 84d86a02..a4166d87 100644 --- a/src/configure/helper/telemetryHelper.ts +++ b/src/configure/helper/telemetryHelper.ts @@ -39,7 +39,7 @@ class TelemetryHelper { } } - public setCurrentStep(stepName: string) : void{ + public setCurrentStep(stepName: string): void { this.actionContext.telemetry.properties.cancelStep = stepName; } diff --git a/src/configure/model/models.ts b/src/configure/model/models.ts index 0f28df2b..285a4da7 100644 --- a/src/configure/model/models.ts +++ b/src/configure/model/models.ts @@ -17,7 +17,7 @@ class ExtensionVariables implements UIExtensionVariables { let extensionVariables = new ExtensionVariables(); export { extensionVariables }; -export interface AzureAccountExtensionExports { +export interface AzureAccountExtensionExports { sessions: AzureSession[]; subscriptions: { session: AzureSession, subscription: SubscriptionModels.Subscription }[]; filters: { session: AzureSession, subscription: SubscriptionModels.Subscription }[]; @@ -45,6 +45,7 @@ export class Organization { accountName: string; accountUri: string; properties: {}; + isMSAOrg: boolean; } export class AzureSession { @@ -109,7 +110,7 @@ export enum ServiceConnectionType { export enum WebAppKind { WindowsApp = 'app', FunctionApp = 'functionapp', - LinuxApp ='app,linux', + LinuxApp = 'app,linux', LinuxContainerApp = 'app,linux,container' }