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

VSCode Explorer using mergeArgsForProfile - returns incorrect result when used in conjunction with a zowe.config.user.json file #2316

Open
davidkjackson54 opened this issue Oct 21, 2024 · 5 comments
Assignees
Labels
bug Something isn't working priority-high Production outage - this quarter or at least next quarter severity-high Bug for which there may be workaround but limits the usage of the Zowe for major use cases

Comments

@davidkjackson54
Copy link

davidkjackson54 commented Oct 21, 2024

I have a VSCode Explorer that needs to create a session.
my zowe.config.json contains this

{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "base": {
            "type": "base",
            "properties": {
                "host": "myHost.com",
                "rejectUnauthorized": true
            },
            "secure": [
                "user",
                "password"
            ]
        },
        "zmf_a": {
            "type": "zmf",
            "properties": {
                "protocol": "http",
                "host": "myHost.com",
                "port": 8280,
                "basePath": "/zmfa",
                "rejectUnauthorized": false
            },
            "secure": [
                "user",
                "password"
            ]
        }
    },
    "defaults": {
        "zmf": "zmf_a",
        "base": "base"
    },
    "autoStore": true
}

I have user and password both saved in the Credentials vault:
D:\saved source\vault>node vault.js

{
  'C:\\Users\\david\\.zowe\\zowe.config.json': {
    'profiles.base.properties.user': 'MYUSER',
    'profiles.base.properties.password': 'myPass',
    'profiles.zmf_a.properties.user': 'MYUSER',
    'profiles.zmf_a.properties.password': 'myPass'
  }
}

I initially do this:

const requireKeytar = () => require("@zowe/secrets-for-zowe-sdk").keyring;
    this.profInfo = new ProfileInfo("zowe", {
      credMgrOverride: ProfileCredentials.defaultCredMgrWithKeytar(requireKeytar),
    });

Then I retriever my profiles

this.zmfProfNames = this.profInfo.getAllProfiles("zmf"); // retrieve ZMF from all profile location sources
 this.baseProfNames = this.profInfo.getAllProfiles("base");

Then for each profile in the array, I call mergeArgsForProfile

const profileArgs: IZmfParms[] = [];
    for (const [index, element] of profileNames.entries()) {
     profileArgs[index] = {
        // array of all profile parms
        mergedArgs: this.profInfo.mergeArgsForProfile(element, { getSecureVals: true }), 
        name: element.profName, // save profile name
        type: element.profType, // save profile type - just in case
        jsonLoc: element.profLoc.jsonLoc, // save the json file location - just in case
      };
   }

When I inspect profileArgs, it correctly shows knownArgs and no missingArgs

0 ={mergedArgs: {…}, name: 'zmf_a', type: 'zmf', jsonLoc: 'profiles.zmf_a'}
jsonLoc ='profiles.zmf_a'
mergedArgs ={knownArgs: Array(7), missingArgs: Array(0)}
knownArgs =
0 ={argName: 'protocol', dataType: 'string', argValue: 'http', argLoc: {…}, secure: false, …}
1 ={argName: 'host', dataType: 'string', argValue: 'myHost.com', argLoc: {…}, secure: false, …}
2 ={argName: 'port', dataType: 'number', argValue: 8280, argLoc: {…}, secure: false, …}
3 ={argName: 'basePath', dataType: 'string', argValue: '/zmfrestn', argLoc: {…}, secure: false, …}
4 ={argName: 'rejectUnauthorized', dataType: 'boolean', argValue: false, argLoc: {…}, secure: false, …}
5 ={argName: 'user', dataType: 'string', argLoc: {…}, secure: true, inSchema: true, …}
6 ={argName: 'password', dataType: 'string', argLoc: {…}, secure: true, inSchema: true, …}
length =7

missingArgs =(0) []

If I now add an empty zowe.config.user.json file:

{
    "$schema": "./zowe.schema.json",
     "profiles": {},   
     "defaults": {},
    "autoStore": true
} 

and test again, I am now seeing profileArgs report user and password as missingArgs.

0 ={mergedArgs: {…}, name: 'zmf_a', type: 'zmf', jsonLoc: 'profiles.zmf_a'}
jsonLoc ='profiles.zmf_a'
mergedArgs ={knownArgs: Array(5), missingArgs: Array(2)}
knownArgs =(5) [{…}, {…}, {…}, {…}, {…}]
missingArgs =(2) 
0 ={argName: 'user', dataType: 'string', argValue: undefined, argLoc: {…}, inSchema: true, …}
1 ={argName: 'password', dataType: 'string', argValue: undefined, argLoc: {…}, inSchema: true, …}
length =2

Either I am misunderstanding how the zowe.config.user.json is used or this is a bug. as both user and password are present in the vault.

