Skip to content

Commit

Permalink
Revert deprecation of updateProfilesArrays method
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Dec 26, 2024
1 parent 4a82088 commit d88d09e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 62 deletions.
1 change: 0 additions & 1 deletion packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t
### Bug fixes

- Fixed an issue where the `responseTimeout` profile property was ignored for z/OSMF MVS and USS API calls. [#3225](https://github.com/zowe/zowe-explorer-vscode/issues/3225)
- Deprecated the method `ProfilesCache.updateProfilesArrays`. Use `ProfilesCache.updateCachedProfile` instead, which handles updating credentials cached in memory when `autoStore` is false. [#3120](https://github.com/zowe/zowe-explorer-vscode/issues/3120)
- Updated the `@zowe/cli` dependency to v7.29.7 for technical currency. [#3342](https://github.com/zowe/zowe-explorer-vscode/pull/3342)

## `2.18.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,35 +230,6 @@ describe("ProfilesCache", () => {
expect((profCache as any).defaultProfileByType.get("zosmf").profile).toMatchObject(lpar2Profile.profile);
});

it("updateCachedProfile should refresh all profiles when autoStore is true", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
jest.spyOn(profCache, "getProfileInfo").mockResolvedValueOnce({
getTeamConfig: jest.fn().mockReturnValue({ properties: { autoStore: true } }),
} as unknown as zowe.imperative.ProfileInfo);
const refreshSpy = jest.spyOn(profCache, "refresh").mockImplementation();
await profCache.updateCachedProfile({
...lpar1Profile,
profile: lpar2Profile.profile,
} as zowe.imperative.IProfileLoaded);
expect(refreshSpy).toHaveBeenCalledTimes(1);
});

it("updateCachedProfile should update cached profile when autoStore is false", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
profCache.allProfiles = [lpar1Profile as zowe.imperative.IProfileLoaded];
(profCache as any).defaultProfileByType = new Map([["zosmf", { ...profCache.allProfiles[0] }]]);
expect(profCache.allProfiles[0].profile).toMatchObject(lpar1Profile.profile);
jest.spyOn(profCache, "getProfileInfo").mockResolvedValueOnce({
getTeamConfig: jest.fn().mockReturnValue({ properties: { autoStore: false } }),
} as unknown as zowe.imperative.ProfileInfo);
await profCache.updateCachedProfile({
...lpar1Profile,
profile: lpar2Profile.profile,
} as zowe.imperative.IProfileLoaded);
expect(profCache.allProfiles[0].profile).toMatchObject(lpar2Profile.profile);
expect((profCache as any).defaultProfileByType.get("zosmf").profile).toMatchObject(lpar2Profile.profile);
});

