Skip to content

Commit

Permalink
Add show secret functionality to vault
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibren van Setten committed Aug 30, 2023
1 parent dc9a7d8 commit 8bc2375
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tabby-settings/src/components/showSecretModal.component.pug
@@ -0,0 +1,15 @@
h4.modal-header.m-0.pb-0 {{title}}
.modal-body
.input-group.w-100
input.form-control(
type='text',
[(ngModel)]='secret.value',
disabled
)
button.btn.btn-secondary(
(click)='copySecret()'
)
i.fas.fa-copy

.modal-footer
button.btn.btn-primary((click)='close()', translate) Close
27 changes: 27 additions & 0 deletions tabby-settings/src/components/showSecretModal.component.ts
@@ -0,0 +1,27 @@
import { Component, Input } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import {NotificationsService, VaultFileSecret} from "tabby-core";

Check failure on line 3 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 3 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'

Check failure on line 3 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 3 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon

/** @hidden */
@Component({
templateUrl: './showSecretModal.component.pug',
})
export class ShowSecretModalComponent {
@Input() title: String

Check failure on line 10 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Don't use `String` as a type. Use string instead
@Input() secret: VaultFileSecret

constructor (
public modalInstance: NgbActiveModal,
private notifications: NotificationsService

Check failure on line 15 in tabby-settings/src/components/showSecretModal.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing trailing comma
) { }

close (): void {
this.modalInstance.dismiss()
}

copySecret (): void {
navigator.clipboard.writeText(this.secret.value)
// Show a notification
this.notifications.info('Copied to clipboard')
}
}
3 changes: 3 additions & 0 deletions tabby-settings/src/components/vaultSettingsTab.component.pug
Expand Up @@ -32,6 +32,9 @@ div(*ngIf='vault.isEnabled()')
button.btn.btn-link(ngbDropdownToggle)
i.fas.fa-ellipsis-v
div(ngbDropdownMenu)
button(ngbDropdownItem, (click)='showSecret(secret)')
i.fas.fa-fw.fa-eye
span(translate) Show
button(
ngbDropdownItem,
*ngIf='secret.type === VAULT_SECRET_TYPE_FILE',
Expand Down
11 changes: 11 additions & 0 deletions tabby-settings/src/components/vaultSettingsTab.component.ts
Expand Up @@ -3,6 +3,7 @@ import { Component, HostBinding } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { BaseComponent, VaultService, VaultSecret, Vault, PlatformService, ConfigService, VAULT_SECRET_TYPE_FILE, PromptModalComponent, VaultFileSecret, TranslateService } from 'tabby-core'
import { SetVaultPassphraseModalComponent } from './setVaultPassphraseModal.component'
import {ShowSecretModalComponent} from "./showSecretModal.component";

Check failure on line 6 in tabby-settings/src/components/vaultSettingsTab.component.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 6 in tabby-settings/src/components/vaultSettingsTab.component.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'

Check failure on line 6 in tabby-settings/src/components/vaultSettingsTab.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 6 in tabby-settings/src/components/vaultSettingsTab.component.ts

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon


/** @hidden */
Expand Down Expand Up @@ -97,6 +98,16 @@ export class VaultSettingsTabComponent extends BaseComponent {
return this.translate.instant('Unknown secret of type {type} for {key}', { type: secret.type, key: JSON.stringify(secret.key) })
}

showSecret (secret: VaultSecret) {
if (!this.vaultContents) {
return
}
const modal = this.ngbModal.open(ShowSecretModalComponent)
modal.componentInstance.title = this.getSecretLabel(secret)
modal.componentInstance.secret = secret

}

removeSecret (secret: VaultSecret) {
if (!this.vaultContents) {
return
Expand Down
2 changes: 2 additions & 0 deletions tabby-settings/src/index.ts
Expand Up @@ -19,6 +19,7 @@ import { SetVaultPassphraseModalComponent } from './components/setVaultPassphras
import { ProfilesSettingsTabComponent } from './components/profilesSettingsTab.component'
import { ReleaseNotesComponent } from './components/releaseNotesTab.component'
import { ConfigSyncSettingsTabComponent } from './components/configSyncSettingsTab.component'
import { ShowSecretModalComponent } from "./components/showSecretModal.component";

import { ConfigSyncService } from './services/configSync.service'

Expand Down Expand Up @@ -61,6 +62,7 @@ import { HotkeySettingsTabProvider, WindowSettingsTabProvider, VaultSettingsTabP
WindowSettingsTabComponent,
ConfigSyncSettingsTabComponent,
ReleaseNotesComponent,
ShowSecretModalComponent,
],
})
export default class SettingsModule {
Expand Down

0 comments on commit 8bc2375

Please sign in to comment.