Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

ProfileInfo: Identify non-schema properties in the mergedArgs #1001

Merged
merged 8 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions 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 `inSchema` property for ProfileInfo to indicate if argument is a known schema argument [#899](https://github.com/zowe/imperative/issues/899)

## `5.16.0`

- Enhancement: Handled unique cookie identifier in the form of dynamic token types. [#966](https://github.com/zowe/imperative/pull/996)
Expand Down
32 changes: 27 additions & 5 deletions packages/config/__tests__/ProfileInfo.TeamConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,20 @@ describe("TeamConfig ProfileInfo tests", () => {

describe("getAllProfiles", () => {
it("should return all profiles if no type is specified", async () => {
const length = 7;
const expectedDefaultProfiles = 4;
const expectedDefaultProfileNameZosmf = "LPAR1";
const expectedDefaultProfileNameTso = "LPAR1.tsoProfName";
const expectedDefaultProfileNameBase = "base_glob";
const expectedDefaultProfileNameDummy = "LPAR4";
let actualDefaultProfiles = 0;
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR1.tsoProfName", "LPAR1.tsoProfName.tsoSubProfName", "base_glob", "LPAR4"];
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR1.tsoProfName", "LPAR1.tsoProfName.tsoSubProfName",
"base_glob", "LPAR4", "LPAR5"];

const profInfo = createNewProfInfo(teamProjDir);
await profInfo.readProfilesFromDisk();
const profAttrs = profInfo.getAllProfiles();

expect(profAttrs.length).toEqual(length);
expect(profAttrs.length).toEqual(expectedProfileNames.length);
for (const prof of profAttrs) {
if (prof.isDefaultProfile) {
let expectedName = "";
Expand Down Expand Up @@ -355,7 +355,7 @@ describe("TeamConfig ProfileInfo tests", () => {
const desiredProfType = "zosmf";
const expectedName = "LPAR1";
const expectedDefaultProfiles = 1;
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR2_home"];
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR2_home", "LPAR5"];
let actualDefaultProfiles = 0;

const profInfo = createNewProfInfo(teamProjDir);
Expand Down Expand Up @@ -389,7 +389,7 @@ describe("TeamConfig ProfileInfo tests", () => {
const desiredProfType = "zosmf";
const expectedName = "LPAR1";
const expectedDefaultProfiles = 1;
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3"];
let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR5"];
let actualDefaultProfiles = 0;

const profInfo = createNewProfInfo(teamProjDir);
Expand Down Expand Up @@ -753,6 +753,28 @@ describe("TeamConfig ProfileInfo tests", () => {
}
});

it("should find correct inSchema args", async () => {
const profInfo = createNewProfInfo(teamProjDir);
await profInfo.readProfilesFromDisk();
const profAttrs = profInfo.getAllProfiles()[7] as IProfAttrs;
const mergedArgs = profInfo.mergeArgsForProfile(profAttrs);

const expectedArgs = [
{ argName: "host", inSchema: true },
{ argName: "port", inSchema: true },
{ argName: "responseFormatHeader", inSchema: false },
{ argName: "fakeOffSchemaArg", inSchema: false },
{ argName: "user", inSchema: true },
{ argName: "password", inSchema: true },
{ argName: "rejectUnauthorized", inSchema: true },
];

expect(mergedArgs.knownArgs.length).toBe(expectedArgs.length);
for (const [idx, arg] of mergedArgs.knownArgs.entries()) {
expect(arg.inSchema).toEqual(expectedArgs[idx].inSchema);
}
});

it("should throw if schema fails to load", async () => {
const profInfo = createNewProfInfo(teamProjDir);
await profInfo.readProfilesFromDisk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
"host": "LPAR4.your.domain.net",
"responseFormatHeader": true
}
},
"LPAR5": {
"type": "zosmf",
"properties": {
"host": "LPAR4.your.domain.net",
"port": 1234,
"responseFormatHeader": true,
"fakeOffSchemaArg": "fakeArg"
}
}
},
"defaults": {
Expand Down
9 changes: 7 additions & 2 deletions packages/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ export class ProfileInfo {
dataType: this.argDataType(typeof propVal), // TODO Is using `typeof` bad for "null" values that may be int or bool?
argValue: propVal,
argLoc,
secure
secure,
inSchema: false
});
}
}
Expand Down Expand Up @@ -654,7 +655,8 @@ export class ProfileInfo {
dataType: this.argDataType(typeof propVal),
argValue: propVal,
argLoc,
secure
secure,
inSchema: false
});
}
}
Expand Down Expand Up @@ -746,6 +748,7 @@ export class ProfileInfo {
dataType: this.argDataType(propInfoInSchema.type),
argValue: (propInfoInSchema as ICommandProfileProperty).optionDefinition?.defaultValue,
argLoc,
inSchema: true,
// See https://github.com/zowe/imperative/issues/739
secure: foundInSecureArray || propInfoInSchema.secure
};
Expand All @@ -760,13 +763,15 @@ export class ProfileInfo {
if (!argFound) {
mergedArgs.missingArgs.push({
argName: propName,
inSchema: true,
dataType: this.argDataType(propInfoInSchema.type),
argValue: (propInfoInSchema as ICommandProfileProperty).optionDefinition?.defaultValue,
argLoc: { locType: ProfLocType.DEFAULT },
secure: propInfoInSchema.secure
});
}
} else {
knownArg.inSchema = true;
knownArg.secure = knownArg.secure ?? propInfoInSchema.secure;
if (knownArg.secure) {
delete knownArg.argValue;
Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/doc/IProfArgAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ export interface IProfArgAttrs {

/** Whether the argument value is stored securely */
secure?: boolean;

/** Whether the argument value is defined in the schema file */
inSchema?: boolean;
}