Skip to content

Commit

Permalink
refactor: unlock all profiles after vault changed
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
  • Loading branch information
traeok committed Feb 25, 2025
1 parent d97d5c1 commit 3eeb67b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ describe("AuthHandler.waitForUnlock", () => {
});
});

describe("AuthHandler.unlockAllProfiles", () => {
it("unlocks all profiles in the AuthHandler.profileLocks map", async () => {
const mutexAuthPrompt = new Mutex();
const mutexProfile = new Mutex();
const releaseAuthPromptMutex = jest.spyOn(mutexAuthPrompt, "release");
const releaseProfileMutex = jest.spyOn(mutexProfile, "release");
(AuthHandler as any).authPromptLocks.set(TEST_PROFILE_NAME, mutexAuthPrompt);
(AuthHandler as any).profileLocks.set(TEST_PROFILE_NAME, mutexProfile);

AuthHandler.unlockAllProfiles();
expect(releaseAuthPromptMutex).toHaveBeenCalledTimes(1);
expect(releaseProfileMutex).toHaveBeenCalledTimes(1);
(AuthHandler as any).authPromptLocks.clear();
(AuthHandler as any).profileLocks.clear();
});
});

describe("AuthHandler.isProfileLocked", () => {
it("returns true if the profile is locked", async () => {
await AuthHandler.lockProfile(TEST_PROFILE_NAME);
Expand Down
15 changes: 15 additions & 0 deletions packages/zowe-explorer-api/src/profiles/AuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ export class AuthHandler {
}
}

/**
* Releases locks for all profiles.
* Used for scenarios such as the `onVaultChanged` event, where we don't know what secure values have changed,
* but we can't assume that the profile still has invalid credentials.
*/
public static unlockAllProfiles(): void {
for (const mutex of this.authPromptLocks.values()) {
mutex.release();
}

for (const mutex of this.profileLocks.values()) {
mutex.release();
}
}

/**
* Checks whether the given profile has its lock acquired.
* @param profile The profile to check
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer/src/trees/shared/SharedInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ZoweScheme,
ZoweVsCodeExtension,
imperative,
AuthHandler,
} from "@zowe/zowe-explorer-api";
import { SharedActions } from "./SharedActions";
import { SharedHistoryView } from "./SharedHistoryView";
Expand Down Expand Up @@ -367,6 +368,7 @@ export class SharedInit {
try {
const zoweWatcher = imperative.EventOperator.getWatcher().subscribeUser(imperative.ZoweUserEvents.ON_VAULT_CHANGED, async () => {
ZoweLogger.info(vscode.l10n.t("Changes in the credential vault detected, refreshing Zowe Explorer."));
AuthHandler.unlockAllProfiles();
await ProfilesUtils.readConfigFromDisk();
await SharedActions.refreshAll();
ZoweExplorerApiRegister.getInstance().onVaultUpdateEmitter.fire(Validation.EventType.UPDATE);
Expand Down

0 comments on commit 3eeb67b

Please sign in to comment.