zowe / zowe-cli

Zowe CLI
Eclipse Public License 2.0
116 stars 85 forks source link

Cannot update password with the SDK #1573

Open kraabrsg opened 2 years ago

kraabrsg commented 2 years ago

1.) when updating the secure stored password, on extension restart an old password is loaded "mLoadedConfig-mSecure-profiles.base.properties.password" (when doing readProfilesFromDisk) (als see this question on slack https://openmainframeproject.slack.com/archives/C010AUS5MK5/p1669033876331619)

This is reallly needed because we then don't have to worry about zowe cli installation (and we want to replace cli commands like zowe config set --global-config --secure with sdk methods..) then (don't need to install node/npm )...

relevant code:

await CredentialManagerFactory.initialize({ service: "zowe" });

const profInfo = new imperative.ProfileInfo("zowe");
await profInfo.readProfilesFromDisk({ projectDir: false });
const baseProfAttrs = profInfo.getDefaultProfile("base");
const baseMergedArgs = profInfo.mergeArgsForProfile(baseProfAttrs, { getSecureVals: true });

await profInfo.updateKnownProperty({ mergedArgs: baseMergedArgs, property: "password", value: "yes" });

Further details (if necessary): dependencies:

"@zowe/imperative": "^5.7.2",
"@zowe/cli": "^7.8.0",
"@zowe/zos-files-for-zowe-sdk": "^7.8.0",
"@zowe/zos-ftp-for-zowe-cli": "2.1.0",
"@zowe/zos-jobs-for-zowe-sdk": "^7.8.0",
"@zowe/zos-tso-for-zowe-sdk": "^7.8.0",
"@zowe/zosmf-for-zowe-sdk": "^7.8.0",
"keytar": "7.9.0",

devdependencies:

...
"@types/node": "^18.0.3", 
"typescript": "^4.7.4"

zowe.config.json:

{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "tso": {
            "type": "tso",
            "properties": {
                "account": "xxx",
                "codePage": "1141",
                "logonProcedure": "xxx",
                "characterSet": "695"
            },
            "secure": []
        },
        "ssh": {
            "type": "ssh",
            "properties": {
                "port": 22
            },
            "secure": []
        },
        "base": {
            "properties": {
                "host": "xxxx",
                "port": 443
            },
            "type": "base",
            "secure": [
                "user",
                "password"
            ]
        }
    },
    "defaults": {
        "tso": "tso",
        "ssh": "ssh",
        "base": "base"
    },
    "autoStore": true
}

cli works like expected from commandline...

thanks (this is done within a vscode extension )!

github-actions[bot] commented 2 years ago

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.

gejohnston commented 2 years ago

Efforts in the related slack conversation have identified no configuration error that would explain this bad behavior. Therefore, we should treat this as a more serious bug which could affect multiple consumers.

kraabrsg commented 1 year ago

Hi @gejohnston any news on this, a fix would save us delivering a nodejs installation... Thanks!

gejohnston commented 1 year ago

Hi @kraabrsg We are still waiting for an opportunity for Product Management staff to review this issue and establish the priority. I will say that our upcoming quarter looks very busy. I do not know if time will be allocated to work on this issue in the next quarter. The Zowe quarterly planning meetings occur during the week of Jan 23, 2023. Some priorities may become more clear after those meetings. You are welcome to attend the planning breakout meetings for Zowe CLI, if you would like to further promote your needs.

kraabrsg commented 1 year ago

Hi @gejohnston thank you for the invitation, my colleaugue found a way around this, by mimic its behaviour and replacing what the commands are doing.

gejohnston commented 1 year ago

Because a workaround was identified, we changed severity and priority to medium. To provide input to any future implementation, can you elaborate more on the techniques used in your workaround?

kraabrsg commented 1 year ago

Hi @gejohnston , well it is basically mimics IProfArgAttrs]

at extensions start

await Promise.all(xxxx, ZoweCliZosmf.initZosmfSession());

the details:

export class ZoweCliZosmf {
    public static session: Session;

    public static async initZosmfSession() {
       //mimic iprofargsattrs to use keytar
        let args: IProfArgAttrs[] = [
            {
                argName: "port",
                dataType: "number",
                argValue: workspace.getConfiguration().get<number>("host.port"),
                argLoc: {
                    locType: 1
                },
                secure: false
            }, {
                argName: "host",
                dataType: "string",
                argValue: workspace.getConfiguration().get<number>("host.host"),
                argLoc: {
                    locType: 1
                },
                secure: false
            }, {
                argName: "rejectUnauthorized",
                dataType: "boolean",
                argValue: false,
                argLoc: {
                    locType: 1
                },
                secure: false
            }, {
                argName: "user",
                dataType: "string",
                argLoc: {
                    locType: 1
                },
                secure: true,
                argValue: workspace.getConfiguration().get<number>("host.user") ?? xxxx.user
            }, {
                argName: "password",
                dataType: "string",
                argLoc: {
                    locType: 1
                },
                secure: true,
                argValue: await keytar.getPassword("myhost-host", xxxx.getUser())
            }
        ];
        this.session = ProfileInfo.createSession(args);
    }
}