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

Profile API merge error #2383

Merged
merged 16 commits into from
Dec 18, 2024
Merged

Profile API merge error #2383

merged 16 commits into from
Dec 18, 2024

Conversation

jace-roell
Copy link
Contributor

@jace-roell jace-roell commented Dec 10, 2024

What It Does
Resolves an issue where team config base profiles were being overwritten if a user config did not have a base profile.

How to Test
See attached issue for details.

Example Config Files:

zowe.config.user.json:

{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "zosmf": {
            "type": "zosmf",
            "properties": {
                "port": <port>
            }
        }
    },
    "defaults": {},
    "autoStore": true
}

zowe.config.json:

{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "zosmf":{
            "type": "zosmf",
            "properties": {
                "user": <user>,
                "password": <password>
            }
        },
        "global_base": {
            "type": "base",
            "properties": {
                "host": <host>,
                "rejectUnauthorized": false
            }
        }
    },
    "defaults": {
        "zosmf": "zosmf",
        "tso": "tso",
        "ssh": "ssh",
        "base": "global_base"
    },
    "autoStore": false
}

Review Checklist
I certify that I have:

Additional Comments

Signed-off-by: jace-roell <[email protected]>
Signed-off-by: jace-roell <[email protected]>
@jace-roell jace-roell changed the title Prof info api fail Profile API merge error Dec 10, 2024
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.28%. Comparing base (5b85f22) to head (95a3fdd).
Report is 20 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2383   +/-   ##
=======================================
  Coverage   91.27%   91.28%           
=======================================
  Files         638      638           
  Lines       18190    18207   +17     
  Branches     3888     3822   -66     
=======================================
+ Hits        16603    16620   +17     
  Misses       1586     1586           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jace-roell jace-roell marked this pull request as ready for review December 13, 2024 15:56
Copy link

📅 Suggested merge-by date: 12/27/2024

Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes and tests LGTM - I tested this alongside Zowe Explorer and its working as expected. Thanks for the fix Jace!

Without fix:
image

With fix:
image

@gejohnston
Copy link
Member

@jace-roell A user config merges differently when both config files are at the same level (profiles are merged property-by-property) than when one profile is global and one profile is in a project directory (the entire profile is replaced). Details are documented here:

zowe-cli/docs/How_config_files_are_merged.md

Have you manually tested such combinations to confirm that they all work as intended?

Copy link
Member

@zFernand0 zFernand0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice the properties seems to be loaded in accordance with the document that Geneshared:

Using the script below
/* Save this file as `test.mjs` and run `node test.mjs` */

import { ProfileInfo } from "@zowe/imperative";
import * as util from "util";
(async () => {
    const profInfo = new ProfileInfo("zowe");
    await profInfo.readProfilesFromDisk();
    const zosmfProfAttrs = profInfo.getDefaultProfile("zosmf");
    const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true });
    console.log("Known args: ", util.inspect(zosmfMergedArgs.knownArgs, {depth: 3, colors: true}))
})().catch((err) => {
    console.error(err);
    process.exit(1);
});

I can see the following outputs:

  • On `prof-info-api-fail` - rejectUnathorized is merged according to the document
    zFernand0 @ Mac (arm64) ~/gh/zowe/cli.master                                                                          [15:39:25]
    > $ node test.mjs                                                                            ⬡ system [±prof-info-api-fail ●(✹)]
        Known args:  [
          {
            argName: 'port',
            dataType: 'number',
            argValue: 1234,
            argLoc: {
              locType: 1,
              osLoc: [ '/Users/zFernand0/.zowe/zowe.config.user.json' ],
              jsonLoc: 'profiles.zosmf.properties.port'
            },
            secure: false,
            inSchema: true
          },
          {
            argName: 'rejectUnauthorized',
            dataType: 'boolean',
            argValue: false,
            argLoc: {
              locType: 1,
              osLoc: [ '/Users/zFernand0/.zowe/zowe.config.user.json' ],
              jsonLoc: 'profiles.base.properties.rejectUnauthorized'
            },
            secure: false,
            inSchema: true
          }
        ]
  • On Master (rejectUnathorized is not merged according to the document)
    zFernand0 @ Mac (arm64) ~/gh/zowe/cli.master                                                                          [15:39:25]
    > $ node test.mjs                                                                                        ⬡ system [±master ●(✹)]
        Known args:  [
          {
            argName: 'port',
            dataType: 'number',
            argValue: 1234,
            argLoc: {
              locType: 1,
              osLoc: [ '/Users/zFernand0/.zowe/zowe.config.user.json' ],
              jsonLoc: 'profiles.zosmf.properties.port'
            },
            secure: false,
            inSchema: true
          }
        ]

The reason for the requested changes is that is you look closely, the osLoc for rejecjectUnauthorized is pointing to the global user config instead of where it came from (the global regular/non-user config). Having a wrong osLoc value may cause other issues in the future if properties need to be updated. I believe we go to that osLoc and update them. Then, attempting to update the rejectUnauthorized value may result in a new base profile being created in the config.user.json file 😋


And yeah, my configs are as simple as:

`zowe.config.user.json`
{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "zosmf": {
            "type": "zosmf",
            "properties": {
                "port": 1234
            },
            "secure": []
        }
    },
    "defaults": {
        "zosmf": "zosmf"
    },
    "autoStore": true
}
`zowe.config.json`
{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "base": {
            "type": "base",
            "properties": {
                "rejectUnauthorized": false
            },
            "secure": []
        }
    },
    "defaults": {
        "base": "base"
    },
    "autoStore": true
}

Copy link
Contributor

@anaxceron anaxceron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting some edits to the changelog entry

Signed-off-by: jace-roell <[email protected]>
Copy link
Contributor

@anaxceron anaxceron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice changelog @jace-roell!

@jace-roell jace-roell requested a review from zFernand0 December 17, 2024 21:24
Copy link
Member

@zFernand0 zFernand0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some lint warnings regarding indentation after removing the if/else login for the osLocInfo 😋
https://github.com/zowe/zowe-cli/actions/runs/12394840626/job/34599196199?pr=2383#step:5:44

But other than that, this PR LGTM! 😋

Signed-off-by: jace-roell <[email protected]>
@jace-roell jace-roell requested a review from zFernand0 December 18, 2024 15:00
@zFernand0 zFernand0 merged commit 2bf93ca into master Dec 18, 2024
18 checks passed
@zFernand0 zFernand0 deleted the prof-info-api-fail branch December 18, 2024 15:31
@zFernand0 zFernand0 added the release-patch Indicates a patch to existing code has been applied label Dec 18, 2024
Copy link

Release succeeded for the master branch. 🎉

The following packages have been published:

Powered by Octorelease 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-patch Indicates a patch to existing code has been applied released
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

ProfileInfo API fails to load base profile when Global User Config exists
5 participants