Skip to content

Commit

Permalink
Merge pull request #2073 from zowe/rm-profile-handlers
Browse files Browse the repository at this point in the history
Remove the 'zowe profiles' command command handlers & APIs
  • Loading branch information
gejohnston authored Mar 1, 2024
2 parents 230203e + a38c22d commit 6ea4c11
Show file tree
Hide file tree
Showing 204 changed files with 1,298 additions and 17,081 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/* eslint-disable max-len */

describe("Imperative Secure Tests", () => {
require("./../../packages/imperative/__tests__/src/packages/profiles/__integration__/CliProfileManager.credentials.integration.subtest");
require("./../../packages/imperative/__tests__/src/packages/imperative/__integration__/PluginManagementFacility.integration.subtest");
require("./../../packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/init/cli.imperative-test-cli.config.init.integration.subtest");
require("./../../packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/auto-init/imperative.test.cli.config.auto-init.fruit.integration.subtest");
Expand Down
11 changes: 0 additions & 11 deletions __tests__/__packages__/cli-test-utils/src/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ export function runCliScript(scriptPath: string, testEnvironment: ITestEnvironme
}
}

/**
* Strip v1 profile deprecation messages from stderr output.
*/
export function stripProfileDeprecationMessages(stderr: Buffer | string): string {
return stderr.toString()
.replace(/Warning: The command 'profiles [a-z]+' is deprecated\./g, "")
.replace(/Recommended replacement: The 'config [a-z]+' command/g, "")
.replace(/Recommended replacement: Edit your Zowe V2 configuration\s+zowe\.config\.json/g, "")
.trim();
}

/**
* Type for handler data used to build mock IHandlerParameters object.
* The type inherits from IHandlerParameters but is different:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
import * as fs from "fs";

import { v4 as uuidv4 } from "uuid";
import { Config, ImperativeError, IO } from "@zowe/imperative";
import { Config } from "@zowe/imperative";

import { ITestEnvironment } from "./doc/response/ITestEnvironment";
import { runCliScript, stripProfileDeprecationMessages } from "../TestUtils";

/**
* Utilities for creating and cleaning up temporary profiles for tests
Expand Down Expand Up @@ -53,12 +52,6 @@ export class TempTestProfiles {
`installed or linked globally so that '${TempTestProfiles.BINARY_NAME}' can be issued to create profiles and ` +
`issue other commands.`;

/**
* Override for the ZOWE_CLI_TEST_OLD_PROFILES environment variable. If
* set to true, old-school profiles will be created instead of team config.
*/
public static forceOldProfiles: boolean = false;

/**
* Create profiles for tests from data in the properties yaml file
* @param {ITestEnvironment} testEnvironment - with working directory and test properties loaded
Expand All @@ -73,11 +66,7 @@ export class TempTestProfiles {
const profileNames: { [key: string]: string[] } = {};
this.log(testEnvironment, "Creating the following profileTypes: " + profileTypes);
for (const profileType of profileTypes) {
if (this.usingTeamConfig) {
profileNames[profileType] = [await this.createV2Profile(testEnvironment, profileType)];
} else {
profileNames[profileType] = [await this.createV1Profile(testEnvironment, profileType)];
}
profileNames[profileType] = [await this.createV2Profile(testEnvironment, profileType)];
}
return profileNames;
}
Expand All @@ -94,11 +83,7 @@ export class TempTestProfiles {
this.log(testEnvironment, "Deleting the following profiles:\n" + JSON.stringify(profiles));
for (const profileType of Object.keys(profiles)) {
for (const profileName of profiles[profileType]) {
if (this.usingTeamConfig) {
await this.deleteV2Profile(testEnvironment, profileType, profileName);
} else {
await this.deleteV1Profile(testEnvironment, profileType, profileName);
}
await this.deleteV2Profile(testEnvironment, profileType, profileName);
}
}
}
Expand All @@ -111,44 +96,6 @@ export class TempTestProfiles {
*/
private static readonly MAX_UUID_LENGTH = 20;

/**
* Whether new team config profiles should be used instead of old school
* profiles.
*/
private static get usingTeamConfig(): boolean {
if (this.forceOldProfiles) return false;
const envOldProfiles = process.env.ZOWE_CLI_TEST_OLD_PROFILES;
return envOldProfiles !== "1" && envOldProfiles?.toLowerCase() !== "true";
}

/**
* Helper to create a temporary old school profile from test properties
* @param {ITestEnvironment} testEnvironment - the test environment with env and working directory to use for output
* @returns {Promise<string>} promise that resolves to the name of the created profile on success
* @throws errors if the profile creation fails
*/
private static async createV1Profile(testEnvironment: ITestEnvironment<any>, profileType: string): Promise<string> {
const profileName: string = uuidv4().substring(0, TempTestProfiles.MAX_UUID_LENGTH) + "_tmp_" + profileType;
let createProfileScript = this.SHEBANG +
`${this.BINARY_NAME} profiles create ${profileType} ${profileName}`;
for (const [k, v] of Object.entries(testEnvironment.systemTestProperties[profileType])) {
createProfileScript += ` ${(k.length > 1) ? "--" : "-"}${k} ${v}`;
}
const scriptPath = testEnvironment.workingDir + "_create_profile_" + profileName;
await IO.writeFileAsync(scriptPath, createProfileScript);
const output = runCliScript(scriptPath, testEnvironment, []);
if (output.status !== 0 || stripProfileDeprecationMessages(output.stderr).length > 0) {
throw new ImperativeError({
msg: `Creation of ${profileType} profile '${profileName}' failed! You should delete the script: ` +
`'${scriptPath}' after reviewing it to check for possible errors. Stderr of the profile create ` +
`command:\n` + output.stderr.toString() + TempTestProfiles.GLOBAL_INSTALL_NOTE
});
}
IO.deleteFile(scriptPath);
this.log(testEnvironment, `Created ${profileType} V1 profile '${profileName}'. Stdout from creation:\n${output.stdout.toString()}`);
return profileName;
}

/**
* Helper to create a temporary team config profile from test properties
* @internal
Expand Down Expand Up @@ -176,31 +123,6 @@ export class TempTestProfiles {
return profileName;
}

/**
* Helper to delete a temporary old school profile
* @param {ITestEnvironment} testEnvironment - the test environment with env and working directory to use for output
* @param {string} profileType - the type of profile e.g. zosmf to
* @param {string} profileName - the name of the profile to delete
* @returns {Promise<string>} promise that resolves to the name of the created profile on success
* @throws errors if the profile delete fails
*/
private static async deleteV1Profile(testEnvironment: ITestEnvironment<any>, profileType: string, profileName: string): Promise<string> {
const deleteProfileScript = this.SHEBANG + `${this.BINARY_NAME} profiles delete ${profileType} ${profileName} --force`;
const scriptPath = testEnvironment.workingDir + "_delete_profile_" + profileName;
await IO.writeFileAsync(scriptPath, deleteProfileScript);
const output = runCliScript(scriptPath, testEnvironment, []);
if (output.status !== 0 || stripProfileDeprecationMessages(output.stderr).length > 0) {
throw new ImperativeError({
msg: "Deletion of " + profileType + " profile '" + profileName + "' failed! You should delete the script: '" + scriptPath + "' " +
"after reviewing it to check for possible errors. Stderr of the profile create command:\n" + output.stderr.toString()
+ TempTestProfiles.GLOBAL_INSTALL_NOTE
});
}
this.log(testEnvironment, `Deleted ${profileType} V1 profile '${profileName}'. Stdout from deletion:\n${output.stdout.toString()}`);
IO.deleteFile(scriptPath);
return profileName;
}

/**
* Helper to delete a temporary team config profile
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export class TestEnvironment {
}

// the result of the test environment setup so far is used to create profiles
TempTestProfiles.forceOldProfiles = params.createOldProfiles ?? false;
if (TempTestProfiles.forceOldProfiles || (params.tempProfileTypes?.length ?? 0 > 0)) {
if (params.tempProfileTypes?.length ?? 0 > 0) {
result.tempProfiles = await TempTestProfiles.createProfiles(result, params.tempProfileTypes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,4 @@ export interface ISetupEnvironmentParms {
* you are trying to execute plugin commands installed into Zowe CLI.
*/
installPlugin?: boolean;

/**
* Should old-school profiles be created instead of team config?
* Default: false
*/
createOldProfiles?: boolean;
}
25 changes: 14 additions & 11 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to the Zowe CLI package will be documented in this file.
## Recent Changes

