Files
vault/ui/lib/pki/addon/components/page/pki-configuration-edit.ts
claire bontempo 5e5e61b5a8 UI: add pki cluster config parameters (#20724)
* add config directory, rename crl and urls models

* fix imports

* add cluster config fields to edit form

* reorder url save

* update tests

* add to details page

* add details test;

* fix adapter name

* fix cluster adapter test name

* combine adapter tests

* update imports

* fix git diff

* move crl and urls adapters to config folder

* add config file

* woops add config adapter

* final renaming!!

* fix imports after naming to base

* add cluster to beforeModel hook

* hide help text

* maybe you should write tests that actually pass, claire

* seriously claire its embarrassing
2023-05-23 15:24:53 -07:00

80 lines
2.5 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 errorMessage from 'vault/utils/error-message';
import type RouterService from '@ember/routing/router-service';
import type FlashMessageService from 'vault/services/flash-messages';
import type VersionService from 'vault/services/version';
import type PkiConfigCrlModel from 'vault/models/pki/config/crl';
import type PkiConfigUrlsModel from 'vault/models/pki/config/urls';
import type { FormField, TtlEvent } from 'vault/app-types';
interface Args {
crl: PkiConfigCrlModel;
urls: PkiConfigUrlsModel;
}
interface PkiConfigCrlTtls {
autoRebuildGracePeriod: string;
expiry: string;
deltaRebuildInterval: string;
ocspExpiry: string;
}
interface PkiConfigCrlBooleans {
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;
@service declare readonly version: VersionService;
@tracked invalidFormAlert = '';
@tracked errorBanner = '';
get isEnterprise() {
return this.version.isEnterprise;
}
@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 PkiConfigCrlTtls] = 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 PkiConfigCrlBooleans] = attr.options.isOppositeValue
? !enabled
: enabled;
}
}