it("getDefaultProfile should find default profile given type", () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
(profCache as any).defaultProfileByType = new Map([["zosmf", lpar1Profile]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("ZoweVsCodeExtension", () => {
mergeArgsForProfile: jest.fn().mockReturnValue({ knownArgs: [] }),
}),
refresh: jest.fn(),
updateCachedProfile: jest.fn(),
updateProfilesArrays: jest.fn(),
};

beforeEach(() => {
Expand Down Expand Up @@ -376,7 +376,7 @@ describe("ZoweVsCodeExtension", () => {
expect(loginSpy).not.toHaveBeenCalled();
expect(testSpy).not.toHaveBeenCalled();
expect(testCache.updateBaseProfileFileLogin).toHaveBeenCalledWith(baseProfile, updProfile, false);
expect(testCache.updateCachedProfile).toHaveBeenCalledWith(serviceProfile, testNode, testRegister);
expect(testCache.updateProfilesArrays).toHaveBeenCalledWith(serviceProfile, testNode);
quickPickMock.mockRestore();
});
});
Expand Down Expand Up @@ -461,7 +461,6 @@ describe("ZoweVsCodeExtension", () => {
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
updateCachedProfile: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword");
const saveCredentialsSpy = jest.spyOn(ZoweVsCodeExtension as any, "saveCredentials");
Expand All @@ -487,7 +486,6 @@ describe("ZoweVsCodeExtension", () => {
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
updateCachedProfile: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword");
const saveCredentialsSpy = jest.spyOn(ZoweVsCodeExtension as any, "saveCredentials");
Expand Down Expand Up @@ -516,7 +514,6 @@ describe("ZoweVsCodeExtension", () => {
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
updateCachedProfile: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword");
jest.spyOn(Gui, "showMessage").mockResolvedValueOnce("yes");
Expand All @@ -543,7 +540,6 @@ describe("ZoweVsCodeExtension", () => {
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
updateCachedProfile: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword");
jest.spyOn(Gui, "showMessage").mockResolvedValueOnce(undefined);
Expand Down
22 changes: 2 additions & 20 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ export class ProfilesCache {

/**
* Updates profile in allProfiles array and if default updates defaultProfileByType
* @deprecated Use `updateCachedProfile` instead
* @param {string} profileLoaded
* @param {IZoweNodeType} profileNode
* @returns {void}
*/
public updateProfilesArrays(profileLoaded: zowe.imperative.IProfileLoaded): void {
public updateProfilesArrays(profileLoaded: zowe.imperative.IProfileLoaded, profileNode?: IZoweNodeType): void {
// update allProfiles array
const promptedTypeIndex = this.allProfiles.findIndex(
(profile) => profile?.type === profileLoaded?.type && profile?.name === profileLoaded?.name
Expand All @@ -143,24 +143,6 @@ export class ProfilesCache {
if (defaultProf?.name === profileLoaded?.name) {
this.defaultProfileByType.set(profileLoaded?.type, profileLoaded);
}
}

public async updateCachedProfile(
profileLoaded: zowe.imperative.IProfileLoaded,
profileNode?: IZoweNodeType,
zeRegister?: ZoweExplorerApi.IApiRegisterClient
): Promise<void> {
if ((await this.getProfileInfo()).getTeamConfig().properties.autoStore) {
await this.refresh(zeRegister);
} else {
// Note: When autoStore is disabled, nested profiles within this service profile may not have their credentials updated.
const profIndex = this.allProfiles.findIndex((profile) => profile.type === profileLoaded.type && profile.name === profileLoaded.name);
this.allProfiles[profIndex].profile = profileLoaded.profile;
const defaultProf = this.defaultProfileByType.get(profileLoaded.type);
if (defaultProf != null && defaultProf.name === profileLoaded.name) {
this.defaultProfileByType.set(profileLoaded.type, profileLoaded);
}
}
profileNode?.setProfileToChoice(profileLoaded);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class ZoweVsCodeExtension {
await profInfo.updateProperty({ ...upd, property: "user", value: creds[0], setSecure });
await profInfo.updateProperty({ ...upd, property: "password", value: creds[1], setSecure });
}
await cache.updateCachedProfile(loadProfile, undefined, apiRegister);
await cache.refresh(apiRegister);

return loadProfile;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ export class ZoweVsCodeExtension {

await cache.updateBaseProfileFileLogin(profileToUpdate, updBaseProfile, !connOk);
serviceProfile.profile = { ...serviceProfile.profile, ...updBaseProfile };
await cache.updateCachedProfile(serviceProfile, node, zeRegister);
cache.updateProfilesArrays(serviceProfile, node);
return true;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ export class ZoweVsCodeExtension {
const connOk = serviceProfile.profile.host === baseProfile.profile.host && serviceProfile.profile.port === baseProfile.profile.port;
await cache.updateBaseProfileFileLogout(connOk ? baseProfile : serviceProfile);
serviceProfile.profile = { ...serviceProfile.profile, tokenType: undefined, tokenValue: undefined };
await cache.updateCachedProfile(serviceProfile, undefined, zeRegister);
cache.updateProfilesArrays(serviceProfile);
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/zowe-explorer/src/Profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ export class Profiles extends ProfilesCache {
return; // See https://github.com/zowe/zowe-explorer-vscode/issues/1827
}

const returnValue: string[] = [promptInfo.profile.user, promptInfo.profile.password];
const returnValue: string[] = [promptInfo.profile.user, promptInfo.profile.password, promptInfo.profile.base64EncodedAuth];
this.updateProfilesArrays(promptInfo);
return returnValue;
}

Expand Down Expand Up @@ -1503,11 +1504,11 @@ export class Profiles extends ProfilesCache {
!serviceProfile.profile.tokenType?.startsWith(zowe.imperative.SessConstants.TOKEN_TYPE_APIML)
) {
await ZoweExplorerApiRegister.getInstance().getCommonApi(serviceProfile).logout(node.getSession());

Check warning on line 1506 in packages/zowe-explorer/src/Profiles.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/Profiles.ts#L1506

Added line #L1506 was not covered by tests
await Profiles.getInstance().updateCachedProfile(serviceProfile, node);
} else {
await ZoweVsCodeExtension.logoutWithBaseProfile(serviceProfile, ZoweExplorerApiRegister.getInstance(), this);
}
Gui.showMessage(localize("ssoLogout.successful", "Logout from authentication service was successful for {0}.", serviceProfile.name));
await Profiles.getInstance().refresh(ZoweExplorerApiRegister.getInstance());
} catch (error) {
const message = localize("ssoLogout.error", "Unable to log out with {0}. {1}", serviceProfile.name, error?.message);
ZoweLogger.error(message);
Expand Down Expand Up @@ -1558,7 +1559,7 @@ export class Profiles extends ProfilesCache {
session.ISession.user = creds[0];
session.ISession.password = creds[1];
await ZoweExplorerApiRegister.getInstance().getCommonApi(serviceProfile).login(session);
await Profiles.getInstance().updateCachedProfile(serviceProfile, node);
Profiles.getInstance().updateProfilesArrays(serviceProfile, node);

Check warning on line 1562 in packages/zowe-explorer/src/Profiles.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/Profiles.ts#L1562

Added line #L1562 was not covered by tests
return true;
}

Expand Down

0 comments on commit d88d09e

Please sign in to comment.