-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap secrets #5664
Wrap secrets #5664
Changes from 20 commits
62e4133
f867433
6a57da6
8345e5c
46de9c8
a9452b2
1b5f1d8
277f84b
a319610
618f320
d88b340
0d7922a
953424a
df3f893
6111d62
0a4947e
055933f
adc5a01
ad94214
a93c347
a040d28
4b123f0
0feb677
1607e5f
4d64235
30a384d
1925af7
286ac71
a3f254d
ff9ef07
096d536
309bc1a
76ea70d
a82f0c2
5af1563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ export default Component.extend(FocusOnInsertMixin, { | |
wizard: service(), | ||
router: service(), | ||
store: service(), | ||
flashMessages: service(), | ||
|
||
// a key model | ||
key: null, | ||
|
@@ -31,6 +32,10 @@ export default Component.extend(FocusOnInsertMixin, { | |
|
||
secretData: null, | ||
|
||
wrappedData: null, | ||
isWrapping: false, | ||
showWrapButton: true, | ||
|
||
// called with a bool indicating if there's been a change in the secretData | ||
onDataChange() {}, | ||
onRefresh() {}, | ||
|
@@ -235,6 +240,51 @@ export default Component.extend(FocusOnInsertMixin, { | |
set(this.modelForData, 'secretData', this.secretData.toJSON()); | ||
}, | ||
|
||
handleWrapClick() { | ||
this.set('isWrapping', true); | ||
if (this.isV2) { | ||
this.store | ||
.adapterFor('secret-v2-version') | ||
.queryRecord(this.modelForData.id, { wrapTTL: 1800 }) | ||
.then(resp => { | ||
this.set('wrappedData', resp.wrap_info.token); | ||
this.flashMessages.success('Secret Successfully Wrapped!'); | ||
this.set('showWrapButton', false); | ||
this.set('isWrapping', false); | ||
}) | ||
.catch(() => { | ||
this.flashMessages.error('Could Not Wrap Secret'); | ||
}); | ||
} else { | ||
this.store | ||
.adapterFor('secret') | ||
.queryRecord(null, null, { backend: this.model.backend, id: this.modelForData.id, wrapTTL: 1800 }) | ||
.then(resp => { | ||
this.set('wrappedData', resp.wrap_info.token); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this get reset or nulled out somewhere? Just thinking through how/why it doesn't stay through multiple popup openings. |
||
this.flashMessages.success('Secret Successfully Wrapped!'); | ||
this.set('showWrapButton', false); | ||
this.set('isWrapping', false); | ||
}) | ||
.catch(() => { | ||
this.flashMessages.error('Could Not Wrap Secret'); | ||
}); | ||
madalynrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, | ||
|
||
handleCopySuccess() { | ||
this.flashMessages.success('Copied Wrapped Data!'); | ||
this.set('showWrapButton', true); | ||
}, | ||
|
||
handleCopyError() { | ||
this.flashMessages.error('Could Not Copy Wrapped Data'); | ||
this.toggleProperty('showWrapButton', true); | ||
}, | ||
|
||
hideWrappedData() { | ||
this.set('showWrapButton', true); | ||
}, | ||
|
||
createOrUpdateKey(type, event) { | ||
event.preventDefault(); | ||
let model = this.modelForData; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const DEFAULTS = { | |
creation_ttl: null, | ||
data: '{\n}', | ||
unwrap_data: null, | ||
details: null, | ||
wrapTTL: null, | ||
sum: null, | ||
random_bytes: null, | ||
|
@@ -33,6 +34,7 @@ export default Component.extend(DEFAULTS, { | |
algorithm: 'sha2-256', | ||
|
||
tagName: '', | ||
unwrapActiveTab: 'data', | ||
|
||
didReceiveAttrs() { | ||
this._super(...arguments); | ||
|
@@ -76,7 +78,13 @@ export default Component.extend(DEFAULTS, { | |
let props = {}; | ||
let secret = (resp && resp.data) || resp.auth; | ||
if (secret && action === 'unwrap') { | ||
props = assign({}, props, { unwrap_data: secret }); | ||
let details = { | ||
'Request ID': resp.request_id, | ||
'Lease ID': resp.lease_id || 'None', | ||
Renewable: resp.renewable ? 'Yes' : 'No', | ||
'Lease Duration': resp.lease_duration || 'None', | ||
}; | ||
props = assign({}, props, { unwrap_data: secret }, { details: details }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You won't need these changes if we move to reading with |
||
} | ||
props = assign({}, props, secret); | ||
if (resp && resp.wrap_info) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
<ConfirmAction | ||
@buttonClasses="button is-compact is-ghost has-icon-right" | ||
@onConfirmAction={{action "deleteKey"}} | ||
@confirmMessage={{if isV2 | ||
@confirmMessage={{if isV2 | ||
(concat "This will permanently delete " model.id " and all its versions. Are you sure you want to do this?") | ||
(concat "Are you sure you want to delete " model.id "?") | ||
}} | ||
|
@@ -53,43 +53,100 @@ | |
<label for="json" class="has-text-grey">JSON</label> | ||
</div> | ||
{{#if (and (eq mode 'show') (or canEditV2Secret canEdit))}} | ||
<div class="control"> | ||
{{#let (concat 'vault.cluster.secrets.backend.' (if (eq mode 'show') 'edit' 'show')) as |targetRoute|}} | ||
{{#if isV2}} | ||
<LinkTo | ||
@params={{array targetRoute model.id (query-params version=this.modelForData.version)}} | ||
@replace={{true}} | ||
class="link link-plain has-text-weight-semibold" | ||
> | ||
Create new version | ||
</LinkTo> | ||
{{else}} | ||
<LinkTo | ||
@params={{array targetRoute model.id}} | ||
@replace={{true}} | ||
class="link link-plain has-text-weight-semibold" | ||
> | ||
Edit Secret | ||
</LinkTo> | ||
{{/if}} | ||
{{/let}} | ||
</div> | ||
{{#unless (and isV2 (or modelForData.destroyed modelForData.deleted))}} | ||
<div class="control"> | ||
<BasicDropdown | ||
@class="popup-menu" | ||
@horizontalPosition="auto-right" | ||
@verticalPosition="below" | ||
@onClose={{action "hideWrappedData"}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha I see how it's working now. What do you think about this clearing out |
||
as |D| | ||
> | ||
<D.trigger | ||
data-test-popup-menu-trigger="true" | ||
@class={{concat "link link-plain has-text-weight-semibold" (if D.isOpen " is-active")}} | ||
@tagName="button" | ||
> | ||
Copy Secret | ||
</D.trigger> | ||
<D.content @class="popup-menu-content is-wide"> | ||
<nav class="box menu"> | ||
<ul class="menu-list"> | ||
<li class="action"> | ||
<CopyButton | ||
@class="link link-plain has-text-weight-semibold is-ghost" | ||
@clipboardText={{codemirrorString}} | ||
@success={{action (set-flash-message "JSON Copied!")}} | ||
data-test-copy-button | ||
> | ||
Copy JSON | ||
</CopyButton> | ||
</li> | ||
<li class="action"> | ||
{{#if showWrapButton}} | ||
<button | ||
class="link link-plain has-text-weight-semibold is-ghost {{if isWrapping "is-loading"}}" | ||
type="button" | ||
{{action "handleWrapClick"}} | ||
data-test-wrap-button | ||
disabled={{isWrapping}} | ||
> | ||
Wrap Secret | ||
</button> | ||
{{else}} | ||
<MaskedInput | ||
@class="has-padding" | ||
@displayOnly={{true}} | ||
@allowCopy={{true}} | ||
@value={{wrappedData}} | ||
@success={{action "handleCopySuccess"}} | ||
@error={{action "handleCopyError"}} | ||
/> | ||
{{/if}} | ||
</li> | ||
</ul> | ||
</nav> | ||
</D.content> | ||
</BasicDropdown> | ||
</div> | ||
{{/unless}} | ||
<div class="control"> | ||
{{#if isV2}} | ||
<LinkTo | ||
@params={{array targetRoute model.id (query-params version=this.modelForData.version)}} | ||
@replace={{true}} | ||
class="link link-plain has-text-weight-semibold" | ||
> | ||
Create new version | ||
</LinkTo> | ||
{{else}} | ||
<LinkTo | ||
@params={{array targetRoute model.id}} | ||
@replace={{true}} | ||
class="link link-plain has-text-weight-semibold" | ||
> | ||
Edit Secret | ||
</LinkTo> | ||
{{/if}} | ||
</div> | ||
{{/let}} | ||
{{/if}} | ||
{{#if (and (eq @mode "show") this.isV2)}} | ||
<div class="control"> | ||
<SecretVersionMenu @version={{this.modelForData}} /> | ||
</div> | ||
<div class="control"> | ||
<BasicDropdown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes not sure why I had all of this trailing whitespace the first time |
||
@class="popup-menu" | ||
@horizontalPosition="auto-right" | ||
@verticalPosition="below" | ||
<BasicDropdown | ||
@class="popup-menu" | ||
@horizontalPosition="auto-right" | ||
@verticalPosition="below" | ||
as |D| | ||
> | ||
<D.trigger | ||
<D.trigger | ||
data-test-popup-menu-trigger="true" | ||
@class={{concat "popup-menu-trigger button is-ghost has-text-grey" (if D.isOpen " is-active")}} | ||
@tagName="button" | ||
@class={{concat "popup-menu-trigger button is-ghost has-text-grey" (if D.isOpen " is-active")}} | ||
@tagName="button" | ||
> | ||
History <ICon @glyph="chevron-right" @size="11" /> | ||
</D.trigger> | ||
|
@@ -101,8 +158,8 @@ | |
@mode="versions" | ||
@secret={{this.model.id}} | ||
@class="has-text-black has-text-weight-semibold has-bottom-shadow" | ||
> | ||
View version history | ||
> | ||
View version history | ||
</SecretLink> | ||
</li> | ||
</ul> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be done in a
finally
in case the call errors.