forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: pki configuration edit form (hashicorp#20245)
* setup routing, move queries in ConfigurationIndex to parent resource route * finish building out form, add model attrs build ttls * add types * update model attribute values, fix default ttl states * remove defaults and use openApi, group with booleans * add model to application route" * add save functionality * add error banner * add transition after save * use defaults from open api * fix empty state language * pass engine data * change model attrs to ttl objects * update types * add invalid form alert to error block * move data manipulation to serialize * fix serializer, add comments * add test for serializer * edit configuration details view * update details test * change to updateRecord so POST request is made * config/urls use POST instead of PUT * add edit tests, update details * add model hooks back to routes * rearrange to remove dif * remove createRecord for urls * update comment * wip sample ttl transform * Revert "wip sample ttl transform" This reverts commit 59fc179. * revert changes, move model updates back to component * simplify model fetches * address comments; * update pki/urls test * update adapter test
- Loading branch information
1 parent
445e2e9
commit ac1cd58
Showing
23 changed files
with
786 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
ui/lib/pki/addon/components/page/pki-configuration-edit.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<div class="box is-sideless is-fullwidth is-marginless"> | ||
{{#if this.errorBanner}} | ||
<AlertBanner @type="danger" @message={{this.errorBanner}} data-test-error-banner /> | ||
{{/if}} | ||
<form {{on "submit" (perform this.save)}}> | ||
<fieldset class="box is-shadowless is-marginless is-borderless is-fullwidth" data-test-urls-edit-section> | ||
<h2 class="title is-size-5 has-border-bottom-light page-header"> | ||
Global URLs | ||
</h2> | ||
{{#if @urls.canSet}} | ||
{{#each @urls.allFields as |attr|}} | ||
<FormField @attr={{attr}} @model={{@urls}} @showHelpText={{false}} /> | ||
{{/each}} | ||
{{else}} | ||
<EmptyState | ||
class="is-box-shadowless" | ||
@title="You do not have permission to set URLs" | ||
@message="Ask your administrator if you think you should have access to:" | ||
> | ||
<code>POST /{{@backend}}/config/urls</code> | ||
</EmptyState> | ||
{{/if}} | ||
</fieldset> | ||
|
||
<fieldset class="box is-shadowless is-marginless is-borderless is-fullwidth" data-test-crl-edit-section> | ||
<h2 class="title is-size-5 has-border-bottom-light page-header"> | ||
Certificate Revocation List (CRL) | ||
</h2> | ||
{{#if @crl.canSet}} | ||
{{#each @crl.formFields as |attr|}} | ||
{{#if (eq attr.name "ocspExpiry")}} | ||
<h2 class="title is-size-5 has-border-bottom-light page-header"> | ||
Online Certificate Status Protocol (OCSP) | ||
</h2> | ||
{{/if}} | ||
{{#if (or (includes attr.name this.alwaysRender) (not @crl.disable))}} | ||
{{#let (get @crl attr.options.mapToBoolean) as |booleanValue|}} | ||
<div class="field"> | ||
<TtlPicker | ||
data-test-input={{attr.name}} | ||
@onChange={{fn this.handleTtl attr}} | ||
@label={{attr.options.label}} | ||
@labelDisabled={{attr.options.labelDisabled}} | ||
@helperTextDisabled={{attr.options.helperTextDisabled}} | ||
@helperTextEnabled={{attr.options.helperTextEnabled}} | ||
@initialEnabled={{if attr.options.isOppositeValue (not booleanValue) booleanValue}} | ||
@initialValue={{get @crl attr.name}} | ||
/> | ||
</div> | ||
{{/let}} | ||
{{/if}} | ||
{{/each}} | ||
{{else}} | ||
<EmptyState | ||
class="is-box-shadowless" | ||
@title="You do not have permission to set revocation configuration" | ||
@message="Ask your administrator if you think you should have access to:" | ||
> | ||
<code>POST /{{@backend}}/config/crl</code> | ||
</EmptyState> | ||
{{/if}} | ||
</fieldset> | ||
|
||
<div class="field is-grouped box is-fullwidth is-bottomless"> | ||
<div class="control"> | ||
{{#if (or @urls.canSet @crl.canSet)}} | ||
<button | ||
type="submit" | ||
class="button is-primary {{if this.save.isRunning 'is-loading'}}" | ||
disabled={{this.save.isRunning}} | ||
data-test-configuration-edit-save | ||
> | ||
Save | ||
</button> | ||
{{/if}} | ||
<button | ||
{{on "click" this.cancel}} | ||
type="button" | ||
class="button has-left-margin-s" | ||
disabled={{this.save.isRunning}} | ||
data-test-configuration-edit-cancel | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
{{#if this.invalidFormAlert}} | ||
<div class="control"> | ||
<AlertInline | ||
@type="danger" | ||
@paddingTop={{true}} | ||
@message={{this.invalidFormAlert}} | ||
@mimicRefresh={{true}} | ||
data-test-configuration-edit-validation-alert | ||
/> | ||
</div> | ||
{{/if}} | ||
</div> | ||
</form> | ||
</div> |
77 changes: 77 additions & 0 deletions
77
ui/lib/pki/addon/components/page/pki-configuration-edit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { inject as service } from '@ember/service'; | ||
import { action } from '@ember/object'; | ||
import { task } from 'ember-concurrency'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import RouterService from '@ember/routing/router-service'; | ||
import FlashMessageService from 'vault/services/flash-messages'; | ||
import { FormField, TtlEvent } from 'vault/app-types'; | ||
import PkiCrlModel from 'vault/models/pki/crl'; | ||
import PkiUrlsModel from 'vault/models/pki/urls'; | ||
import errorMessage from 'vault/utils/error-message'; | ||
|
||
interface Args { | ||
crl: PkiCrlModel; | ||
urls: PkiUrlsModel; | ||
} | ||
interface PkiCrlTtls { | ||
autoRebuildGracePeriod: string; | ||
expiry: string; | ||
deltaRebuildInterval: string; | ||
ocspExpiry: string; | ||
} | ||
interface PkiCrlBooleans { | ||
autoRebuild: boolean; | ||
enableDelta: boolean; | ||
disable: boolean; | ||
ocspDisable: boolean; | ||
} | ||
export default class PkiConfigurationEditComponent extends Component<Args> { | ||
@service declare readonly router: RouterService; | ||
@service declare readonly flashMessages: FlashMessageService; | ||
|
||
@tracked invalidFormAlert = ''; | ||
@tracked errorBanner = ''; | ||
|
||
get alwaysRender() { | ||
return ['expiry', 'ocspExpiry']; | ||
} | ||
|
||
@task | ||
@waitFor | ||
*save(event: Event) { | ||
event.preventDefault(); | ||
try { | ||
yield this.args.urls.save(); | ||
yield this.args.crl.save(); | ||
this.flashMessages.success('Successfully updated configuration'); | ||
this.router.transitionTo('vault.cluster.secrets.backend.pki.configuration.index'); | ||
} catch (error) { | ||
this.invalidFormAlert = 'There was an error submitting this form.'; | ||
this.errorBanner = errorMessage(error); | ||
} | ||
} | ||
|
||
@action | ||
cancel() { | ||
this.router.transitionTo('vault.cluster.secrets.backend.pki.configuration.index'); | ||
} | ||
|
||
@action | ||
handleTtl(attr: FormField, e: TtlEvent) { | ||
const { enabled, goSafeTimeString } = e; | ||
const ttlAttr = attr.name; | ||
this.args.crl[ttlAttr as keyof PkiCrlTtls] = goSafeTimeString; | ||
// expiry and ocspExpiry both correspond to 'disable' booleans | ||
// so when ttl is enabled, the booleans are set to false | ||
this.args.crl[attr.options.mapToBoolean as keyof PkiCrlBooleans] = attr.options.isOppositeValue | ||
? !enabled | ||
: enabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.