- BugFix: Updated engine to Node 18.12.0. [#2074](https://github.com/zowe/zowe-cli/pull/2074)
- BugFix: Eliminated a Node Version Manager (NVM) GUI popup dialog which NVM now displays during the `zowe config report-env` command by removing the NVM version number from our report.
- Enhancement: Replaced the term "Team configuration" with "Zowe client configuration" in the `zowe config report-env` command.

## `8.0.0-next.202402261705`

Expand Down Expand Up @@ -41,7 +43,7 @@ LTS Breaking: Removed the following previously deprecated items: [#1981](https:/
- SSH_OPTION_HOST_PROFILE use SSH_OPTION_HOST
- Removed zosmfProfile from `ZosFilesBase.handler.ts`
- Removed statCmdFlag as an export from Shell.ts


## `8.0.0-next.202401262128`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,47 +79,6 @@ describe("TargetProfileHandler", () => {
});
});

it("should merge properties from v1 profiles and command arguments", async () => {
const commandParameters = {
...DEFAULT_PARAMETERS,
arguments: {
...DEFAULT_PARAMETERS.arguments,
host: "example1.com",
user: "user1",
password: "password1",
targetUser: "user2",
targetPassword: "password3",
targetZosmfProfile: "target_zosmf"
}
};

commandParameters.response.data.setObj = jest.fn();
const getProfileMock = jest.fn().mockReturnValue({
password: "password2",
port: 123
});
commandParameters.profiles.get = getProfileMock;
jest.spyOn(ImperativeConfig, "instance", "get").mockReturnValue({
config: { exists: false }
} as any);

const handler = new TargetProfileHandler();
await handler.process(commandParameters);

expect(getProfileMock).toHaveBeenCalledTimes(1);
expect(commandParameters.response.data.setObj).toHaveBeenCalledWith({
apiResponse: {
sessCfg: expect.objectContaining({
hostname: "example1.com",
port: 123,
user: "user2",
password: "password3"
})
},
success: true
});
});

