-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Microsoft/saw/wizard
Add wizard and website creation code from vscode-azurewebservice
- Loading branch information
Showing
9 changed files
with
1,176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Event } from 'vscode'; | ||
import { ServiceClientCredentials } from 'ms-rest'; | ||
import { AzureEnvironment } from 'ms-rest-azure'; | ||
import { SubscriptionModels } from 'azure-arm-resource'; | ||
|
||
export type AzureLoginStatus = 'Initializing' | 'LoggingIn' | 'LoggedIn' | 'LoggedOut'; | ||
|
||
export interface AzureAccount { | ||
readonly status: AzureLoginStatus; | ||
readonly onStatusChanged: Event<AzureLoginStatus>; | ||
readonly sessions: AzureSession[]; | ||
readonly onSessionsChanged: Event<void>; | ||
readonly filters: AzureResourceFilter[]; | ||
readonly onFiltersChanged: Event<void>; | ||
} | ||
|
||
export interface AzureSession { | ||
readonly environment: AzureEnvironment; | ||
readonly userId: string; | ||
readonly tenantId: string; | ||
readonly credentials: ServiceClientCredentials; | ||
} | ||
|
||
export interface AzureResourceFilter { | ||
readonly session: AzureSession; | ||
readonly subscription: SubscriptionModels.Subscription; | ||
} | ||
|
||
export interface Credentials { | ||
readSecret(service: string, account: string): Thenable<string | undefined>; | ||
writeSecret(service: string, account: string, secret: string): Thenable<void>; | ||
deleteSecret(service: string, account: string): Thenable<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// TEMPORARILY DISABLE | ||
// tslint:disable:ordered-imports | ||
// tslint:disable:no-unexternalized-strings | ||
// tslint:disable:no-require-imports | ||
// tslint:disable:no-parameter-properties | ||
// tslint:disable:member-ordering | ||
// tslint:disable:typedef | ||
// tslint:disable:triple-equals | ||
// tslint:disable:variable-name | ||
// tslint:disable:member-access | ||
// tslint:disable:prefer-const | ||
// tslint:disable:max-classes-per-file | ||
// tslint:disable:no-var-keyword | ||
// tslint:disable:no-multiline-string | ||
// tslint:disable:prefer-template | ||
// tslint:disable:semicolon | ||
// tslint:disable:no-consecutive-blank-lines | ||
// tslint:disable:no-shadowed-variable | ||
// tslint:disable:no-constant-condition | ||
// tslint:disable:no-increment-decrement | ||
// tslint:disable:align | ||
// tslint:disable:no-empty | ||
// tslint:disable:no-non-null-assertion | ||
// tslint:disable:no-unnecessary-local-variable | ||
// tslint:disable:no-any | ||
|
||
// tslint:disable:newline-before-return | ||
// tslint:disable:no-single-line-block-comment | ||
// tslint:disable:interface-name | ||
// tslint:disable:function-name | ||
|
||
import { ExtensionContext, extensions, Disposable } from 'vscode'; | ||
import { ServiceClientCredentials } from 'ms-rest'; | ||
import { SubscriptionClient, SubscriptionModels } from 'azure-arm-resource'; | ||
import { AzureAccount, AzureSession, AzureLoginStatus } from './azure-account.api'; | ||
|
||
export class NotSignedInError extends Error { } | ||
|
||
export class CredentialError extends Error { } | ||
|
||
export class AzureAccountWrapper { | ||
readonly accountApi: AzureAccount; | ||
|
||
constructor(readonly extensionConext: ExtensionContext) { | ||
this.accountApi = extensions.getExtension<AzureAccount>('ms-vscode.azure-account')!.exports; | ||
} | ||
|
||
getAzureSessions(): AzureSession[] { | ||
const status = this.signInStatus; | ||
if (status !== 'LoggedIn') { | ||
throw new NotSignedInError(status) | ||
} | ||
return this.accountApi.sessions; | ||
} | ||
|
||
getCredentialByTenantId(tenantId: string): ServiceClientCredentials { | ||
const session = this.getAzureSessions().find(s => s.tenantId.toLowerCase() === tenantId.toLowerCase()); | ||
|
||
if (session) { | ||
return session.credentials; | ||
} | ||
|
||
throw new CredentialError(`Failed to get credential, tenant ${tenantId} not found.`); | ||
} | ||
|
||
get signInStatus(): AzureLoginStatus { | ||
return this.accountApi.status; | ||
} | ||
|
||
getFilteredSubscriptions(): SubscriptionModels.Subscription[] { | ||
return this.accountApi.filters.map<SubscriptionModels.Subscription>(filter => { | ||
return { | ||
id: filter.subscription.id, | ||
subscriptionId: filter.subscription.subscriptionId, | ||
tenantId: filter.session.tenantId, | ||
displayName: filter.subscription.displayName, | ||
state: filter.subscription.state, | ||
subscriptionPolicies: filter.subscription.subscriptionPolicies, | ||
authorizationSource: filter.subscription.authorizationSource | ||
}; | ||
}); | ||
} | ||
|
||
async getLocationsBySubscription(subscription: SubscriptionModels.Subscription): Promise<SubscriptionModels.Location[]> { | ||
const credential = this.getCredentialByTenantId(subscription.tenantId); | ||
const client = new SubscriptionClient(credential); | ||
const locations = <SubscriptionModels.Location[]>(await client.subscriptions.listLocations(subscription.subscriptionId)); | ||
return locations; | ||
} | ||
|
||
registerStatusChangedListener(listener: (e: AzureLoginStatus) => any, thisArg: any): Disposable { | ||
return this.accountApi.onStatusChanged(listener, thisArg, this.extensionConext.subscriptions); | ||
} | ||
|
||
registerFiltersChangedListener(listener: (e: void) => any, thisArg: any): Disposable { | ||
return this.accountApi.onFiltersChanged(listener, thisArg, this.extensionConext.subscriptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
export class UserCancelledError extends Error { } | ||
|
||
export class WizardFailedError extends Error { | ||
public readonly stepTitle: string; | ||
public readonly stepIndex: number; | ||
constructor(error: Error, stepTitle: string, stepIndex: number) { | ||
super(); | ||
this.message = error.message; | ||
this.stepTitle = stepTitle; | ||
this.stepIndex = stepIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// TEMPORARILY DISABLE | ||
// tslint:disable:export-name | ||
// tslint:disable:typedef | ||
|
||
// tslint:disable:newline-before-return | ||
|
||
import * as crypto from "crypto"; | ||
|
||
export namespace randomUtils { | ||
|
||
export function getRandomHexString(length: number): string { | ||
const buffer = crypto.randomBytes(Math.ceil(length / 2)); | ||
return buffer.toString('hex').slice(0, length); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// TEMPORARILY DISABLE | ||
// tslint:disable:export-name | ||
// tslint:disable:typedef | ||
// tslint:disable:strict-boolean-expressions | ||
// tslint:disable:no-unsafe-any | ||
|
||
// tslint:disable:newline-before-return | ||
// tslint:disable:interface-name | ||
|
||
export namespace uiUtils { | ||
|
||
export interface PartialList<T> extends Array<T> { | ||
nextLink?: string; | ||
} | ||
|
||
export async function listAll<T>(client: { listNext(nextPageLink: string): Promise<PartialList<T>>; }, first: Promise<PartialList<T>>): Promise<T[]> { | ||
const all: T[] = []; | ||
|
||
for (let list = await first; list.length || list.nextLink; list = list.nextLink ? await client.listNext(list.nextLink) : []) { | ||
all.push(...list); | ||
} | ||
|
||
return all; | ||
} | ||
|
||
export function getSignInCommandString(): string { | ||
return 'azure-account.login'; | ||
} | ||
|
||
} |
Oops, something went wrong.