allow renaming and replacing files in the vault - fixes #4110

This commit is contained in:
Eugene Pankov
2021-07-10 21:31:18 +02:00
parent 0008b2f022
commit 67bbbd7f65
6 changed files with 109 additions and 8 deletions

View File

@@ -27,8 +27,35 @@ div(*ngIf='vault.isEnabled()')
.list-group-item.d-flex.align-items-center.p-1.pl-3(*ngFor='let secret of vaultContents.secrets')
i.fas.fa-key
.mr-auto {{getSecretLabel(secret)}}
button.btn.btn-link((click)='removeSecret(secret)')
i.fas.fa-trash
.hover-reveal(ngbDropdown)
button.btn.btn-link(ngbDropdownToggle)
i.fas.fa-ellipsis-v
div(ngbDropdownMenu)
button(
ngbDropdownItem,
*ngIf='secret.type === VAULT_SECRET_TYPE_FILE',
(click)='renameFile(secret)'
)
i.fas.fa-fw.fa-pencil-alt
span Rename
button(
ngbDropdownItem,
*ngIf='secret.type === VAULT_SECRET_TYPE_FILE',
(click)='replaceFileContent(secret)'
)
i.fas.fa-fw.fa-file-import
span Replace
button(
ngbDropdownItem,
*ngIf='secret.type === VAULT_SECRET_TYPE_FILE',
(click)='exportFile(secret)'
)
i.fas.fa-fw.fa-file-export
span Export
button(ngbDropdownItem, (click)='removeSecret(secret)')
i.fas.fa-fw.fa-trash
span Delete
h3.mt-5 Options
.form-line

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { BaseComponent, VaultService, VaultSecret, Vault, PlatformService, ConfigService, VAULT_SECRET_TYPE_FILE } from 'tabby-core'
import { BaseComponent, VaultService, VaultSecret, Vault, PlatformService, ConfigService, VAULT_SECRET_TYPE_FILE, PromptModalComponent, VaultFileSecret } from 'tabby-core'
import { SetVaultPassphraseModalComponent } from './setVaultPassphraseModal.component'
@@ -12,6 +12,7 @@ import { SetVaultPassphraseModalComponent } from './setVaultPassphraseModal.comp
})
export class VaultSettingsTabComponent extends BaseComponent {
vaultContents: Vault|null = null
VAULT_SECRET_TYPE_FILE = VAULT_SECRET_TYPE_FILE
constructor (
public vault: VaultService,
@@ -91,4 +92,51 @@ export class VaultSettingsTabComponent extends BaseComponent {
this.vaultContents.secrets = this.vaultContents.secrets.filter(x => x !== secret)
this.vault.removeSecret(secret.type, secret.key)
}
async replaceFileContent (secret: VaultFileSecret) {
const transfers = await this.platform.startUpload()
if (!transfers.length) {
return
}
await this.vault.updateSecret(secret, {
...secret,
value: (await transfers[0].readAll()).toString('base64'),
})
this.loadVault()
}
async renameFile (secret: VaultFileSecret) {
const modal = this.ngbModal.open(PromptModalComponent)
modal.componentInstance.prompt = 'New name'
modal.componentInstance.value = secret.key.description
const description = (await modal.result)?.value
if (!description) {
return
}
await this.vault.updateSecret(secret, {
...secret,
key: {
...secret.key,
description,
},
})
this.loadVault()
}
async exportFile (secret: VaultFileSecret) {
this.vault.forgetPassphrase()
secret = (await this.vault.getSecret(secret.type, secret.key)) as VaultFileSecret
const content = Buffer.from(secret.value, 'base64')
const download = await this.platform.startDownload(secret.key.description, 0o600, content.length)
if (download) {
await download.write(content)
download.close()
}
}
}