it("should handle error loading target z/OSMF profile", async () => {
const commandParameters = {
...DEFAULT_PARAMETERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("submit shared handler", () => {

expect(error).toBeDefined();
expect(error instanceof ImperativeError).toBe(true);
expect(error.message).toMatchSnapshot();
expect(error.message).toContain("Unable to determine the JCL source. Please contact support");
});

it("should not transform an error thrown by the submit JCL API", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`submit shared handler error handling should detect if the JCL source type (data set, etc.) could not be determined 1`] = `"Internal submit error: Unable to determine the JCL source. Please contact support."`;

exports[`submit shared handler process method should submit JCL contained within a data-set if requested 1`] = `
Object {
"fields": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export default class TargetProfileHandler extends ZosFilesBaseHandler {

try {
if (targetProfileName != null) {
if (ImperativeConfig.instance.config?.exists) {
targetCmdArgs = ImperativeConfig.instance.config.api.profiles.get(targetProfileName);
} else {
targetCmdArgs = params.profiles.get("zosmf", false, targetProfileName);
}
targetCmdArgs = ImperativeConfig.instance.config.api.profiles.get(targetProfileName);
}

const targetPrefix = "target";
Expand Down
3 changes: 3 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to the Zowe core SDK package will be documented in this file
## Recent Changes

- BugFix: Updated engine to Node 18.12.0. [#2074](https://github.com/zowe/zowe-cli/pull/2074)
- LTS Breaking: Removed the file ProfileUtils.ts which contains the following obsolete V1 profile functions:
- getDefaultProfile
- getZoweDir - moved to ProfileInfo.getZoweDir

## `8.0.0-next.202402261705`

Expand Down
Loading

0 comments on commit 6ea4c11

Please sign in to comment.