Skip to content

Commit

Permalink
Merge pull request #1911 from codefori/fix/auth_order
Browse files Browse the repository at this point in the history
Auth update notices
  • Loading branch information
chrjorgensen authored Mar 23, 2024
2 parents 2c54d18 + d622639 commit ec37969
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 34 deletions.
19 changes: 19 additions & 0 deletions src/locale/ids/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const da: Locale = {
'clearList': `$(trash) Nulstil liste`,
'clearedList': `Nulstillede liste.`,
'currentLibrary': `(aktuelle bibliotek)`,
'current': `aktuelle`,
'duplicate': 'Kopier',
'save': 'Gem',
'delete': 'Slet',
Expand All @@ -38,6 +39,10 @@ export const da: Locale = {
'ask.overwrite':'{0} eksisterer allerede.\nVil du erstatte?',
'skip':'Spring over',
'skip_all':'Spring alle over',
'password': 'Kodeord',
'privateKey': 'Privat nøgle',
'username': 'Brugernavn',
'stored': `gemt`,
// Sandbox:
'sandbox.input.user.title': `Bruger for server`,
'sandbox.input.user.prompt': `Indtast brugernavn for {0}`,
Expand Down Expand Up @@ -77,6 +82,20 @@ export const da: Locale = {
'connectionBrowser.copyConnection.select.custom.variables': `Bruger variable`,
'connectionBrowser.copyConnection.select.command.profiles': `Kommando profiler`,
'connectionBrowser.copyConnection.select.connection.profiles': `Forbindelses profiler`,
// Login page:
'login.title.create': `Forbind til IBM i`,
'login.title.edit': `Login Indstillinger: '{0}'`,
'login.host': `Værtsnavn eller IP adresse`,
'login.port': `Port (SSH)`,
'login.authDecision': `Angiv enten kodeord eller privat nøgle - ikke begge dele.`,
'login.removeAuth': `Fjern kodeord+nøgle`,
'login.authRemoved': `Kodeord og privat nøgle er fjernet for '{0}'.`,
'login.password.label': 'Angiv kun et kodeord hvis du ønsker at ændre det gemte eller oprette et nyt.',
'login.password.updated': `Kodeord er opdateret og bruges for '{0}'.`,
'login.savePassword': `Gem kodeord`,
'login.privateKey.label': `Angiv kun en privat nøgle hvis du ønsker at opdatere den aktuelle eller indstille en ny.`,
'login.privateKey.support': 'OpenSSH, RFC4716 og PPK formater understøttes.',
'login.privateKey.updated': `Privat nøgle er opdateret og bruges for '{0}'.`,
// helpView:
'helpView.getStarted': `Dokumentation`,
'helpView.officialForum': `Forum`,
Expand Down
21 changes: 20 additions & 1 deletion src/locale/ids/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const en: Locale = {
'clearList': `$(trash) Clear list`,
'clearedList': `Cleared list.`,
'currentLibrary': `(current library)`,
'current': `current`,
'duplicate': 'Duplicate',
'save': 'Save',
'delete': 'Delete',
Expand All @@ -38,6 +39,10 @@ export const en: Locale = {
'ask.overwrite':'{0} already exists.\nDo you want to replace it?',
'skip':'Skip',
'skip_all':'Skip all',
'password': 'Password',
'privateKey': 'Private Key',
'username': 'Username',
'stored': `stored`,
// Sandbox:
'sandbox.input.user.title': `User for server`,
'sandbox.input.user.prompt': `Enter username for {0}`,
Expand Down Expand Up @@ -77,6 +82,20 @@ export const en: Locale = {
'connectionBrowser.copyConnection.select.custom.variables': `Custom variables`,
'connectionBrowser.copyConnection.select.command.profiles': `Command profiles`,
'connectionBrowser.copyConnection.select.connection.profiles': `Connection profiles`,
// Login page:
'login.title.create': `Connect to IBM i`,
'login.title.edit': `Login Settings: '{0}'`,
'login.host': `Host or IP Address`,
'login.port': `Port (SSH)`,
'login.authDecision': `Only provide either the password or a private key - not both.`,
'login.removeAuth': `Remove auth methods`,
'login.authRemoved': `Authentication methods removed for '{0}'.`,
'login.password.label': 'Only provide a password if you want to update an existing one or set a new one.',
'login.password.updated': `Password updated and will be used for '{0}'.`,
'login.savePassword': `Save Password`,
'login.privateKey.label': `Only provide a private key if you want to update from the existing one or set one.`,
'login.privateKey.support': 'OpenSSH, RFC4716 and PPK formats are supported.',
'login.privateKey.updated': `Private key updated and will be used for '{0}'.`,
// helpView:
'helpView.getStarted': `Get started`,
'helpView.officialForum': `Open official Forum`,
Expand Down Expand Up @@ -131,7 +150,7 @@ export const en: Locale = {
'ifsBrowser.searchIFS.placeholder': `Enter search term or select one of the previous search terms.`,
'ifsBrowser.searchIFS.placeholder2': `Enter search term.`,
'ifsBrowser.searchIFS.noGrep': `grep must be installed on the remote system for the IFS search.`,
'ifsBrowser.downloadStreamfile.downloading':'Downloading',
'ifsBrowser.downloadStreamfile.downloading':'Downloading',
'ifsBrowser.downloadStreamfile.complete': `Download complete`,
'ifsBrowser.downloadStreamfile.errorMessage': `Error downloading file(s): {0}`,
'ifsBrowser.getChildren.errorMessage': `Error loading objects.`,
Expand Down
19 changes: 19 additions & 0 deletions src/locale/ids/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const fr: Locale = {
'clearList': `$(trash) Effacer liste`,
'clearedList': `Liste effacée.`,
'currentLibrary': `(bibliothèque en cours)`,
'current': `actuelle`,
'duplicate': 'Dupliquer',
'save': 'Enregistrer',
'delete': 'Supprimer',
Expand All @@ -38,6 +39,10 @@ export const fr: Locale = {
'ask.overwrite':'{0} existe déjà.\nVoulez-vous le remplacer?',
'skip':'Ignorer',
'skip_all':'Ignorer tout',
'password': 'Mot de passe',
'privateKey': 'Clé privée',
'username': 'Utilisateur',
'stored': `enregistré`,
// Sandbox:
'sandbox.input.user.title': `Nom d'utilisateur`,
'sandbox.input.user.prompt': `Entrez le nom d'utilisateur pour {0}`,
Expand Down Expand Up @@ -77,6 +82,20 @@ export const fr: Locale = {
'connectionBrowser.copyConnection.select.custom.variables': `Variables personnalisées`,
'connectionBrowser.copyConnection.select.command.profiles': `Profiles de commande`,
'connectionBrowser.copyConnection.select.connection.profiles': `Profile de connection`,
// Login page:
'login.title.create': `Connect to IBM i`,
'login.title.edit': `paramètres d'authentification: '{0}'`,
'login.host': `Nom d'Hôte ou Adresse IP`,
'login.port': `Port (SSH)`,
'login.authDecision': `Renseignez soit le mot de passe, soit la clé privée - pas les deux.`,
'login.removeAuth': `Supprimer l'authentification`,
'login.authRemoved': `Authentification supprimée pour '{0}'.`,
'login.password.label': 'Rensignez un mot de passe seulement si vous souhaitez le changer.',
'login.password.updated': `Mot de passe mis à jour et utilisé pour se connecter à '{0}'.`,
'login.savePassword': `Sauvegarder Mot de passe`,
'login.privateKey.label': `Sélectionnez une clé privée seulement si vous souhaitez en changer.`,
'login.privateKey.support': 'Les formats OpenSSH, RFC4716 et PPK sont supportés.',
'login.privateKey.updated': `Clé privée mise à jour et utilisée pour se connecter à '{0}'.`,
// helpView:
'helpView.getStarted': `Pour commencer`,
'helpView.officialForum': `Forum officiel`,
Expand Down
15 changes: 8 additions & 7 deletions src/webviews/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CustomUI, Section } from "../../api/CustomUI";
import IBMi from "../../api/IBMi";
import { disconnect, instance } from "../../instantiate";
import { ConnectionData } from '../../typings';
import { t } from "../../locale";

type NewLoginSettings = ConnectionData & {
savePassword: boolean
Expand All @@ -28,13 +29,13 @@ export class Login {

const connectionTab = new Section()
.addInput(`name`, `Connection Name`, undefined, { minlength: 1 })
.addInput(`host`, `Host or IP Address`, undefined, { minlength: 1 })
.addInput(`port`, `Port (SSH)`, ``, { default: `22`, minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
.addInput(`username`, `Username`, undefined, { minlength: 1, maxlength: 10 })
.addParagraph(`Only provide either the password or a private key - not both.`)
.addPassword(`password`, `Password`)
.addCheckbox(`savePassword`, `Save Password`)
.addFile(`privateKeyPath`, `Private Key`, `OpenSSH, RFC4716, or PPK formats are supported.`);
.addInput(`host`, t(`login.host`), undefined, { minlength: 1 })
.addInput(`port`, t(`login.port`), ``, { default: `22`, minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
.addInput(`username`, t(`username`), undefined, { minlength: 1, maxlength: 10 })
.addParagraph(t(`login.authDecision`))
.addPassword(`password`, t(`password`))
.addCheckbox(`savePassword`, t(`login.savePassword`))
.addFile(`privateKeyPath`, t(`privateKey`), t(`login.privateKey.support`));

const tempTab = new Section()
.addInput(`tempLibrary`, `Temporary library`, `Temporary library. Cannot be QTEMP.`, { default: `ILEDITOR`, minlength: 1, maxlength: 10 })
Expand Down
86 changes: 60 additions & 26 deletions src/webviews/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isManaged } from "../../api/debug";
import * as certificates from "../../api/debug/certificates";
import { instance } from "../../instantiate";
import { ConnectionData, Server } from '../../typings';
import { t } from "../../locale";

const ENCODINGS = [`37`, `256`, `273`, `277`, `278`, `280`, `284`, `285`, `297`, `500`, `871`, `870`, `905`, `880`, `420`, `875`, `424`, `1026`, `290`, `win37`, `win256`, `win273`, `win277`, `win278`, `win280`, `win284`, `win285`, `win297`, `win500`, `win871`, `win870`, `win905`, `win880`, `win420`, `win875`, `win424`, `win1026`];

Expand Down Expand Up @@ -311,44 +312,77 @@ export class SettingsUI {
if (connections) {
const connectionIdx = connections.findIndex(item => item.name === name);
let connection = connections[connectionIdx];
const storedPassword = await context.secrets.get(`${name}_password`);

const page = await new CustomUI()
.addInput(`host`, `Host or IP Address`, undefined, { default: connection.host, minlength: 1 })
.addInput(`port`, `Port (SSH)`, undefined, { default: String(connection.port), minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
.addInput(`username`, `Username`, undefined, { default: connection.username, minlength: 1 })
.addParagraph(`Only provide either the password or a private key - not both.`)
.addPassword(`password`, `Password`, `Only provide a password if you want to update an existing one or set a new one.`)
.addFile(`privateKeyPath`, `Private Key${connection.privateKeyPath ? ` (current: ${connection.privateKeyPath})` : ``}`, `Only provide a private key if you want to update from the existing one or set one. OpenSSH, RFC4716, or PPK formats are supported.`)
.addButtons({ id: `submitButton`, label: `Save`, requiresValidation: true })
.loadPage<LoginSettings>(`Login Settings: ${name}`);
.addInput(`host`, t(`login.host`), undefined, { default: connection.host, minlength: 1 })
.addInput(`port`, t(`login.port`), undefined, { default: String(connection.port), minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
.addInput(`username`, t(`username`), undefined, { default: connection.username, minlength: 1 })
.addParagraph(t(`login.authDecision`))
.addPassword(`password`, `${t(`password`)}${storedPassword ? ` (${t(`stored`)})` : ``}`, t(`login.password.label`))
.addFile(`privateKeyPath`, `${t(`privateKey`)}${connection.privateKeyPath ? ` (${t(`current`)}: ${connection.privateKeyPath})` : ``}`, t(`login.privateKey.label`) + ' ' + t(`login.privateKey.support`))
.addButtons(
{ id: `submitButton`, label: t(`save`), requiresValidation: true },
{ id: `removeAuth`, label: t(`login.removeAuth`) }
)
.loadPage<LoginSettings>(t(`login.title.edit`, name));

if (page && page.data) {
page.panel.dispose();

const data = page.data;
if (!data.privateKeyPath?.trim()) {
if (connection.privateKeyPath?.trim()) {
data.privateKeyPath = connection.privateKeyPath;

let doUpdate = false;

const chosenButton = data.buttons as "submitButton" | "removeAuth";

switch (chosenButton) {
case `submitButton`:
if (data.password) {
// New password was entered, so store the password
// and remove the private key path from the data
await context.secrets.store(`${name}_password`, `${data.password}`);
data.privateKeyPath = undefined;

vscode.window.showInformationMessage(t(`login.password.updated`, name));

doUpdate = true;

} else {
// If no password was entered, but a keypath exists
// then remove the password from the data and
// use the keypath instead
if (data.privateKeyPath?.trim()) {
await context.secrets.delete(`${name}_password`);

vscode.window.showInformationMessage(t(`login.privateKey.updated`, name));

doUpdate = true;
}
}
break;

case `removeAuth`:
await context.secrets.delete(`${name}_password`);
}
else {
delete data.privateKeyPath;
}
}
data.password = undefined;
data.privateKeyPath = undefined;

vscode.window.showInformationMessage(t(`login.authRemoved`, name));

if (data.password && !data.privateKeyPath) {
await context.secrets.delete(`${name}_password`);
await context.secrets.store(`${name}_password`, `${data.password}`);
delete data.privateKeyPath;
doUpdate = true;
break;
}

//Fix values before assigning the data
data.port = Number(data.port);
delete data.password;
delete data.buttons;

connections[connectionIdx] = Object.assign(connection, data);
await GlobalConfiguration.set(`connections`, connections);
if (doUpdate) {
//Fix values before assigning the data
data.port = Number(data.port);
delete data.password;
delete data.buttons;

connections[connectionIdx] = Object.assign(connection, data);
await GlobalConfiguration.set(`connections`, connections);
}
}
}
}
Expand Down

0 comments on commit ec37969

Please sign in to comment.