Enable azure cloud console in ADS (#8546)

* initial changes

* Enable cloud console

* Delete unnecessary code

* error handling

* error handling

* Deal with promises

* Fix externals

* Fix externals for ws

* Cleanup name of terminal

* Update yarn.lock

* Fix yarn.lock

* Fix externals

* Cleanup parts of the code

* Fix more issues

* Fix cloud terminal

* Go back to our client ID

* Fix message

* Respect preferred location

* Fix govt cloud

* Some more messaging

* Enable items on right click

* Some feedback

* Change to status message
This commit is contained in:
Amir Omidi
2020-03-31 18:39:58 -07:00
committed by GitHub
parent 2b111c6bfd
commit fc726c1477
18 changed files with 521 additions and 302 deletions

View File

@@ -124,6 +124,7 @@ export abstract class AzureAuth implements vscode.Disposable {
this.metadata.settings.sqlResource,
this.metadata.settings.graphResource,
this.metadata.settings.ossRdbmsResource,
this.metadata.settings.microsoftResource,
this.metadata.settings.azureKeyVaultResource
];
@@ -153,6 +154,7 @@ export abstract class AzureAuth implements vscode.Disposable {
try {
await this.refreshAccessToken(account.key, refreshToken);
} catch (ex) {
account.isStale = true;
if (ex.message) {
await vscode.window.showErrorMessage(ex.message);
}
@@ -163,6 +165,10 @@ export abstract class AzureAuth implements vscode.Disposable {
public async getSecurityToken(account: azdata.Account, azureResource: azdata.AzureResource): Promise<TokenResponse | undefined> {
if (account.isStale === true) {
return undefined;
}
const resource = this.resources.find(s => s.azureResourceId === azureResource);
if (!resource) {
return undefined;
@@ -199,8 +205,13 @@ export abstract class AzureAuth implements vscode.Disposable {
if (!baseToken) {
return undefined;
}
try {
await this.refreshAccessToken(account.key, baseToken.refreshToken, tenant, resource);
} catch (ex) {
account.isStale = true;
return undefined;
}
await this.refreshAccessToken(account.key, baseToken.refreshToken, tenant, resource);
cachedTokens = await this.getCachedToken(account.key, resource.id, tenant.id);
if (!cachedTokens) {
return undefined;
@@ -349,8 +360,7 @@ export abstract class AzureAuth implements vscode.Disposable {
return { accessToken, refreshToken, tokenClaims };
} catch (err) {
console.dir(err);
const msg = localize('azure.noToken', "Retrieving the token failed.");
const msg = localize('azure.noToken', "Retrieving the Azure token failed. Please sign in again.");
vscode.window.showErrorMessage(msg);
throw new Error(err);
}

View File

@@ -69,7 +69,7 @@ export class AzureAuthCodeGrant extends AzureAuth {
serverPort = await this.server.startup();
} catch (err) {
const msg = localize('azure.serverCouldNotStart', 'Server could not start. This could be a permissions error or an incompatibility on your system. You can try enabling device code authentication from settings.');
await vscode.window.showErrorMessage(msg);
vscode.window.showErrorMessage(msg);
console.dir(err);
return undefined;
}
@@ -181,7 +181,7 @@ export class AzureAuthCodeGrant extends AzureAuth {
refreshToken = rt;
} catch (ex) {
if (ex.msg) {
await vscode.window.showErrorMessage(ex.msg);
vscode.window.showErrorMessage(ex.msg);
}
console.log(ex);
}
@@ -199,7 +199,7 @@ export class AzureAuthCodeGrant extends AzureAuth {
} catch (ex) {
console.log(ex);
if (ex.msg) {
await vscode.window.showErrorMessage(ex.msg);
vscode.window.showErrorMessage(ex.msg);
authCompleteDeferred.reject(ex);
} else {
authCompleteDeferred.reject(new Error('There was an issue when storing the cache.'));

View File

@@ -128,7 +128,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
if (this.authMappings.size === 0) {
console.log('No auth method was enabled.');
await vscode.window.showErrorMessage(noAuthAvailable);
vscode.window.showErrorMessage(noAuthAvailable);
return { canceled: true };
}
@@ -145,7 +145,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
if (!pick) {
console.log('No auth method was selected.');
await vscode.window.showErrorMessage(noAuthSelected);
vscode.window.showErrorMessage(noAuthSelected);
return { canceled: true };
}

View File

@@ -69,6 +69,11 @@ interface Settings {
*/
signInResourceId?: string;
/**
* Information that describes the Microsoft resource management resource
*/
microsoftResource?: Resource
/**
* Information that describes the AAD graph resource
*/

View File

@@ -18,6 +18,11 @@ const publicAzureSettings: ProviderSettings = {
host: 'https://login.microsoftonline.com/',
clientId: 'a69788c6-1d43-44ed-9ca3-b83e194da255',
signInResourceId: 'https://management.core.windows.net/',
microsoftResource: {
id: 'marm',
endpoint: 'https://management.core.windows.net/',
azureResourceId: AzureResource.MicrosoftResourceManagement
},
graphResource: {
id: 'graph',
endpoint: 'https://graph.microsoft.com',
@@ -62,6 +67,11 @@ const usGovAzureSettings: ProviderSettings = {
host: 'https://login.microsoftonline.us/',
clientId: 'a69788c6-1d43-44ed-9ca3-b83e194da255',
signInResourceId: 'https://management.core.usgovcloudapi.net/',
microsoftResource: {
id: 'marm',
endpoint: 'https://management.core.usgovcloudapi.net/',
azureResourceId: AzureResource.MicrosoftResourceManagement
},
graphResource: {
id: 'graph',
endpoint: 'https://graph.windows.net',