Files
vault/ui/lib/core/addon/components/masked-input.hbs
claire bontempo 88ed074287 UI: add warning before downloading secret data (#23260)
* add confirm modal for downloading masked data

* close modal if user clicks download

* add changelog;

* pass onSuccess function instead

* only render modal on DOM if download is allowed
2023-09-22 20:19:38 +00:00

91 lines
2.6 KiB
Handlebars

{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
~}}
<div
class="masked-input {{if @displayOnly 'display-only'}} {{if @allowCopy 'allow-copy'}}"
data-test-masked-input
data-test-field
...attributes
>
{{#if @displayOnly}}
{{#if this.showValue}}
{{! Show minus icon if there is no value }}
{{#if (eq @value "")}}
<Icon class="masked-value" @name="minus" />
{{else}}
<pre class="masked-value display-only is-word-break">{{@value}}</pre>
{{/if}}
{{else}}
<pre class="masked-value display-only masked-font">***********</pre>
{{/if}}
{{else}}
<Textarea
id={{this.textareaId}}
name={{@name}}
@value={{@value}}
class="input masked-value {{unless this.showValue 'masked-font'}}"
rows={{1}}
wrap="off"
spellcheck="false"
{{on "change" this.onChange}}
{{on "keyup" (fn this.handleKeyUp @name)}}
data-test-textarea
/>
{{/if}}
{{#if @allowCopy}}
<Hds::Copy::Button
@text="Copy"
@isIconOnly={{true}}
@textToCopy={{@value}}
class="transparent icon-only is-paddingless"
data-test-copy-button
/>
{{/if}}
{{#if @allowDownload}}
<button type="button" class="button download-button" {{on "click" (fn (mut this.modalOpen) true)}}>
<Icon data-test-download-icon @name="download" />
</button>
{{/if}}
<button
onclick={{this.toggleMask}}
type="button"
aria-label={{if this.showValue "mask value" "show value"}}
title={{if this.showValue "mask value" "show value"}}
class="masked-input-toggle button"
data-test-button="toggle-masked"
>
<Icon @name={{if this.showValue "eye" "eye-off"}} />
</button>
</div>
{{! CONFIRM DOWNLOAD MODAL }}
{{#if @allowDownload}}
<Modal
@title="Download secret value?"
@onClose={{action (mut this.modalOpen) false}}
@isActive={{this.modalOpen}}
@type="warning"
>
<section class="modal-card-body">
This download is
<strong>unencrypted</strong>. Are you sure you want to download this secret data as plaintext?
</section>
<footer class="modal-card-foot modal-card-foot-outlined">
<DownloadButton
class="button is-primary"
@filename={{or @name "secret-value"}}
@data={{@value}}
@stringify={{true}}
aria-label="Download secret value"
@onSuccess={{fn (mut this.modalOpen) false}}
>
Download
</DownloadButton>
<button type="button" class="button is-secondary" {{on "click" (fn (mut this.modalOpen) false)}}>
Cancel
</button>
</footer>
</Modal>
{{/if}}