Skip to content

Commit

Permalink
Display a warning when the private key doesn't exixt locally
Browse files Browse the repository at this point in the history
Signed-off-by: Seb Julliand <[email protected]>
  • Loading branch information
sebjulliand committed Dec 2, 2024
1 parent 9e6cf5d commit 1490cab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/webviews/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from "fs";
import vscode from "vscode";
import { ConnectionConfiguration, ConnectionManager, GlobalConfiguration } from "../../api/Configuration";
import { ComplexTab, CustomUI, Section } from "../../api/CustomUI";
Expand Down Expand Up @@ -352,14 +353,15 @@ export class SettingsUI {
if (connection) {
const storedPassword = await ConnectionManager.getStoredPassword(context, name);
let { data: stored, index } = connection;

const privateKeyPath = stored.privateKeyPath ? Tools.resolvePath(stored.privateKeyPath) : undefined;
const privateKeyWarning = !privateKeyPath || existsSync(privateKeyPath) ? "" : "<b>⚠️ This private key doesn't exist on this system! ⚠️</b></br></br>";
const ui = new CustomUI()
.addInput(`host`, vscode.l10n.t(`Host or IP Address`), undefined, { default: stored.host, minlength: 1 })
.addInput(`port`, vscode.l10n.t(`Port (SSH)`), undefined, { default: String(stored.port), minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
.addInput(`username`, vscode.l10n.t(`Username`), undefined, { default: stored.username, minlength: 1 })
.addParagraph(vscode.l10n.t(`Only provide either the password or a private key - not both.`))
.addPassword(`password`, `${vscode.l10n.t(`Password`)}${storedPassword ? ` (${vscode.l10n.t(`stored`)})` : ``}`, vscode.l10n.t("Only provide a password if you want to update an existing one or set a new one."))
.addFile(`privateKeyPath`, `${vscode.l10n.t(`Private Key`)}${stored.privateKeyPath ? ` (${vscode.l10n.t(`Private Key`)}: ${Tools.resolvePath(stored.privateKeyPath)})` : ``}`, vscode.l10n.t("Only provide a private key if you want to update from the existing one or set one.") + '<br />' + vscode.l10n.t("OpenSSH, RFC4716 and PPK formats are supported."))
.addFile(`privateKeyPath`, `${vscode.l10n.t(`Private Key`)}${privateKeyPath ? ` (${vscode.l10n.t(`Private Key`)}: ${privateKeyPath})` : ``}`, privateKeyWarning + vscode.l10n.t("Only provide a private key if you want to update from the existing one or set one.") + '<br />' + vscode.l10n.t("OpenSSH, RFC4716 and PPK formats are supported."))
.addButtons(
{ id: `submitButton`, label: vscode.l10n.t(`Save`), requiresValidation: true },
{ id: `removeAuth`, label: vscode.l10n.t(`Remove auth methods`) }
Expand Down

0 comments on commit 1490cab

Please sign in to comment.