As a further test, I then copied the zowe.config.,json into the zowe.config.user.json - so they are now identical and then reran the test again.
Once again, it reports both user and password in missingArgs.

I then changed the defaults in the zowe.config.user.json file to now be:

"defaults": {},
 "autoStore": true

and reran the test again.
This time, I am seeing no missingArgs but the knownArgs are incorrect and show this:

0 ={mergedArgs: {…}, name: 'zmf_a', type: 'zmf', jsonLoc: 'profiles.zmf_a'}
jsonLoc ='profiles.zmf_a'
mergedArgs ={knownArgs: Array(7), missingArgs: Array(0)}
knownArgs =(7)
0 ={argName: 'protocol', dataType: 'string', argValue: 'http', argLoc: {…}, secure: false, …}
1 ={argName: 'host', dataType: 'string', argValue: 'myHost.com', argLoc: {…}, secure: false, …}
2 ={argName: 'port', dataType: 'number', argValue: 8280, argLoc: {…}, secure: false, …}
3 ={argName: 'basePath', dataType: 'string', argValue: '/zmfrestn', argLoc: {…}, secure: false, …}
4 ={argName: 'rejectUnauthorized', dataType: 'boolean', argValue: false, argLoc: {…}, secure: false, …}
5 ={argName: 'user', dataType: 'string', argLoc: {…}, secure: true, inSchema: true, …}
  argLoc ={locType: 1, osLoc: Array(1), jsonLoc: 'profiles.zmf_a.properties.user'}
  argName ='user'
  argValue =undefined
  dataType ='string'
  inSchema =true
  secure =true
6 ={argName: 'password', dataType: 'string', argLoc: {…}, secure: true, inSchema: true, …}
  argLoc ={locType: 1, osLoc: Array(1), jsonLoc: 'profiles.zmf_a.properties.password'}
  argName ='password'
  argValue =undefined
  dataType ='string'
  inSchema =true
  secure =true

Notice that now user and password are considered to be knownArgs but the argValues are undefined.

Something isn't quite right here.

@davidkjackson54 davidkjackson54 added bug Something isn't working new The issue wasn't triaged yet labels Oct 21, 2024
@github-project-automation github-project-automation bot moved this to New Issues in Zowe CLI Squad Oct 21, 2024
Copy link

Thank you for creating a bug report.
We will investigate the bug and evaluate its impact on the product.
If you haven't already, please ensure you have provided steps to reproduce the bug and as much context as possible.

@davidkjackson54 davidkjackson54 changed the title VSCode Explorer using mergeArgsForProfile - returns incorrect result when using a zowe.config.user.json file VSCode Explorer using mergeArgsForProfile - returns incorrect result when used in conjunction with a zowe.config.user.json file Oct 21, 2024
@JTonda JTonda added priority-high Production outage - this quarter or at least next quarter severity-high Bug for which there may be workaround but limits the usage of the Zowe for major use cases and removed new The issue wasn't triaged yet labels Oct 23, 2024
@zowe-robot zowe-robot moved this from New Issues to High Priority in Zowe CLI Squad Oct 23, 2024
@t1m0thyj
Copy link
Member

@davidkjackson54 I assume your zowe.config.json and zowe.config.user.json file both located in your Zowe home directory (C:\Users\david\.zowe). Is this assumption correct? Also can you confirm that you don't have any zowe.config.json files in a project directory?

I've tried to reproduce both issues with exactly the same config, except I used profile type zosmf instead of zmf because I don't have the zmf profile defined in my schema JSON file. I see the second issue (no missingArgs but the knownArgs are incorrect), however I'm unable to reproduce the first one (profileArgs report user and password as missingArgs) because user and password still show as knownArgs for me.

@davidkjackson54
Copy link
Author

Hi TImothy,
I can confirm that the 2 config files reside in my /.zowe folder within my user folder and that no other copies of the config files exist anywhere else.

I ran through the test again making sure that only the user and password defined in profile in the zowe.config.json have their secure Args stored in the vault.
D:\saved source\vault>node vault.js

{
  'C:\\Users\\david\\.zowe\\zowe.config.json': {
    'profiles.base.properties.user': 'DJ',
    'profiles.base.properties.password': 'djpw',
    'profiles.zmf_a.properties.user': 'DJ2',
    'profiles.zmf_a.properties.password': 'djpw2'
  }
}

After mergeArgsForProfile with the empty zowe.config.user.,json file present, I see this:
Here is element expanded:

profLoc = {locType: 1, osLoc: Array(1), jsonLoc: 'profiles.zmf_a'}
jsonLoc ='profiles.zmf_a'
locType =1
osLoc =(1) ['C:\\Users\\david\\.zowe\\zowe.config.json']
0 ='C:\\Users\\david\\.zowe\\zowe.config.json'
length =1
profName ='zmf_a'
profType ='zmf'

