Skip to content

Commit

Permalink
Merge pull request #2383 from zowe/prof-info-api-fail
Browse files Browse the repository at this point in the history
Profile API merge error
  • Loading branch information
zFernand0 authored Dec 18, 2024
2 parents 9220a10 + 95a3fdd commit 2bf93ca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

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


## Recent Changes

- BugFix: Resolved an issue where base profiles in a team configuration file were overwritten when a user configuration file did not include a base profile. [#2383](https://github.com/zowe/zowe-cli/pull/2383)

## `8.10.0`

- BugFix: Modified location of Proxy-Authorization header to be located in the agent instead of the request. [#2389](https://github.com/zowe/zowe-cli/issues/2389)


## `8.8.3`

- BugFix: Modified 8.8.2 bugfix to correct web help alias. [#2361](https://github.com/zowe/zowe-cli/pull/2361)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,14 @@ describe("TeamConfig ProfileInfo tests", () => {
expect(arg.argValue).toEqual(expectedArgs[idx].argValue);
expect(arg.argLoc.locType).toBe(ProfLocType.TEAM_CONFIG);
expect(arg.argLoc.jsonLoc).toMatch(/^profiles\.(base_glob|LPAR2_home)\.properties\./);
expect(arg.argLoc.osLoc[0]).toEqual(path.normalize(path.join(teamHomeProjDir, `${testAppNm}.config.json`)));
expect([
path.normalize(
path.join(teamHomeProjDir, `${testAppNm}.config.json`)
),
path.normalize(
path.join(teamProjDir, `${testAppNm}.config.json`)
),
]).toContain(arg.argLoc.osLoc[0]);
}
});

Expand Down Expand Up @@ -956,6 +963,44 @@ describe("TeamConfig ProfileInfo tests", () => {
expect(caughtError).toBeDefined();
expect(caughtError.message).toContain("Profile attributes must be defined");
});
it("should fall back to layerProperties when realBaseProfileName is undefined", async () => {
const profInfo = createNewProfInfo(teamProjDir);
await profInfo.readProfilesFromDisk();

jest.spyOn(ProfileInfo.prototype, "getOsLocInfo").mockReturnValue([{
global: true,
name: "LPAR1",
path: "/mocked/path/xyz",
user: true
}]);

// Simulate the condition where the active layer has no `defaults.base` but global and user layers exist
const layerActive = profInfo.getTeamConfig().layerActive();
delete layerActive.properties.defaults.base;

const globalLayer = profInfo.getTeamConfig().findLayer(false, true);
globalLayer.properties.defaults.base = "globalBaseProfile";

const userLayer = profInfo.getTeamConfig().findLayer(true, true);
userLayer.properties.defaults.base = "";

const profAttrs = profInfo.getDefaultProfile("zosmf") as IProfAttrs;

// Merge args to trigger the logic
const mergedArgs = profInfo.mergeArgsForProfile(profAttrs);

// Expected args should include those from the global base profile
const expectedArgs = [
{argName: 'host', dataType: 'string', argValue: 'LPAR1.your.domain.net', secure: false},
{argName: 'port', dataType: 'number', argValue: 1234, secure: false},
{argName: 'responseFormatHeader', dataType: 'boolean', argValue: true, secure: false}
];

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

describe("mergeArgsForProfileType", () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ export class ProfileInfo {
if (osLoc?.global) {
layerProperties = this.mLoadedConfig.findLayer(osLoc.user, osLoc.global)?.properties;
realBaseProfileName = layerProperties?.defaults.base;
if (!realBaseProfileName && osLoc.user) {
layerProperties = this.mLoadedConfig.findLayer(false, osLoc.global)?.properties;
realBaseProfileName = layerProperties?.defaults.base;
}
if (realBaseProfileName) baseProfile = this.mLoadedConfig.api.profiles.buildProfile(realBaseProfileName, layerProperties?.profiles);
else baseProfile = null;
}
Expand Down Expand Up @@ -1650,15 +1654,11 @@ export class ProfileInfo {
};

let filePath: string;
if (_isPropInLayer(opts.configProperties) && opts.osLocInfo) {
filePath = opts.osLocInfo.path;
} else {
for (const layer of this.mLoadedConfig.mLayers) {
// Find the first layer that includes the JSON path
if (_isPropInLayer(layer.properties)) {
filePath = layer.path;
break;
}
for (const layer of this.mLoadedConfig.mLayers) {
// Find the first layer that includes the JSON path
if (_isPropInLayer(layer.properties)) {
filePath = layer.path;
break;
}
}

Expand Down

0 comments on commit 2bf93ca

Please sign in to comment.