Skip to content

Commit

Permalink
Update Azure core packages and additional error handling (#24500)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored and siyangMicrosoft committed Oct 12, 2023
1 parent 0f54720 commit c39e377
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 115 deletions.
6 changes: 3 additions & 3 deletions build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"@actions/core": "1.9.1",
"@actions/github": "2.1.1",
"@azure/cosmos": "^3.17.3",
"@azure/identity": "^2.1.0",
"@azure/storage-blob": "^12.13.0",
"@azure/identity": "^3.3.0",
"@azure/storage-blob": "^12.16.0",
"@electron/get": "^1.12.4",
"@types/ansi-colors": "^3.2.0",
"@types/azure": "0.9.19",
"@types/azure": "0.9.20",
"@types/byline": "^4.2.32",
"@types/cssnano": "^4.0.0",
"@types/debounce": "^1.0.0",
Expand Down
82 changes: 47 additions & 35 deletions build/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
"@azure/abort-controller" "^1.0.0"
tslib "^2.2.0"

"@azure/core-auth@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.5.0.tgz#a41848c5c31cb3b7c84c409885267d55a2c92e44"
integrity sha512-udzoBuYG1VBoHVohDTrvKjyzel34zt77Bhp7dQntVGGD0ehVq48owENbBG8fIgkHRNUBQH5k1r0hpoMu5L8+kw==
dependencies:
"@azure/abort-controller" "^1.0.0"
"@azure/core-util" "^1.1.0"
tslib "^2.2.0"

"@azure/core-client@^1.4.0":
version "1.6.1"
resolved "https://registry.npmjs.org/@azure/core-client/-/core-client-1.6.1.tgz"
Expand Down Expand Up @@ -140,6 +149,14 @@
dependencies:
tslib "^2.2.0"

"@azure/core-util@^1.1.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.5.0.tgz#ffe49c3e867044da67daeb8122143fa065e1eb0e"
integrity sha512-GZBpVFDtQ/15hW1OgBcRdT4Bl7AEpcEZqLfbAvOtm1CQUncKWiYapFHVD588hmlV27NbOOtSm3cnLF3lvoHi4g==
dependencies:
"@azure/abort-controller" "^1.0.0"
tslib "^2.2.0"

"@azure/core-util@^1.1.1":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.3.0.tgz#ea736a0cb0437ac0d049d57ff627c240b41479ec"
Expand Down Expand Up @@ -167,21 +184,21 @@
universal-user-agent "^6.0.0"
uuid "^8.3.0"

"@azure/identity@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@azure/identity/-/identity-2.1.0.tgz#89f0bfc1d1264dfd3d0cb19837c33a9c6706d548"
integrity sha512-BPDz1sK7Ul9t0l9YKLEa8PHqWU4iCfhGJ+ELJl6c8CP3TpJt2urNCbm0ZHsthmxRsYoMPbz2Dvzj30zXZVmAFw==
"@azure/identity@^3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@azure/identity/-/identity-3.3.0.tgz#0166cfdfa892d73eeb69c390dac91796c6f85f79"
integrity sha512-gISa/dAAxrWt6F2WiDXZY0y2xY4MLlN2wkNW4cPuq5OgPQKLSkxLc4I2WR04puTfZyQZnpXbAapAMEj1b96fgg==
dependencies:
"@azure/abort-controller" "^1.0.0"
"@azure/core-auth" "^1.3.0"
"@azure/core-auth" "^1.5.0"
"@azure/core-client" "^1.4.0"
"@azure/core-rest-pipeline" "^1.1.0"
"@azure/core-tracing" "^1.0.0"
"@azure/core-util" "^1.0.0"
"@azure/logger" "^1.0.0"
"@azure/msal-browser" "^2.26.0"
"@azure/msal-common" "^7.0.0"
"@azure/msal-node" "^1.10.0"
"@azure/msal-browser" "^2.37.1"
"@azure/msal-common" "^13.1.0"
"@azure/msal-node" "^1.17.3"
events "^3.0.0"
jws "^4.0.0"
open "^8.0.0"
Expand All @@ -196,36 +213,31 @@
dependencies:
tslib "^2.0.0"

"@azure/msal-browser@^2.26.0":
version "2.37.0"
resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-2.37.0.tgz#32d7af74eef53f2692f8a9d6bd6818c78faf4c1b"
integrity sha512-YNGD/W/tw/5wDWlXOfmrVILaxVsorVLxYU2ovmL1PDvxkdudbQRyGk/76l4emqgDAl/kPQeqyivxjOU6w1YfvQ==
"@azure/msal-browser@^2.37.1":
version "2.38.2"
resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-2.38.2.tgz#707725c892258fe6b3af4dd410e1daff608521b5"
integrity sha512-71BeIn2we6LIgMplwCSaMq5zAwmalyJR3jFcVOZxNVfQ1saBRwOD+P77nLs5vrRCedVKTq8RMFhIOdpMLNno0A==
dependencies:
"@azure/msal-common" "13.0.0"

"@azure/[email protected]":
version "13.0.0"
resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-13.0.0.tgz#9c39184903b5d0fd6e643ccc12193fae220e912b"
integrity sha512-GqCOg5H5bouvLij9NFXFkh+asRRxsPBRwnTDsfK7o0KcxYHJbuidKw8/VXpycahGXNxgtuhqtK/n5he+5NhyEA==
"@azure/msal-common" "13.3.0"

"@azure/msal-common@^7.0.0":
version "7.6.0"
resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-7.6.0.tgz#b52e97ef540275f72611cff57937dfa0b34cdcca"
integrity sha512-XqfbglUTVLdkHQ8F9UQJtKseRr3sSnr9ysboxtoswvaMVaEfvyLtMoHv9XdKUfOc0qKGzNgRFd9yRjIWVepl6Q==
"@azure/msal-common@13.3.0", "@azure/msal-common@^13.1.0":
version "13.3.0"
resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-13.3.0.tgz#dfa39810e0fbce6e07ca85a2cf305da58d30b7c9"
integrity sha512-/VFWTicjcJbrGp3yQP7A24xU95NiDMe23vxIU1U6qdRPFsprMDNUohMudclnd+WSHE4/McqkZs/nUU3sAKkVjg==

"@azure/msal-node@^1.10.0":
version "1.17.2"
resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-1.17.2.tgz#42566443e0cdf476bcb43854c9fe47a2def40baf"
integrity sha512-l8edYnA2LQj4ue3pjxVz1Qy4HuU5xbcoebfe2bGTRvBL9Q6n2Df47aGftkLIyimD1HxHuA4ZZOe23a/HshoYXw==
"@azure/msal-node@^1.17.3":
version "1.18.3"
resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-1.18.3.tgz#e265556d4db0340590eeab5341469fb6740251d0"
integrity sha512-lI1OsxNbS/gxRD4548Wyj22Dk8kS7eGMwD9GlBZvQmFV8FJUXoXySL1BiNzDsHUE96/DS/DHmA+F73p1Dkcktg==
dependencies:
"@azure/msal-common" "13.0.0"
"@azure/msal-common" "13.3.0"
jsonwebtoken "^9.0.0"
uuid "^8.3.0"

"@azure/storage-blob@^12.13.0":
version "12.14.0"
resolved "https://registry.yarnpkg.com/@azure/storage-blob/-/storage-blob-12.14.0.tgz#32d3e5fa3bb2a12d5d44b186aed11c8e78f00178"
integrity sha512-g8GNUDpMisGXzBeD+sKphhH5yLwesB4JkHr1U6be/X3F+cAMcyGLPD1P89g2M7wbEtUJWoikry1rlr83nNRBzg==
"@azure/storage-blob@^12.16.0":
version "12.16.0"
resolved "https://registry.yarnpkg.com/@azure/storage-blob/-/storage-blob-12.16.0.tgz#c41fb1e538d6f6e2a6756bfcc69382eededf4fa1"
integrity sha512-jz33rUSUGUB65FgYrTRgRDjG6hdPHwfvHe+g/UrwVG8MsyLqSxg9TaW7Yuhjxu1v1OZ5xam2NU6+IpCN0xJO8Q==
dependencies:
"@azure/abort-controller" "^1.0.0"
"@azure/core-http" "^3.0.0"
Expand Down Expand Up @@ -540,10 +552,10 @@
resolved "https://registry.npmjs.org/@types/ansi-colors/-/ansi-colors-3.2.0.tgz"
integrity sha512-0caWAhXht9N2lOdMzJLXybsSkYCx1QOdxx6pae48tswI9QV3DFX26AoOpy0JxwhCb+zISTqmd6H8t9Zby9BoZg==

"@types/[email protected].19":
version "0.9.19"
resolved "https://registry.npmjs.org/@types/azure/-/azure-0.9.19.tgz"
integrity sha1-Gmqb2Fa0N93s8/n8hAemg8hpugI=
"@types/[email protected].20":
version "0.9.20"
resolved "https://registry.yarnpkg.com/@types/azure/-/azure-0.9.20.tgz#ce00ed2546c5dc5c63489162c804a2f773b95cfa"
integrity sha512-5+YeTSAruOEjCtmRJlqnhUTJtA4+kjPhOwUUT6Eo4O3MDQIlGzGwJw70umHgaSw0hZoWIB2g/iCRXtmesn9F2w==
dependencies:
"@types/node" "*"

Expand Down
9 changes: 5 additions & 4 deletions extensions/azurecore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,13 @@
"hasAzureResourceProviders": true
},
"dependencies": {
"@azure/arm-resourcegraph": "^4.0.0",
"@azure/arm-resourcegraph": "^4.2.1",
"@azure/arm-subscriptions": "^3.0.0",
"@azure/msal-common": "^11.0.0",
"@azure/msal-node": "^1.16.0",
"@azure/msal-common": "^13.3.0",
"@azure/msal-node": "^1.18.3",
"@azure/ms-rest-js": "^2.2.0",
"@azure/storage-blob": "^12.13.0",
"axios": "^0.27.2",
"axios": "^1.5.0",
"lockfile": "1.0.4",
"@microsoft/ads-extension-telemetry": "^3.0.1",
"node-fetch": "^2.6.7",
Expand Down
12 changes: 8 additions & 4 deletions extensions/azurecore/src/account-provider/auths/azureAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const localize = nls.loadMessageBundle();

export type GetTenantsResponseData = {
value: TenantResponse[];
error?: string;
}

export abstract class AzureAuth implements vscode.Disposable {
Expand All @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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> { }

Expand Down
32 changes: 18 additions & 14 deletions extensions/azurecore/src/account-provider/utils/msalCachePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.`);
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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';

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 {
Expand Down
Loading

0 comments on commit c39e377

Please sign in to comment.