Then I expand profArgs after the call to mergeArgsForProfile

0 = {mergedArgs: {…}, name: 'zmf_a', type: 'zmf', jsonLoc: 'profiles.zmf_a'}
jsonLoc = 'profiles.zmf_a'
mergedArgs = {knownArgs: Array(5), missingArgs: Array(2)}
knownArgs =(5) [{…}, {…}, {…}, {…}, {…}]
0 ={argName: 'protocol', dataType: 'string', argValue: 'http', argLoc: {…}, secure: false, …}
1 ={argName: 'host', dataType: 'string', argValue: 'myHost.com', argLoc: {…}, secure: false, …}
2 ={argName: 'port', dataType: 'number', argValue: 8280, argLoc: {…}, secure: false, …}
3 ={argName: 'basePath', dataType: 'string', argValue: '/zmfa', argLoc: {…}, secure: false, …}
4 ={argName: 'rejectUnauthorized', dataType: 'boolean', argValue: false, argLoc: {…}, secure: false, …}

missingArgs =(2) [{…}, {…}]
0 ={argName: 'user', dataType: 'string', argValue: undefined, argLoc: {…}, inSchema: true, …}
argLoc = {locType: 1, osLoc: Array(1), jsonLoc: 'profiles.zmf_a.properties.user'}
jsonLoc = 'profiles.zmf_a.properties.user'
locType =1
osLoc =(1) ['C:\\Users\\david\\.zowe\\zowe.config.json']
argName = 'user'
argValue =undefined
dataType ='string'
inSchema =true
secure =true
1 ={argName: 'password', dataType: 'string', argValue: undefined, argLoc: {…}, inSchema: true, …}
argLoc = {locType: 1, osLoc: Array(1), jsonLoc: 'profiles.zmf_a.properties.password'}

jsonLoc ='profiles.zmf_a.properties.password'
locType =1
osLoc =(1) ['C:\\Users\\david\\.zowe\\zowe.config.json']
argName = 'password'
argValue = undefined
dataType ='string'
inSchema =true
secure =true

name ='zmf_a'
type ='zmf'

This does not occur if the empty user config is not present.

Are there any additional diagnostics that might help here?

@davidkjackson54
Copy link
Author

I have sent you via slack a slimmed down sample program that helps highlight the missingArg issue

@t1m0thyj
Copy link
Member

t1m0thyj commented Dec 5, 2024

I was able to reproduce the issue with the following files:

zowe.config.json

{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "base": {
            "type": "base",
            "properties": {
                "host": "myHost.com",
                "rejectUnauthorized": true
            },
            "secure": [
                "user",
                "password"
            ]
        },
        "zmf_a": {
            "type": "zosmf",
            "properties": {
                "protocol": "http",
                "host": "myHost.com",
                "port": 8280,
                "basePath": "/zmfa",
                "rejectUnauthorized": false
            },
            "secure": [
                "user",
                "password"
            ]
        }
    },
    "defaults": {
        "zosmf": "zmf_a",
        "base": "base"
    },
    "autoStore": true
}

zowe.config.user.json

{
    "$schema": "./zowe.schema.json",
    "profiles": {},
    "defaults": {},
    "autoStore": true
}

Sample Script

const { ProfileCredentials, ProfileInfo } = require("@zowe/imperative");

(async () => {
    // Load connection info from default z/OSMF profile
    const requireKeytar = () => require("@zowe/secrets-for-zowe-sdk").keyring;
    const profInfo = new ProfileInfo("zowe", {
        credMgrOverride: ProfileCredentials.defaultCredMgrWithKeytar(requireKeytar),
    });
    console.log("returned profInfo ", profInfo);
    await profInfo.readProfilesFromDisk();
    const zosmfProfNames = profInfo.getAllProfiles("zosmf");
    const baseProfNames = profInfo.getAllProfiles("base");
    console.log("ZMF profiles ", zosmfProfNames);
    console.log("profLoc expands to ", zosmfProfNames[0].profLoc);
    console.log("BASE profiles ", baseProfNames);
    console.log("profLoc expands to ", baseProfNames[0].profLoc);
    for (const element of zosmfProfNames) {
        console.log("return from mergeArgsForProfile ", profInfo.mergeArgsForProfile(element, { getSecureVals: true }));
    }
})().catch((err) => {
    console.error(err);
    process.exit(1);
});

@JTonda JTonda assigned zFernand0 and unassigned t1m0thyj Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high Production outage - this quarter or at least next quarter severity-high Bug for which there may be workaround but limits the usage of the Zowe for major use cases
Projects
Status: High Priority
Development

No branches or pull requests

4 participants