Skip to content

Commit

Permalink
Rename ProfileIO to V1ProfileConversion
Browse files Browse the repository at this point in the history
Remove all write functions from V1ProfileConversion
Replace 'team config' with 'Zowe client config'

Signed-off-by: Gene Johnston <[email protected]>
  • Loading branch information
gejohnston committed Mar 7, 2024
1 parent a5a4590 commit e69134d
Show file tree
Hide file tree
Showing 21 changed files with 605 additions and 1,194 deletions.
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- Enhancement: Changed references in command output from 'Team Configuration' to 'Zowe client configuration'.

## `8.0.0-next.202403041352`

- BugFix: Updated engine to Node 18.12.0. [#2074](https://github.com/zowe/zowe-cli/pull/2074)
Expand Down
13 changes: 13 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to the Imperative package will be documented in this file.

## Recent Changes
- LTS Breaking: [#1703](https://github.com/zowe/zowe-cli/issues/1703)
- Renamed class ProfileIO to V1ProfileConversion in package @zowe/imperative class.
- Removed the following obsolete V1 profile functions:
- createProfileDirs
- deleteProfile
- exists
- writeMetaFile
- writeProfile
- Removed the following obsolete V1 profile constant:
- MAX_YAML_DEPTH
- Changed fileToProfileName from public to private

## `8.0.0-next.202403041352`

- BugFix: Updated engine to Node 18.12.0. [#2074](https://github.com/zowe/zowe-cli/pull/2074)
Expand Down
26 changes: 13 additions & 13 deletions packages/imperative/src/config/__tests__/ConfigBuilder.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { CredentialManagerFactory, IImperativeConfig } from "../..";
import { Config, ConfigBuilder, IConfig } from "../";
import { ProfileIO } from "../../profiles";
import { V1ProfileConversion } from "../../profiles";
import * as config from "../../../__tests__/__integration__/imperative/src/imperative";
import * as lodash from "lodash";

Expand Down Expand Up @@ -247,14 +247,14 @@ describe("Config Builder tests", () => {
});

it("should successfully convert multiple v1 profiles to config object", async () => {
jest.spyOn(ProfileIO, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(ProfileIO, "getAllProfileNames")
jest.spyOn(V1ProfileConversion, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(V1ProfileConversion, "getAllProfileNames")
.mockReturnValueOnce(["apple", "banana", "coconut"])
.mockReturnValueOnce(["almond", "brazil", "cashew"]);
jest.spyOn(ProfileIO, "readMetaFile")
jest.spyOn(V1ProfileConversion, "readMetaFile")
.mockReturnValueOnce({ defaultProfile: "apple" } as any)
.mockReturnValueOnce({ defaultProfile: "brazil" } as any);
jest.spyOn(ProfileIO, "readProfileFile")
jest.spyOn(V1ProfileConversion, "readProfileFile")
.mockReturnValueOnce({ color: "green", secret: "managed by A" })
.mockReturnValueOnce({ color: "yellow", secret: "managed by B" })
.mockReturnValueOnce({ color: "brown", secret: "managed by C" })
Expand Down Expand Up @@ -309,12 +309,12 @@ describe("Config Builder tests", () => {
mockSecureLoad.mockReturnValueOnce(null);
const metaError = new Error("invalid meta file");
const profileError = new Error("invalid profile file");
jest.spyOn(ProfileIO, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(ProfileIO, "getAllProfileNames")
jest.spyOn(V1ProfileConversion, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(V1ProfileConversion, "getAllProfileNames")
.mockReturnValueOnce(["apple", "banana", "coconut"])
.mockReturnValueOnce([]);
jest.spyOn(ProfileIO, "readMetaFile").mockImplementationOnce(() => { throw metaError; });
jest.spyOn(ProfileIO, "readProfileFile")
jest.spyOn(V1ProfileConversion, "readMetaFile").mockImplementationOnce(() => { throw metaError; });
jest.spyOn(V1ProfileConversion, "readProfileFile")
.mockImplementationOnce(() => ({ color: "green", secret: "managed by A" }))
.mockImplementationOnce(() => { throw profileError; })
.mockImplementationOnce(() => ({ color: "brown", secret: "managed by C" }));
Expand Down Expand Up @@ -350,12 +350,12 @@ describe("Config Builder tests", () => {
});

it("should convert v1 property names to v2 names", async () => {
jest.spyOn(ProfileIO, "getAllProfileDirectories").mockReturnValueOnce(["zosmf"]);
jest.spyOn(ProfileIO, "getAllProfileNames")
jest.spyOn(V1ProfileConversion, "getAllProfileDirectories").mockReturnValueOnce(["zosmf"]);
jest.spyOn(V1ProfileConversion, "getAllProfileNames")
.mockReturnValueOnce(["LPAR1"]);
jest.spyOn(ProfileIO, "readMetaFile")
jest.spyOn(V1ProfileConversion, "readMetaFile")
.mockReturnValueOnce({ defaultProfile: "LPAR1" } as any);
jest.spyOn(ProfileIO, "readProfileFile")
jest.spyOn(V1ProfileConversion, "readProfileFile")
.mockReturnValueOnce({
hostname: "should change to host",
username: "should change to user",
Expand Down
10 changes: 5 additions & 5 deletions packages/imperative/src/config/src/ConfigBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as path from "path";
import * as lodash from "lodash";
import { ProfileIO, ProfilesConstants, ProfileUtils } from "../../profiles";
import { V1ProfileConversion, ProfilesConstants, ProfileUtils } from "../../profiles";
import { IImperativeConfig } from "../../imperative";
import { Config } from "./Config";
import { IConfig } from "./doc/IConfig";
Expand Down Expand Up @@ -99,17 +99,17 @@ export class ConfigBuilder {
profilesFailed: []
};

for (const profileType of ProfileIO.getAllProfileDirectories(profilesRootDir)) {
for (const profileType of V1ProfileConversion.getAllProfileDirectories(profilesRootDir)) {
const profileTypeDir = path.join(profilesRootDir, profileType);
const profileNames = ProfileIO.getAllProfileNames(profileTypeDir, ".yaml", `${profileType}_meta`);
const profileNames = V1ProfileConversion.getAllProfileNames(profileTypeDir, ".yaml", `${profileType}_meta`);
if (profileNames.length === 0) {
continue;
}

for (const profileName of profileNames) {
try {
const profileFilePath = path.join(profileTypeDir, `${profileName}.yaml`);
const profileProps = ProfileIO.readProfileFile(profileFilePath, profileType);
const profileProps = V1ProfileConversion.readProfileFile(profileFilePath, profileType);
const secureProps = [];

for (const [key, value] of Object.entries(profileProps)) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class ConfigBuilder {

try {
const metaFilePath = path.join(profileTypeDir, `${profileType}_meta.yaml`);
const profileMetaFile = ProfileIO.readMetaFile(metaFilePath);
const profileMetaFile = V1ProfileConversion.readMetaFile(metaFilePath);
if (profileMetaFile.defaultProfile != null) {
result.config.defaults[profileType] = ProfileUtils.getProfileMapKey(profileType, profileMetaFile.defaultProfile);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class ProfileInfo {
if (!Object.prototype.hasOwnProperty.call(configProperties.defaults, profileType)) {
// no default exists for the requested type
this.mImpLogger.warn("Found no profile of type '" +
profileType + "' in team config."
profileType + "' in Zowe client configuration."
);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export interface IImperativeErrorParms {
logger?: Logger;
/**
* Message tag - prepended to the error message specified. Useful for categorizing error messages
* (e.g. "Profile IO Error"). A ": " is appended automatically (e.g. "Profile IO Error: ")
* (e.g. "V1ProfileConversion Read Error").
* A ": " is appended automatically (e.g. "V1ProfileConversion Read Error: ")
* @type {string}
* @memberof IImperativeErrorParms
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as fsExtra from "fs-extra";
import { keyring as keytar } from "@zowe/secrets-for-zowe-sdk";
import { Config, ConfigBuilder, ConfigSchema } from "../../../../../config";
import { IHandlerParameters } from "../../../../../cmd";
import { ProfileIO } from "../../../../../profiles";
import { V1ProfileConversion } from "../../../../../profiles";
import { AppSettings } from "../../../../../settings";
import { ImperativeConfig } from "../../../../../utilities";
import * as npmInterface from "../../../../src/plugins/utilities/npm-interface";
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("Configuration Convert Profiles command handler", () => {
const params = getIHandlerParametersObject();

await handler.process(params);
expect(stdout).toContain("No old profiles were found");
expect(stdout).toContain("Found no old V1 profiles to convert to a current Zowe client configuration");
expect(stderr).toBe("");
});

Expand Down Expand Up @@ -140,7 +140,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.prompt = false;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut");
expect(stderr).toContain("Failed to load fruit profile \"banana\"");
expect(stderr).toContain(profileError.message);
Expand Down Expand Up @@ -169,8 +169,8 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.prompt = false;

await handler.process(params);
expect(stdout).toContain("A team configuration file was detected");
expect(stdout).toContain("No old profiles were found");
expect(stdout).toContain("A current Zowe client configuration was detected. V1 profiles will not be converted");
expect(stdout).toContain("Found no old V1 profiles to convert to a current Zowe client configuration");
expect(stdout).not.toContain("Converted fruit profiles: apple, coconut");
expect(updateSchemaSpy).not.toHaveBeenCalled();
expect(mockImperativeConfig.config.save).not.toHaveBeenCalled();
Expand All @@ -196,10 +196,10 @@ describe("Configuration Convert Profiles command handler", () => {
(params.response.console.prompt as any).mockResolvedValueOnce("y");

await handler.process(params);
expect(stdout).toContain("Detected 1 old profile(s)");
expect(stdout).toContain("Detected 1 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("The following plug-ins will be removed");
expect(stdout).toContain("Your new profiles have been saved");
expect(stdout).toContain("Your old profiles have been moved");
expect(stdout).toContain("Your old V1 profiles have been moved");
expect(stderr).toBe("");
expect(uninstallSpy).toHaveBeenCalled();
expect(configConvertSpy).toHaveBeenCalled();
Expand All @@ -216,7 +216,7 @@ describe("Configuration Convert Profiles command handler", () => {
(params.response.console.prompt as any).mockResolvedValueOnce("n");

await handler.process(params);
expect(stdout).toContain("Detected 1 old profile(s)");
expect(stdout).toContain("Detected 1 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("The following plug-ins will be removed");
expect(stderr).toBe("");
expect(uninstallSpy).not.toHaveBeenCalled();
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).toContain("Deleting the profiles directory");
expect(stdout).toContain("Deleting secure value for \"@brightside/core/testAcct\"");
Expand Down Expand Up @@ -298,7 +298,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).toContain("Deleting the profiles directory");
expect(stdout).toContain("Deleting secure value for \"@brightside/core/testAcct\"");
Expand Down Expand Up @@ -344,7 +344,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).not.toContain("Deleting the profiles directory");
expect(stdout).not.toContain("Deleting secure value for \"@brightside/core/testAcct\"");
Expand Down Expand Up @@ -392,7 +392,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).toContain("Deleting the profiles directory");
expect(stdout).toContain("Deleting secure value for \"@brightside/core/testAcct\"");
Expand Down Expand Up @@ -437,7 +437,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("No old profiles were found");
expect(stdout).toContain("Found no old V1 profiles to convert to a current Zowe client configuration");
expect(stdout).toContain("Deleting the profiles directory");
expect(stdout).toContain("Deleting secure value for \"@brightside/core/testAcct\"");
expect(stdout).toContain("Deleting secure value for \"@zowe/cli/testAcct\"");
Expand Down Expand Up @@ -482,7 +482,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).toContain("Deleting secure value for \"@brightside/core/testAcct\"");
expect(stdout).toContain("Deleting secure value for \"@zowe/cli/testAcct\"");
Expand Down Expand Up @@ -524,7 +524,7 @@ describe("Configuration Convert Profiles command handler", () => {
params.arguments.delete = true;

await handler.process(params);
expect(stdout).toContain("Detected 3 old profile(s)");
expect(stdout).toContain("Detected 3 old V1 profile(s) to convert to a current Zowe client configuration");
expect(stdout).toContain("Converted fruit profiles: apple, coconut, banana");
expect(stdout).toContain("Deleting the profiles directory");
expect(stderr).toContain("Keytar or the credential vault are unavailable.");
Expand Down Expand Up @@ -736,8 +736,8 @@ describe("Configuration Convert Profiles command handler", () => {
});

it("getOldProfileCount should find multiple types of profiles", () => {
jest.spyOn(ProfileIO, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(ProfileIO, "getAllProfileNames")
jest.spyOn(V1ProfileConversion, "getAllProfileDirectories").mockReturnValueOnce(["fruit", "nut"]);
jest.spyOn(V1ProfileConversion, "getAllProfileNames")
.mockReturnValueOnce(["apple", "banana", "coconut"])
.mockReturnValueOnce(["almond", "brazil", "cashew"]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const convertProfilesDefinition: ICommandDefinition = {
aliases: ["convert"],
type: "command",
handler: join(__dirname, "convert-profiles.handler"),
summary: "Convert profiles to team config",
summary: "Convert V1 profiles to a current Zowe client configuration",
description: `Convert v1 profiles to a global ${ImperativeConfig.instance.rootCommandName}.config.json file.`,
options: [{
name: "prompt",
Expand All @@ -35,10 +35,10 @@ export const convertProfilesDefinition: ICommandDefinition = {
type: "boolean"
}],
examples: [{
description: "Convert profiles to team config without prompting",
description: "Convert V1 profiles to a new Zowe client configuration without prompting",
options: "--no-prompt"
}, {
description: "Convert profiles to team config and delete the old profiles",
description: "Convert V1 profiles to a new Zowe client configuration and delete the old V1 profiles",
options: "--delete"
}]
};
Loading

0 comments on commit e69134d

Please sign in to comment.