add alternate entry mode for ssh keys

This commit is contained in:
2024-07-03 16:28:12 -04:00
parent ae93a57aab
commit 10231df860
11 changed files with 71 additions and 11 deletions

View File

@ -9,7 +9,7 @@
// Extra 50ms so the window can finish disappearing before the redraw
const rehideDelay = Math.min(5000, $appState.config.rehide_ms + 50);
const rehideDelay = Math.min(5000, $appState.config.rehide_ms + 100);
let alert;
let success = false;

View File

@ -15,7 +15,6 @@
async function saveCredential() {
await invoke('save_credential', {record: local});
dispatch('save', local);
showDetails = false;
}
async function copyText(evt) {

View File

@ -13,20 +13,23 @@
let name;
let file;
let privateKey = '';
let passphrase = '';
let showDetails = true;
let mode = 'file';
const dispatch = createEventDispatcher();
let defaultPath = null;
homeDir().then(d => defaultPath = `${d}/.ssh`);
let alert;
let saving = false;
async function saveCredential() {
saving = true;
try {
let key = await invoke('sshkey_from_file', {path: file.path, passphrase});
let key = await getKey();
const payload = {
id: record.id,
name,
@ -41,9 +44,40 @@
}
}
async function getKey() {
if (mode === 'file') {
return await invoke('sshkey_from_file', {path: file.path, passphrase});
}
else {
return await invoke('sshkey_from_private_key', {privateKey, passphrase});
}
}
</script>
<div role="tablist" class="join max-w-sm mx-auto flex justify-center">
<button
type="button"
role="tab"
class="join-item flex-1 btn border border-primary"
class:btn-primary={mode === 'file'}
on:click={() => mode = 'file'}
>
From file
</button>
<button
type="button"
role="tab"
class="join-item flex-1 btn border border-primary"
class:btn-primary={mode === 'direct'}
on:click={() => mode = 'direct'}
>
From private key
</button>
</div>
<form class="space-y-4" on:submit|preventDefault={alert.run(saveCredential)}>
<ErrorAlert bind:this={alert} />
@ -55,15 +89,20 @@
bind:value={name}
>
<span class="justify-self-end">File</span>
<FileInput params={{defaultPath}} bind:value={file} on:update={() => name = file.name} />
{#if mode === 'file'}
<span class="justify-self-end">File</span>
<FileInput params={{defaultPath}} bind:value={file} on:update={() => name = file.name} />
{:else}
<span class="justify-self-end">Private key</span>
<textarea bind:value={privateKey} rows="5" class="textarea textarea-bordered bg-transparent font-mono whitespace-pre overflow-x-auto"></textarea>
{/if}
<span class="justify-self-end">Passphrase</span>
<PassphraseInput class="bg-transparent" bind:value={passphrase} />
</div>
<div class="flex justify-end">
{#if file?.path}
{#if file?.path || privateKey !== ''}
<button
transition:fade={{duration: 100}}
type="submit"

View File

@ -64,7 +64,7 @@
{#if record.isNew}
<NewSshKey {record} on:save on:save={handleSave} />
{:else}
<EditSshKey bind:local={local} {isModified} on:save />
<EditSshKey bind:local={local} {isModified} on:save={handleSave} on:save />
{/if}
</div>
{/if}