Skip to content

Commit

Permalink
Enhance UX for managing credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Sep 6, 2023
1 parent 45d0625 commit 974fdd5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packages/zowe-explorer/i18n/sample/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
66 changes: 18 additions & 48 deletions packages/zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
69 changes: 57 additions & 12 deletions packages/zowe-explorer/src/utils/ProfilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, vscode.QuickPickItem> = {
[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<void> {
Expand Down

0 comments on commit 974fdd5

Please sign in to comment.