diff --git a/packages/zowe-explorer/i18n/sample/package.i18n.json b/packages/zowe-explorer/i18n/sample/package.i18n.json index 5930969b05..e788086fbf 100644 --- a/packages/zowe-explorer/i18n/sample/package.i18n.json +++ b/packages/zowe-explorer/i18n/sample/package.i18n.json @@ -2,7 +2,7 @@ "displayName": "Zowe Explorer", "description": "VS Code extension, powered by Zowe CLI, that streamlines interaction with mainframe data sets, USS files, and jobs", "viewsContainers.activitybar": "Zowe Explorer", - "zowe.promptCredentials": "Update Credentials", + "zowe.promptCredentials": "Manage Credentials", "zowe.extRefresh": "Refresh Zowe Explorer", "zowe.ds.explorer": "Data Sets", "zowe.uss.explorer": "Unix System Services (USS)", diff --git a/packages/zowe-explorer/i18n/sample/src/utils/ProfilesUtils.i18n.json b/packages/zowe-explorer/i18n/sample/src/utils/ProfilesUtils.i18n.json index db62def29c..d37c8ed906 100644 --- a/packages/zowe-explorer/i18n/sample/src/utils/ProfilesUtils.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/utils/ProfilesUtils.i18n.json @@ -12,6 +12,12 @@ "createNewConnection.option.prompt.profileName.placeholder": "Connection Name", "createNewConnection.option.prompt.profileName": "Enter a name for the connection.", "createNewConnection.undefined.passWord": "Operation Cancelled", + "promptCredentials.quickPick.basicAuthLabel": "$(circle-large) User and Password", + "promptCredentials.quickPick.basicAuthDescription": "Store user and password", + "promptCredentials.quickPick.tokenAuthLabel": "$(circle-large) Authentication Token", + "promptCredentials.quickPick.tokenAuthDescription": "Authenticate to API and store a token", + "promptCredentials.quickPick.logOutLabel": "Log out of Authentication Service", + "promptCredentials.quickPick.title": "Select an authentication method", "promptCredentials.updatedCredentials": "Credentials for {0} were successfully updated", "initializeZoweFolder.location": "Zowe home directory is located at {0}", "writeOverridesFile.readFile.error": "Reading imperative.json failed. Will try to create file.", diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index b4c8a1a7cc..76e6a8b311 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -939,30 +939,20 @@ "group": "099_zowe_ussModification:@4" }, { - "when": "view == zowe.uss.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.uss.disableValidation", + "when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", + "command": "zowe.promptCredentials", "group": "098_zowe_ussProfileAuthentication@1" }, { - "when": "view == zowe.uss.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.uss.enableValidation", + "when": "view == zowe.uss.explorer && viewItem =~ /_validate/ && !listMultiSelection", + "command": "zowe.uss.disableValidation", "group": "098_zowe_ussProfileAuthentication@2" }, { - "when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", - "command": "zowe.promptCredentials", + "when": "view == zowe.uss.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", + "command": "zowe.uss.enableValidation", "group": "098_zowe_ussProfileAuthentication@3" }, - { - "when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", - "command": "zowe.uss.ssoLogin", - "group": "098_zowe_ussProfileAuthentication@4" - }, - { - "when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", - "command": "zowe.uss.ssoLogout", - "group": "098_zowe_ussProfileAuthentication@5" - }, { "when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", "command": "zowe.uss.editSession", @@ -1149,30 +1139,20 @@ "group": "099_zowe_dsModification@5" }, { - "when": "view == zowe.ds.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.ds.disableValidation", + "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", + "command": "zowe.promptCredentials", "group": "098_zowe_dsProfileAuthentication@6" }, { - "when": "view == zowe.ds.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.ds.enableValidation", + "when": "view == zowe.ds.explorer && viewItem =~ /_validate/ && !listMultiSelection", + "command": "zowe.ds.disableValidation", "group": "098_zowe_dsProfileAuthentication@7" }, { - "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", - "command": "zowe.promptCredentials", + "when": "view == zowe.ds.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", + "command": "zowe.ds.enableValidation", "group": "098_zowe_dsProfileAuthentication@8" }, - { - "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", - "command": "zowe.ds.ssoLogin", - "group": "098_zowe_dsProfileAuthentication@9" - }, - { - "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", - "command": "zowe.ds.ssoLogout", - "group": "098_zowe_dsProfileAuthentication@10" - }, { "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", "command": "zowe.ds.editSession", @@ -1314,30 +1294,20 @@ "group": "099_zowe_jobsModification" }, { - "when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.jobs.disableValidation", + "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", + "command": "zowe.promptCredentials", "group": "098_zowe_jobsProfileAuthentication@3" }, { - "when": "view == zowe.jobs.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.jobs.enableValidation", + "when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection", + "command": "zowe.jobs.disableValidation", "group": "098_zowe_jobsProfileAuthentication@4" }, { - "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", - "command": "zowe.promptCredentials", + "when": "view == zowe.jobs.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", + "command": "zowe.jobs.enableValidation", "group": "098_zowe_jobsProfileAuthentication@5" }, - { - "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", - "command": "zowe.jobs.ssoLogin", - "group": "098_zowe_jobsProfileAuthentication@6" - }, - { - "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", - "command": "zowe.jobs.ssoLogout", - "group": "098_zowe_jobsProfileAuthentication@7" - }, { "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", "command": "zowe.jobs.editSession", diff --git a/packages/zowe-explorer/package.nls.json b/packages/zowe-explorer/package.nls.json index 5930969b05..e788086fbf 100644 --- a/packages/zowe-explorer/package.nls.json +++ b/packages/zowe-explorer/package.nls.json @@ -2,7 +2,7 @@ "displayName": "Zowe Explorer", "description": "VS Code extension, powered by Zowe CLI, that streamlines interaction with mainframe data sets, USS files, and jobs", "viewsContainers.activitybar": "Zowe Explorer", - "zowe.promptCredentials": "Update Credentials", + "zowe.promptCredentials": "Manage Credentials", "zowe.extRefresh": "Refresh Zowe Explorer", "zowe.ds.explorer": "Data Sets", "zowe.uss.explorer": "Unix System Services (USS)", diff --git a/packages/zowe-explorer/src/utils/ProfilesUtils.ts b/packages/zowe-explorer/src/utils/ProfilesUtils.ts index 3152e66200..84ff5e32ca 100644 --- a/packages/zowe-explorer/src/utils/ProfilesUtils.ts +++ b/packages/zowe-explorer/src/utils/ProfilesUtils.ts @@ -330,19 +330,64 @@ export class ProfilesUtils { } } - const creds = await Profiles.getInstance().promptCredentials(profile, true); - - if (creds != null) { - const successMsg = localize( - "promptCredentials.updatedCredentials", - "Credentials for {0} were successfully updated", - typeof profile === "string" ? profile : profile.name - ); - ZoweLogger.info(successMsg); - Gui.showMessage(successMsg); - // config file watcher isn't noticing changes for secure fields - await vscode.commands.executeCommand("zowe.extRefresh"); + const hasTokenValue = typeof profile === "string" || profile.profile?.tokenValue != null; + const authTypeChoices: Record = { + [imperative.SessConstants.AUTH_TYPE_BASIC]: { + label: localize("promptCredentials.quickPick.basicAuthLabel", "$(circle-large) User and Password"), + description: localize("promptCredentials.quickPick.basicAuthDescription", "Store user and password"), + }, + [imperative.SessConstants.AUTH_TYPE_TOKEN]: { + label: localize("promptCredentials.quickPick.tokenAuthLabel", "$(circle-large) Authentication Token"), + description: localize("promptCredentials.quickPick.tokenAuthDescription", "Authenticate to API and store a token"), + }, + // [imperative.SessConstants.AUTH_TYPE_CERT_PEM]: { + // label: localize("promptCredentials.quickPick.certAuthLabel", "$(circle-large) Certificate File"), + // description: localize("promptCredentials.quickPick.certAuthDescription", "Connect with PEM certificate file"), + // }, + }; + let currentAuthType = imperative.SessConstants.AUTH_TYPE_BASIC; + if (typeof profile !== "string" && profile.profile?.tokenType != null) { + currentAuthType = imperative.SessConstants.AUTH_TYPE_TOKEN; + } else if (typeof profile !== "string" && profile.profile?.certFile != null) { + // currentAuthType = imperative.SessConstants.AUTH_TYPE_CERT_PEM; + } + authTypeChoices[currentAuthType].label = authTypeChoices[currentAuthType].label.replace("$(circle-large)", "$(record)"); + const quickPickOptions: vscode.QuickPickItem[] = Object.values(authTypeChoices); + if (hasTokenValue) { + quickPickOptions.push(globals.SEPARATORS.BLANK, { + label: localize("promptCredentials.quickPick.logOutLabel", "Log out of Authentication Service"), + }); } + const qp = Gui.createQuickPick(); + qp.items = quickPickOptions; + qp.activeItems = [authTypeChoices[currentAuthType]]; + qp.title = localize("promptCredentials.quickPick.title", "Select an authentication method"); + return new Promise((resolve) => { + qp.onDidChangeSelection(async ([item]) => { + if (item === authTypeChoices[imperative.SessConstants.AUTH_TYPE_BASIC]) { + const creds = await Profiles.getInstance().promptCredentials(profile, true); + if (creds != null) { + const successMsg = localize( + "promptCredentials.updatedCredentials", + "Credentials for {0} were successfully updated", + typeof profile === "string" ? profile : profile.name + ); + ZoweLogger.info(successMsg); + Gui.showMessage(successMsg); + // config file watcher isn't noticing changes for secure fields + await vscode.commands.executeCommand("zowe.extRefresh"); + } + } else if (item === authTypeChoices[imperative.SessConstants.AUTH_TYPE_TOKEN]) { + await Profiles.getInstance().ssoLogin(node); + } else if (item === authTypeChoices[imperative.SessConstants.AUTH_TYPE_CERT_PEM]) { + // TODO Add support for certificates + } else if (hasTokenValue && item === quickPickOptions[quickPickOptions.length - 1]) { + await Profiles.getInstance().ssoLogout(node); + } + resolve(); + }); + qp.show(); + }); } public static async initializeZoweFolder(): Promise {