mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
Update Azure core packages and additional error handling (#24500)
This commit is contained in:
@@ -32,6 +32,7 @@ const localize = nls.loadMessageBundle();
|
||||
|
||||
export type GetTenantsResponseData = {
|
||||
value: TenantResponse[];
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export abstract class AzureAuth implements vscode.Disposable {
|
||||
@@ -45,6 +46,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
protected readonly clientId: string;
|
||||
protected readonly resources: Resource[];
|
||||
protected readonly httpClient: HttpClient;
|
||||
private readonly _disposableStore: vscode.Disposable[];
|
||||
|
||||
constructor(
|
||||
protected readonly metadata: AzureAccountProviderMetadata,
|
||||
@@ -55,7 +57,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
protected readonly authType: AzureAuthType,
|
||||
public readonly userFriendlyName: string
|
||||
) {
|
||||
|
||||
this._disposableStore = [];
|
||||
this.loginEndpointUrl = this.metadata.settings.host;
|
||||
this.commonTenant = {
|
||||
id: 'common',
|
||||
@@ -99,6 +101,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
this.scopes = [...this.metadata.settings.scopes];
|
||||
this.scopesString = this.scopes.join(' ');
|
||||
this.httpClient = getProxyEnabledHttpClient();
|
||||
this._disposableStore.push(this.uriEventEmitter);
|
||||
}
|
||||
|
||||
public async startLogin(): Promise<AzureAccount | azdata.PromptFailedResult> {
|
||||
@@ -510,8 +513,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
this.clientApplication.clearCache();
|
||||
|
||||
// unlink both cache files
|
||||
await this.msalCacheProvider.unlinkMsalCache();
|
||||
await this.msalCacheProvider.unlinkLocalCache();
|
||||
await this.msalCacheProvider.unlinkCacheFiles();
|
||||
|
||||
// Delete Encryption Keys
|
||||
await this.msalCacheProvider.clearCacheEncryptionKeys();
|
||||
@@ -541,7 +543,9 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
await this.msalCacheProvider.clearAccountFromLocalCache(accountKey.accountId);
|
||||
}
|
||||
|
||||
public async dispose() { }
|
||||
public async dispose() {
|
||||
this._disposableStore.forEach(d => d.dispose());
|
||||
}
|
||||
|
||||
public async autoOAuthCancelled(): Promise<void> { }
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export class MsalCachePluginProvider {
|
||||
// Handle deserialization error in cache file in case file gets corrupted.
|
||||
// Clearing cache here will ensure account is marked stale so re-authentication can be triggered.
|
||||
Logger.verbose(`MsalCachePlugin: Error occurred when trying to read cache file, file will be deleted: ${e.message}`);
|
||||
await fsPromises.unlink(this._msalCacheConfiguration.cacheFilePath);
|
||||
await this.unlinkCache(this._msalCacheConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,17 +177,11 @@ export class MsalCachePluginProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes Msal access token cache file
|
||||
* Deletes both cache files.
|
||||
*/
|
||||
public async unlinkMsalCache(): Promise<void> {
|
||||
await fsPromises.unlink(this._msalCacheConfiguration.cacheFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes local access token cache file.
|
||||
*/
|
||||
public async unlinkLocalCache(): Promise<void> {
|
||||
await fsPromises.unlink(this._localCacheConfiguration.cacheFilePath);
|
||||
public async unlinkCacheFiles(): Promise<void> {
|
||||
await this.unlinkCache(this._msalCacheConfiguration);
|
||||
await this.unlinkCache(this._localCacheConfiguration);
|
||||
}
|
||||
|
||||
//#region Private helper methods
|
||||
@@ -225,13 +219,12 @@ export class MsalCachePluginProvider {
|
||||
else {
|
||||
Logger.error(`MsalCachePlugin: Failed to read from cache file: ${e}`);
|
||||
Logger.verbose(`MsalCachePlugin: Error occurred when trying to read cache file ${currentConfig.name}, file will be deleted: ${e.message}`);
|
||||
await fsPromises.unlink(currentConfig.cacheFilePath);
|
||||
|
||||
await this.unlinkCache(currentConfig);
|
||||
// Ensure both configurations are not same.
|
||||
if (currentConfig.name !== alternateConfig.name) {
|
||||
// Delete alternate cache file as well.
|
||||
alternateConfig.lockTaken = await this.waitAndLock(alternateConfig.lockFilePath, alternateConfig.lockTaken);
|
||||
await fsPromises.unlink(alternateConfig.cacheFilePath);
|
||||
await this.unlinkCache(alternateConfig);
|
||||
lockFile.unlockSync(alternateConfig.lockFilePath);
|
||||
alternateConfig.lockTaken = false;
|
||||
Logger.verbose(`MsalCachePlugin: Cache file for ${alternateConfig.name} cache also deleted.`);
|
||||
@@ -276,5 +269,16 @@ export class MsalCachePluginProvider {
|
||||
}
|
||||
return lockTaken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes access token cache file for specified config
|
||||
*/
|
||||
private async unlinkCache(config: CacheConfiguration): Promise<void> {
|
||||
try {
|
||||
await fsPromises.unlink(config.cacheFilePath);
|
||||
} catch (e) {
|
||||
Logger.info(`An error occurred when clearing ${config.name} Cache, safely ignored: ${e}`);
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as vscode from 'vscode';
|
||||
import { SubscriptionClient } from '@azure/arm-subscriptions';
|
||||
import { AzureAccount, azureResource } from 'azurecore';
|
||||
import { IAzureResourceSubscriptionService } from '../interfaces';
|
||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||
import { AzureSubscriptionError } from '../errors';
|
||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||
import { Logger } from '../../utils/Logger';
|
||||
@@ -16,6 +15,7 @@ import { Logger } from '../../utils/Logger';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { TenantIgnoredError } from '../../utils/TenantIgnoredError';
|
||||
import { multiple_matching_tokens_error } from '../../constants';
|
||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class AzureResourceSubscriptionService implements IAzureResourceSubscriptionService {
|
||||
|
||||
Reference in New Issue
Block a user