Skip to content

Commit

Permalink
Merge pull request #251 from hiyadav/master
Browse files Browse the repository at this point in the history
Features/choose right subscription (#55)
  • Loading branch information
vtbassmatt authored Sep 4, 2019
2 parents 18e439e + 7a6d894 commit 4d6e458
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
8 changes: 5 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
}
]
}
}
24 changes: 16 additions & 8 deletions src/configure/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -322,6 +320,7 @@ class PipelineConfigurer {

private async extractAzureResourceFromNode(node: any): Promise<void> {
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 {
Expand Down Expand Up @@ -352,6 +351,7 @@ class PipelineConfigurer {

private async getAzureDevOpsDetails(): Promise<void> {
try {
this.createAzureDevOpsClient();
if (this.inputs.sourceRepository.repositoryProvider === RepositoryProvider.AzureRepos) {
let repoDetails = AzureDevOpsHelper.getRepositoryDetailsFromRemoteUrl(this.inputs.sourceRepository.remoteUrl);
this.inputs.organizationName = repoDetails.orgnizationName;
Expand Down Expand Up @@ -434,14 +434,17 @@ class PipelineConfigurer {
// show available subscriptions and get the chosen one
let subscriptionList = extensionVariables.azureAccountExtensionApi.filters.map((subscriptionObject) => {
return <QuickPickItemWithData>{
label: <string>subscriptionObject.subscription.displayName,
data: subscriptionObject
label: `${<string>subscriptionObject.subscription.displayName}`,
data: subscriptionObject,
description: `${<string>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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/configure/helper/azureSessionHelper.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/configure/helper/telemetryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TelemetryHelper {
}
}

public setCurrentStep(stepName: string) : void{
public setCurrentStep(stepName: string): void {
this.actionContext.telemetry.properties.cancelStep = stepName;
}

Expand Down
5 changes: 3 additions & 2 deletions src/configure/model/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];
Expand Down Expand Up @@ -45,6 +45,7 @@ export class Organization {
accountName: string;
accountUri: string;
properties: {};
isMSAOrg: boolean;
}

export class AzureSession {
Expand Down Expand Up @@ -109,7 +110,7 @@ export enum ServiceConnectionType {
export enum WebAppKind {
WindowsApp = 'app',
FunctionApp = 'functionapp',
LinuxApp ='app,linux',
LinuxApp = 'app,linux',
LinuxContainerApp = 'app,linux,container'
}

Expand Down

0 comments on commit 4d6e458

Please sign in to comment.