Skip to content

Commit

Permalink
Merge branch 'next' into fix/ext-refresh-errors
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed Jul 24, 2024
2 parents a2d1594 + 3ba345a commit e221a64
Show file tree
Hide file tree
Showing 19 changed files with 990 additions and 403 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@
"test:parallel": "pnpm -r --parallel --color test",
"package": "pnpm -r --sequential package",
"preinstall": "npx only-allow pnpm",
"update-sdks": "pnpm -r update \"@zowe/*@next\" \"!@zowe/zowe-explorer-api\""
"update-sdks": "pnpm -r update \"@zowe/*@next\" \"!@zowe/zowe-explorer-api\" \"!@zowe/zos-ftp-for-zowe-cli\""
}
}
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t
- Updated the `ProfilesCache.getProfiles` method to return empty list instead of undefined when there are no profiles. [#2947](https://github.com/zowe/zowe-explorer-vscode/pull/2947)
- Added PEM certificate support as an authentication method for logging into the API ML. [#2621](https://github.com/zowe/zowe-explorer-vscode/issues/2621)
- Deprecated the `getUSSDocumentFilePath` function on the `IZoweTreeNode` interface as Zowe Explorer no longer uses the local file system for storing USS files. **No replacement is planned**; please access data from tree nodes using their [resource URIs](https://github.com/zowe/zowe-explorer-vscode/wiki/FileSystemProvider#operations-for-extenders) instead. [#2968](https://github.com/zowe/zowe-explorer-vscode/pull/2968)
- **Next Breaking:** Changed `ProfilesCache.convertV1ProfToConfig` method to be a static method that requires `ProfileInfo` instance as a parameter.

### Bug fixes

- Fixed an issue where the `onProfilesUpdate` event did not fire after secure credentials were updated. [#2822](https://github.com/zowe/zowe-explorer-vscode/issues/2822)
- Fixed an issue where `ProfilesCache` may return missing or incorrect profile values when multiple extensions call it during activation. [#2831](https://github.com/zowe/zowe-explorer-vscode/issues/2831)
- Removed `handlebars` dependency in favor of `mustache` for technical currency purposes. [#2975](https://github.com/zowe/zowe-explorer-vscode/pull/2975)
- Update Zowe SDKs to `8.0.0-next.202407051717` for technical currency. [#2918](https://github.com/zowe/zowe-explorer-vscode/issues/2918)
- Fixed an issue where the `ZoweVsCodeExtension.updateCredentials` method could remove credentials from session when input prompt was cancelled. [#3009](https://github.com/zowe/zowe-explorer-vscode/pull/3009)

## `3.0.0-next.202404242037`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as path from "path";
import * as fs from "fs";
import * as imperative from "@zowe/imperative";
import { ProfilesCache } from "../../../src/profiles/ProfilesCache";
import { FileManagement, ZoweExplorerApi } from "../../../src";
import { FileManagement, Types } from "../../../src";

jest.mock("fs");

Expand Down Expand Up @@ -141,6 +141,7 @@ describe("ProfilesCache", () => {

it("getProfileInfo should initialize ProfileInfo API", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
jest.spyOn(FileManagement, "getZoweDir").mockReturnValue(fakeZoweDir);
const profInfo = await new ProfilesCache(fakeLogger as unknown as imperative.Logger, __dirname).getProfileInfo();
expect(readProfilesFromDiskSpy).toHaveBeenCalledTimes(1);
expect(defaultCredMgrWithKeytarSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -260,7 +261,7 @@ describe("ProfilesCache", () => {
it("should refresh profile data for multiple profile types", async () => {
const profCache = new ProfilesCache({ ...fakeLogger, error: mockLogError } as unknown as imperative.Logger);
const getProfInfoSpy = jest.spyOn(profCache, "getProfileInfo").mockResolvedValue(createProfInfoMock([lpar1Profile, zftpProfile]));
await profCache.refresh(fakeApiRegister as unknown as ZoweExplorerApi.IApiRegisterClient);
await profCache.refresh(fakeApiRegister as unknown as Types.IApiRegisterClient);
expect(profCache.allProfiles.length).toEqual(2);
expect(profCache.allProfiles[0]).toMatchObject(lpar1Profile);
expect(profCache.allProfiles[1]).toMatchObject(zftpProfile);
Expand All @@ -273,7 +274,7 @@ describe("ProfilesCache", () => {
jest.spyOn(profCache, "getProfileInfo").mockResolvedValue(
createProfInfoMock([lpar1ProfileWithToken, lpar2ProfileWithToken, baseProfileWithToken])
);
await profCache.refresh(fakeApiRegister as unknown as ZoweExplorerApi.IApiRegisterClient);
await profCache.refresh(fakeApiRegister as unknown as Types.IApiRegisterClient);
expect(profCache.allProfiles.length).toEqual(3);
expect(profCache.allProfiles[0]).toMatchObject(lpar1ProfileWithToken);
expect(profCache.allProfiles[1]).toMatchObject(lpar2Profile); // without token
Expand All @@ -288,7 +289,7 @@ describe("ProfilesCache", () => {
jest.spyOn(profCache, "getProfileInfo").mockImplementation(() => {
throw fakeError;
});
await profCache.refresh(fakeApiRegister as unknown as ZoweExplorerApi.IApiRegisterClient);
await profCache.refresh(fakeApiRegister as unknown as Types.IApiRegisterClient);
expect(profCache.allProfiles.length).toEqual(0);
expect(profCache.getAllTypes().length).toEqual(0);
expect(mockLogError).toHaveBeenCalledWith(fakeError);
Expand Down Expand Up @@ -438,55 +439,48 @@ describe("ProfilesCache", () => {
});

describe("convertV1ProfToConfig", () => {
Object.defineProperty(FileManagement, "getZoweDir", { value: jest.fn().mockReturnValue(fakeZoweDir), configurable: true });
Object.defineProperty(ProfilesCache, "addToConfigArray", { value: jest.fn(), configurable: true });
Object.defineProperty(fs, "renameSync", { value: jest.fn(), configurable: true });
Object.defineProperty(ProfilesCache, "getConfigArray", { value: jest.fn(), configurable: true });
it("Should convert v1 profiles to config file", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as imperative.Logger);
jest.spyOn(imperative.ConfigBuilder, "convert").mockImplementationOnce(() => {
const profInfo = createProfInfoMock([lpar1Profile]);
jest.spyOn(imperative.ConvertV1Profiles, "convert").mockImplementationOnce(() => {
return {
profilesConverted: { zosmf: ["profile1"] },
profilesFailed: {},
config: {},
} as any;
});
await expect(profCache.convertV1ProfToConfig()).resolves.not.toThrow();
await expect(ProfilesCache.convertV1ProfToConfig(profInfo)).resolves.not.toThrow();
});
it("Should convert v1 profiles to config file with profilesFailed", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as imperative.Logger);
jest.spyOn(imperative.ConfigBuilder, "convert").mockImplementationOnce(() => {
const profInfo = createProfInfoMock([lpar1Profile]);
jest.spyOn(imperative.ConvertV1Profiles, "convert").mockImplementationOnce(() => {
return {
profilesConverted: {},
profilesFailed: [{ name: ["profile2"], types: "zosmf", error: "Error converting" }],
config: {},
} as any;
});
await expect(profCache.convertV1ProfToConfig()).resolves.not.toThrow();
await expect(ProfilesCache.convertV1ProfToConfig(profInfo)).resolves.not.toThrow();
});
it("Should convert v1 profiles to config even if rename of profiles directory fails", async () => {
Object.defineProperty(fs, "renameSync", {
value: jest.fn().mockImplementation(() => {
throw new Error("Error renaming file");
}),
configurable: true,
jest.spyOn(fs, "renameSync").mockImplementationOnce(() => {
throw new Error("Error renaming file");
});
const profCache = new ProfilesCache(fakeLogger as unknown as imperative.Logger);
jest.spyOn(imperative.ConfigBuilder, "convert").mockImplementationOnce(() => {
const profInfo = createProfInfoMock([lpar1Profile]);
jest.spyOn(imperative.ConvertV1Profiles, "convert").mockImplementationOnce(() => {
return {
profilesConverted: {},
profilesFailed: [{ name: ["profile2"], types: "zosmf", error: "Error converting" }],
config: {},
} as any;
});
await expect(profCache.convertV1ProfToConfig()).resolves.not.toThrow();
await expect(ProfilesCache.convertV1ProfToConfig(profInfo)).resolves.not.toThrow();
});
it("Should reject if error thrown other than renaming profiles directory", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as imperative.Logger);
jest.spyOn(imperative.ConfigBuilder, "convert").mockImplementationOnce(() => {
const profInfo = createProfInfoMock([lpar1Profile]);
jest.spyOn(imperative.ConvertV1Profiles, "convert").mockImplementationOnce(() => {
throw new Error("Error converting config");
});
await expect(profCache.convertV1ProfToConfig()).rejects.toThrow("Error converting config");
await expect(ProfilesCache.convertV1ProfToConfig(profInfo)).rejects.toThrow("Error converting config");
});
});

Expand Down
18 changes: 9 additions & 9 deletions packages/zowe-explorer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
},
"dependencies": {
"@types/vscode": "^1.53.2",
"@zowe/core-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/imperative": "8.0.0-next.202404032038",
"@zowe/secrets-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-console-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-files-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-jobs-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-tso-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-uss-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zosmf-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/core-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/imperative": "8.0.0-next.202407051717",
"@zowe/secrets-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-console-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-files-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-jobs-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-tso-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-uss-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zosmf-for-zowe-sdk": "8.0.0-next.202407051717",
"mustache": "^4.2.0",
"semver": "^7.6.0"
},
Expand Down
18 changes: 0 additions & 18 deletions packages/zowe-explorer-api/src/globals/Interfaces.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/zowe-explorer-api/src/globals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
export * from "./Constants";
export * from "./Gui";
export * from "./GuiOptions";
export * from "./Interfaces";
52 changes: 6 additions & 46 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
*
*/

import * as path from "path";
import * as fs from "fs";
import * as imperative from "@zowe/imperative";
import type { IRegisterClient } from "../extend/IRegisterClient";
import { FileManagement } from "../utils";
import { Validation } from "./Validation";
import { ZeApiConvertResponse } from "../globals";
import { ZosmfProfile } from "@zowe/zosmf-for-zowe-sdk";
import { ZosTsoProfile } from "@zowe/zos-tso-for-zowe-sdk";
import { ZosUssProfile } from "@zowe/zos-uss-for-zowe-sdk";
import { ProfileConstants } from "@zowe/core-for-zowe-sdk";

export class ProfilesCache {
public profilesForValidation: Validation.IValidationProfile[] = [];
Expand Down Expand Up @@ -354,48 +350,12 @@ export class ProfilesCache {
};
}

public async convertV1ProfToConfig(): Promise<ZeApiConvertResponse> {
const successMsg: string[] = [];
const warningMsg: string[] = [];
const zoweDir = FileManagement.getZoweDir();
const profilesPath = path.join(zoweDir, "profiles");
const oldProfilesPath = `${profilesPath.replace(/[\\/]$/, "")}-old`;
const convertResult = await imperative.ConfigBuilder.convert(profilesPath);
for (const [k, v] of Object.entries(convertResult.profilesConverted)) {
successMsg.push(`Converted ${k} profile: ${v.join(", ")}\n`);
}
if (convertResult.profilesFailed.length > 0) {
warningMsg.push(`Failed to convert ${convertResult.profilesFailed.length} profile(s). See details below\n`);
for (const { name, type, error } of convertResult.profilesFailed) {
if (name != null) {
warningMsg.push(`Failed to load ${type} profile "${name}":\n${String(error)}\n`);
} else {
warningMsg.push(`Failed to find default ${type} profile:\n${String(error)}\n`);
}
}
}
const teamConfig = await imperative.Config.load("zowe", {
homeDir: zoweDir,
projectDir: false,
});
teamConfig.api.layers.activate(false, true);
teamConfig.api.layers.merge(convertResult.config);
const knownCliConfig: imperative.ICommandProfileTypeConfiguration[] = this.getCoreProfileTypes();
knownCliConfig.push(ProfileConstants.BaseProfile);
this.addToConfigArray(knownCliConfig);
teamConfig.setSchema(imperative.ConfigSchema.buildSchema(this.getConfigArray()));
await teamConfig.save();
try {
fs.renameSync(profilesPath, oldProfilesPath);
} catch (error) {
warningMsg.push(`Failed to rename profiles directory to ${oldProfilesPath}:\n ${String(error)}`);
}
successMsg.push(`Your new profiles have been saved to ${teamConfig.layerActive().path}.\n`);
return {
success: String(successMsg.join("")),
warnings: String(warningMsg.join("")),
convertResult,
};
public static async convertV1ProfToConfig(
profileInfo: imperative.ProfileInfo,
deleteV1Profs: boolean = false
): Promise<imperative.IConvertV1ProfResult> {
const convertResult = await imperative.ConvertV1Profiles.convert({ deleteV1Profs, profileInfo });
return convertResult;
}

protected getCoreProfileTypes(): imperative.IProfileTypeConfiguration[] {
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-ftp-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to the "zowe-explorer-ftp-extension" extension will be docum

- Changed the hashing algorithm for e-tag generation from `sha1` to `sha256` to avoid collisions. [#2890](https://github.com/zowe/zowe-explorer-vscode/pull/2890)
- Updated the FTP plugin dependency to `3.0.0-next.202403191358` for technical currency [#2783](https://github.com/zowe/vscode-extension-for-zowe/pull/2783).
- Update Zowe SDKs to `8.0.0-next.202405241828` for technical currency. [#2918](https://github.com/zowe/zowe-explorer-vscode/issues/2918)

## `3.0.0-next.202404242037`

Expand Down Expand Up @@ -80,6 +81,7 @@ All notable changes to the "zowe-explorer-ftp-extension" extension will be docum
### Bug fixes

- Fixed ECONNRESET error when trying to upload or create an empty data set member. [#2350](https://github.com/zowe/vscode-extension-for-zowe/issues/2350)
- Update Zowe SDKs to `8.0.0-next.202407051717` for technical currency. [#2918](https://github.com/zowe/zowe-explorer-vscode/issues/2918)

## 2.16.0

Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer-ftp-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"vscode": "^1.79.0"
},
"dependencies": {
"@zowe/zos-files-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-files-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zos-ftp-for-zowe-cli": "3.0.0-next.202403191358",
"@zowe/zos-jobs-for-zowe-sdk": "8.0.0-next.202404032038",
"@zowe/zos-jobs-for-zowe-sdk": "8.0.0-next.202407051717",
"@zowe/zowe-explorer-api": "3.0.0-next-SNAPSHOT",
"tmp": "0.2.3"
},
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed issue where saving changes to favorited PDS member fails when custom temp folder is set on Windows. [#2880](https://github.com/zowe/zowe-explorer-vscode/issues/2880)
- Fixed issue where multiple extensions that contribute profiles to a tree view using the Zowe Explorer API may fail to load. [#2888](https://github.com/zowe/zowe-explorer-vscode/issues/2888)
- Fixed regression where `getProviderForNode` returned the wrong tree provider after performing an action on a Zowe tree node, causing some commands to fail silently. [#2967](https://github.com/zowe/zowe-explorer-vscode/issues/2967)
- Update Zowe SDKs to `8.0.0-next.202407051717` for technical currency. [#2918](https://github.com/zowe/zowe-explorer-vscode/issues/2918)
- Fixed issue where creating a new team configuration file could cause Zowe Explorer to crash, resulting in all sessions disappearing from trees. [#2906](https://github.com/zowe/zowe-explorer-vscode/issues/2906)

## `3.0.0-next.202404242037`
Expand Down
11 changes: 11 additions & 0 deletions packages/zowe-explorer/__tests__/__mocks__/@zowe/imperative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,14 @@ export namespace SessConstants {
export const apiErrorHeader = {
message: "API Error",
};

export class ConvertV1Profiles {
public static convert() {
return {
msgs: "",
profilesConverted: [],
profilesFailed: [],
v1ScsPluginName: undefined,
};
}
}
2 changes: 2 additions & 0 deletions packages/zowe-explorer/__tests__/__mocks__/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class FakeStats implements Stats {

export function access(path: string, callback: any): void {}

export function appendFileSync(path: string, data: any, encoding: string): void {}

export function closeSync(fd: number): void {}

export function existsSync(path: string | Buffer): boolean {
Expand Down
Loading

0 comments on commit e221a64

Please sign in to comment.