Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate different base profile names for global and project configs #2194

Merged
merged 22 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
029c49f
Remove the yamljs dependency
gejohnston Jun 4, 2024
ec9aadd
Remove another yamljs dependency
gejohnston Jun 4, 2024
db3fb0b
Generate global and project base profile names
gejohnston Jun 4, 2024
3bd3494
Add tests for formGlobOrProjProfileNm & findProfTypeInNestedProfiles
gejohnston Jun 4, 2024
40b5651
Fix config-list tests that don't know project_base
gejohnston Jun 6, 2024
321d40c
Fix config-init integ tests for project_base
gejohnston Jun 6, 2024
e1a7590
Fix config-secure integ tests for project_base
gejohnston Jun 6, 2024
9c7e3fa
Merge remote-tracking branch 'origin/next' into projectBase
gejohnston Jul 8, 2024
08b5b1d
Specify tests as Global, globalUser, Project, & projectUser
gejohnston Jul 8, 2024
563307b
Use Global, globalUser, Project, & projectUser tests
gejohnston Jul 8, 2024
27d6231
Replace redundant test case
gejohnston Jul 9, 2024
a32f325
Use expectedProjectConfigObject
gejohnston Jul 9, 2024
982ed5d
Empty secure arrays in expected user config data
gejohnston Jul 9, 2024
5042ab9
Use different config objects for proj, projUser, global, globalUser
gejohnston Jul 9, 2024
99e0705
Empty the secure array for user configs
gejohnston Jul 9, 2024
9686911
Add required snapshot
gejohnston Jul 9, 2024
76c3124
Empty the secure array for user configs
gejohnston Jul 9, 2024
ca8e848
Remove wrong snapshot file. Update right snapshot file
gejohnston Jul 9, 2024
03c21e3
change hardcoded 'base' to 'project_base'
gejohnston Jul 10, 2024
978717a
Add changelog entries
gejohnston Jul 10, 2024
9c099d7
Merge branch 'next' into projectBase
t1m0thyj Jul 17, 2024
efe6ea1
Merge branch 'next' into projectBase
t1m0thyj Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Imperative Secure Tests imperative-test-cli config profiles should list profiles 1`] = `
"secured
base
project_base
global_base
"
`;
31 changes: 11 additions & 20 deletions npm-shrinkwrap.json

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

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: The 'zowe config auto-init' command now generates a base profile name of 'global_base' or 'project_base', depending on whether a global or project configuration file is being generated. Related to Zowe Explorer issue https://github.com/zowe/zowe-explorer-vscode/issues/2682.

## `8.0.0-next.202407021516`

- BugFix: Updated dependencies for technical currency [#2188](https://github.com/zowe/zowe-cli/pull/2188)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("config auto-init without profile", () => {
let config = fs.readFileSync(path.join(TEST_ENVIRONMENT.workingDir, "zowe.config.json")).toString();
// Typecasting because of this issue: https://github.com/kaelzhang/node-comment-json/issues/42
const configJson = JSONC.parse(config) as any;
configJson.profiles.base.properties = {};
configJson.profiles.project_base.properties = {};
config = JSONC.stringify(configJson, null, 4);
fs.writeFileSync(path.join(TEST_ENVIRONMENT.workingDir, "zowe.config.json"), config);

Expand Down Expand Up @@ -239,8 +239,8 @@ describe("config auto-init without profile and with certificates", () => {
let config = fs.readFileSync(path.join(TEST_ENVIRONMENT.workingDir, "zowe.config.json")).toString();
// Typecasting because of this issue: https://github.com/kaelzhang/node-comment-json/issues/42
const configJson = JSONC.parse(config) as any;
configJson.profiles.base.properties = {};
configJson.profiles.base.secure = [];
configJson.profiles.project_base.properties = {};
configJson.profiles.project_base.secure = [];
config = JSONC.stringify(configJson, null, 4);
fs.writeFileSync(path.join(TEST_ENVIRONMENT.workingDir, "zowe.config.json"), config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ describe("ApimlAutoInitHandler", () => {
}, {
arguments: {
$0: "fake",
_: ["fake"]
_: ["fake"],
}
});
expect(mockGetPluginApimlConfigs).toHaveBeenCalledTimes(1);
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(1);
expect(response.profiles.base.secure).toContain("tokenValue");
expect(response.profiles.base.properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles.base.properties.tokenValue).toEqual("fakeToken");
const baseProfName = "project_base";
expect(response.profiles[baseProfName].secure).toContain("tokenValue");
expect(response.profiles[baseProfName].properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles[baseProfName].properties.tokenValue).toEqual("fakeToken");
});

it("should not have changed - tokenType and tokenValue", async () => {
Expand Down Expand Up @@ -141,9 +142,11 @@ describe("ApimlAutoInitHandler", () => {
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(0);
expect(response.profiles.base.secure).toContain("tokenValue");
expect(response.profiles.base.properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles.base.properties.tokenValue).toEqual("fakeToken");

const baseProfName = "project_base";
expect(response.profiles[baseProfName].secure).toContain("tokenValue");
expect(response.profiles[baseProfName].properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles[baseProfName].properties.tokenValue).toEqual("fakeToken");
});

it("should not have changed - PEM Certificates", async () => {
Expand Down Expand Up @@ -190,9 +193,11 @@ describe("ApimlAutoInitHandler", () => {
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(1);
expect(response.profiles.base.secure).toContain("tokenValue");
expect(response.profiles.base.properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles.base.properties.tokenValue).toEqual("fakeToken");

const baseProfName = "project_base";
expect(response.profiles[baseProfName].secure).toContain("tokenValue");
expect(response.profiles[baseProfName].properties.tokenType).toEqual(SessConstants.TOKEN_TYPE_APIML);
expect(response.profiles[baseProfName].properties.tokenValue).toEqual("fakeToken");
});

it("should not have changed - user & password with existing base profile", async () => {
Expand Down Expand Up @@ -301,7 +306,7 @@ describe("ApimlAutoInitHandler", () => {
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(1);
expect(response.profiles.base.properties.rejectUnauthorized).toEqual(true);
expect(response.profiles["project_base"].properties.rejectUnauthorized).toEqual(true);
});

it("should not have changed - rejectUnauthorized flag false", async () => {
Expand Down Expand Up @@ -349,7 +354,7 @@ describe("ApimlAutoInitHandler", () => {
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(1);
expect(response.profiles.base.properties.rejectUnauthorized).toEqual(false);
expect(response.profiles["project_base"].properties.rejectUnauthorized).toEqual(false);
});

it("should not have changed - a condition that shouldn't ever happen", async () => {
Expand Down Expand Up @@ -393,9 +398,11 @@ describe("ApimlAutoInitHandler", () => {
expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1);
expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1);
expect(mockLogin).toHaveBeenCalledTimes(0);
expect(response.profiles.base.secure).not.toContain("tokenValue");
expect(response.profiles.base.properties.tokenType).not.toBeDefined();
expect(response.profiles.base.properties.tokenValue).not.toBeDefined();

const baseProfName = "project_base";
expect(response.profiles[baseProfName].secure).not.toContain("tokenValue");
expect(response.profiles[baseProfName].properties.tokenType).not.toBeDefined();
expect(response.profiles[baseProfName].properties.tokenValue).not.toBeDefined();
});

it("should throw an error if an error 403 is experienced", async () => {
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as lodash from "lodash";
import { ZosmfSession } from "@zowe/zosmf-for-zowe-sdk";
import { BaseAutoInitHandler, AbstractSession, ICommandArguments, IConfig, IConfigProfile,
ISession, IHandlerResponseApi, IHandlerParameters, SessConstants, ImperativeConfig,
ImperativeError, RestClientError, TextUtils, Config
ImperativeError, RestClientError, TextUtils, Config, ConfigUtils
} from "@zowe/imperative";
import { IApimlProfileInfo, IAutoInitRpt, IProfileRpt, Login, Services } from "@zowe/core-for-zowe-sdk";

Expand Down Expand Up @@ -108,9 +108,15 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler {
// Check to see if there is an active base profile to avoid creating a new one named "base"
let activeBaseProfile = params.arguments[`${this.mProfileType}-profile`] || config.properties.defaults[this.mProfileType];
let baseProfileCreated = false;

// Populate the config with base profile information
if (activeBaseProfile == null) {
profileConfig.profiles[this.mProfileType] = {

// Name our base profile differently in a global config vs a project config
const globalConfig: boolean = params.arguments?.globalConfig ? true : false;
activeBaseProfile = ConfigUtils.formGlobOrProjProfileNm(this.mProfileType, globalConfig);

profileConfig.profiles[activeBaseProfile] = {
type: this.mProfileType,
properties: {
host: session.ISession.hostname,
Expand All @@ -119,7 +125,6 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler {
},
secure: []
};
activeBaseProfile = this.mProfileType;
baseProfileCreated = true;
} else {
const oldBaseProfile = this.getOldBaseProfileProps(config, activeBaseProfile);
Expand Down Expand Up @@ -149,7 +154,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler {

// Report whether or not we created a base profile in this auto-init execution
this.mAutoInitReport.profileRpts.push({
profName: this.mProfileType,
profName: activeBaseProfile,
profType: this.mProfileType,
changeForProf: baseProfileCreated ? "created" : "modified",
basePath: null,
Expand Down
4 changes: 4 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Recent Changes

- Enhancement: Added the function ConfigUtils.formGlobOrProjProfileNm and modified the function ConfigBuilder.build so that the 'zowe config init' command now generates a base profile name of 'global_base' or 'project_base', depending on whether a global or project configuration file is being generated. Related to Zowe Explorer issue https://github.com/zowe/zowe-explorer-vscode/issues/2682.

## `8.0.0-next.202407181255`

- BugFix: Resolved bug that resulted in each plug-in to have identical public registries regardless of actual installation location/reference. [#2189](https://github.com/zowe/zowe-cli/pull/2189)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const expectedSchemaObject = {
}
};

export const expectedConfigObject: IConfig = {
export const expectedGlobalConfigObject: IConfig = {
$schema: "./imperative-test-cli.schema.json",
profiles: {
secured: {
Expand All @@ -206,31 +206,72 @@ export const expectedConfigObject: IConfig = {
},
secure: []
},
base: {
global_base: {
type: "base",
properties: {},
secure: ["secret"]
},
},
defaults: {
secured: "secured",
base: "base"
base: "global_base"
},
autoStore: true
};

export const expectedUserConfigObject: IConfig = {
export const expectedGlobalUserConfigObject: IConfig = {
$schema: "./imperative-test-cli.schema.json",
profiles: {
secured: {
type: "secured",
properties: {},
secure: []
},
base: {
global_base: {
type: "base",
properties: {},
secure: ["secret"]
},
},
defaults: {},
autoStore: true
};

export const expectedProjectConfigObject: IConfig = {
$schema: "./imperative-test-cli.schema.json",
profiles: {
secured: {
type: "secured",
properties: {
info: ""
},
secure: []
},
project_base: {
type: "base",
properties: {},
secure: ["secret"]
},
},
defaults: {
secured: "secured",
base: "project_base"
},
autoStore: true
};

export const expectedProjectUserConfigObject: IConfig = {
$schema: "./imperative-test-cli.schema.json",
profiles: {
secured: {
type: "secured",
properties: {},
secure: []
},
project_base: {
type: "base",
properties: {},
secure: ["secret"]
}
},
defaults: {},
Expand Down
Loading
Loading