vault/ui/lib/pki/addon/components/page/pki-configuration-edit.ts
claire bontempo ac1cd58504
UI: pki configuration edit form (#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 59fc179b5c.

* revert changes, move model updates back to component

* simplify model fetches

* address comments;

* update pki/urls test

* update adapter test
2023-04-25 21:50:19 +00:00

78 lines
2.3 KiB
TypeScript

/**
* 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;
}
}