mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Handle out of sync extension activations for encryption keys updated event (#22415)
This commit is contained in:
@@ -81,6 +81,13 @@ export class AzureAccountProviderService implements vscode.Disposable {
|
||||
return this._onEncryptionKeysUpdated;
|
||||
}
|
||||
|
||||
public async getEncryptionKeys(): Promise<CacheEncryptionKeys> {
|
||||
if (!this._cachePluginProvider) {
|
||||
await this.onDidChangeConfiguration();
|
||||
}
|
||||
return this._cachePluginProvider!.getCacheEncryptionKeys();
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
while (this._disposables.length) {
|
||||
const item = this._disposables.pop();
|
||||
@@ -167,6 +174,10 @@ export class AzureAccountProviderService implements vscode.Disposable {
|
||||
|
||||
// MSAL Cache Plugin
|
||||
this._cachePluginProvider = new MsalCachePluginProvider(tokenCacheKeyMsal, this._userStoragePath, this._credentialProvider, this._onEncryptionKeysUpdated);
|
||||
if (this._authLibrary === Constants.AuthLibrary.MSAL) {
|
||||
// Initialize cache provider and encryption keys
|
||||
await this._cachePluginProvider.init();
|
||||
}
|
||||
|
||||
const msalConfiguration: Configuration = {
|
||||
auth: {
|
||||
|
||||
@@ -53,10 +53,18 @@ export class FileEncryptionHelper {
|
||||
|
||||
// Emit event with cache encryption keys to send notification to provider services.
|
||||
if (this._authLibrary === AuthLibrary.MSAL && this._onEncryptionKeysUpdated) {
|
||||
this._onEncryptionKeysUpdated.fire({
|
||||
iv: this._ivBuffer.toString(this._bufferEncoding),
|
||||
key: this._keyBuffer.toString(this._bufferEncoding)
|
||||
});
|
||||
this._onEncryptionKeysUpdated.fire(this.getEncryptionKeys());
|
||||
Logger.verbose('FileEncryptionHelper: Fired encryption keys updated event.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides encryption keys in use for instant access.
|
||||
*/
|
||||
public getEncryptionKeys(): CacheEncryptionKeys {
|
||||
return {
|
||||
iv: this._ivBuffer!.toString(this._bufferEncoding),
|
||||
key: this._keyBuffer!.toString(this._bufferEncoding)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,14 @@ export class MsalCachePluginProvider {
|
||||
return this._msalFilePath + '.lockfile';
|
||||
}
|
||||
|
||||
public async init(): Promise<void> {
|
||||
await this._fileEncryptionHelper.init();
|
||||
}
|
||||
|
||||
public getCacheEncryptionKeys(): CacheEncryptionKeys {
|
||||
return this._fileEncryptionHelper.getEncryptionKeys();
|
||||
}
|
||||
|
||||
public getCachePlugin(): ICachePlugin {
|
||||
const lockFilePath = this.getLockfilePath();
|
||||
const beforeCacheAccess = async (cacheContext: TokenCacheContext): Promise<void> => {
|
||||
|
||||
4
extensions/azurecore/src/azurecore.d.ts
vendored
4
extensions/azurecore/src/azurecore.d.ts
vendored
@@ -321,6 +321,10 @@ declare module 'azurecore' {
|
||||
* by connection providers to read/write to the same access token cache for stable connectivity.
|
||||
*/
|
||||
onEncryptionKeysUpdated: vscode.Event<CacheEncryptionKeys>;
|
||||
/**
|
||||
* Fetches MSAL cache encryption keys currently in use.
|
||||
*/
|
||||
getEncryptionKeys(): Promise<CacheEncryptionKeys>;
|
||||
}
|
||||
|
||||
export type GetSubscriptionsResult = { subscriptions: azureResource.AzureResourceSubscription[], errors: Error[] };
|
||||
|
||||
@@ -241,7 +241,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
|
||||
query: string): Promise<azurecore.ResourceQueryResult<T>> {
|
||||
return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, query);
|
||||
},
|
||||
onEncryptionKeysUpdated: eventEmitter!.event
|
||||
onEncryptionKeysUpdated: eventEmitter!.event,
|
||||
async getEncryptionKeys(): Promise<azurecore.CacheEncryptionKeys> {
|
||||
if (!providerService) {
|
||||
throw new Error("Failed to initialize Azure account provider.");
|
||||
}
|
||||
return await providerService!.getEncryptionKeys();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user