vault/ui/lib/pki/addon/components/page/pki-tidy-status.ts
claire bontempo ec6a1f2934
UI: pki auto-tidy views (#20685)
* UI: plumbing for pki tidy work (#20611)

* update tidy model

* Dynamic group on tidy based on version

* UI: VAULT-16261 PKI autotidy config view (#20641)

* UI: VAULT-16203 tidy status page (#20635)

* ui: pki tidy form (#20630)

* order routes to match tabs

* add tidy routes

* add tidy-status page component

* update routes rename edit to configure, remove manage

* add page component to route template

* add comment

* finish routing

* change to queryRecord, delete old tidy file

* remove findRecord

* fix serializer name

* tidy.index only needs controller empty state logic

* build form and page components

* update tidy model

* alphabetize!

* revert model changes

* finish adapter

* move form out of page folder in tests

* refactor to accommodate model changes from chelseas pr

* WIP tests

* reuse shared fields in model

* finish tests

* update model hook and breadcrumbs

* remove subtext for checkbox

* fix tests add ACME fields

* Update ui/app/adapters/pki/tidy.js

* Update ui/app/adapters/pki/tidy.js

* refactor intervalDuration using feedback suggested

* move errors to second line, inside conditional brackets

* add ternary operator to allByKey attr

* surface error message

* make polling request longer

* UI: VAULT-16368 pki tidy custom method (#20696)

* ui: adds empty state and updates modal (#20695)

* add empty state to status page

* update tidy modal

* conditionally change cancel transition route for auto tidy form

* teeny copy update

* organize tidy-status conditoionals

* a couple more template cleanups

* fix conditional, change to settings

* UI: VAULT-16367 VAULT-16378 Tidy acceptance tests + tidy toolbar cleanup (#20698)

* update copy

* move tidyRevokedCertIssuerAssociations up to applicable section

* add tidy info to readme

* update copy

* UI: Add tidy as a tab to the error route (#20723)

* small cleanup items

* fix prettier

* cancel polling when we leave tidy.index (status view)

* revert changes to declaration file

* remove space

---------

Co-authored-by: Chelsea Shaw <cshaw@hashicorp.com>
Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
2023-05-23 23:05:15 +00:00

158 lines
4.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 { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import errorMessage from 'vault/utils/error-message';
import type Store from '@ember-data/store';
import type SecretMountPath from 'vault/services/secret-mount-path';
import type FlashMessageService from 'vault/services/flash-messages';
import type VersionService from 'vault/services/version';
import type PkiTidyModel from 'vault/models/pki/tidy';
import type RouterService from '@ember/routing/router-service';
interface Args {
autoTidyConfig: PkiTidyModel;
tidyStatus: TidyStatusParams;
}
interface TidyStatusParams {
safety_buffer: number;
tidy_cert_store: boolean;
tidy_revoked_certs: boolean;
state: string;
error: string;
time_started: string | null;
time_finished: string | null;
message: string;
cert_store_deleted_count: number;
revoked_cert_deleted_count: number;
missing_issuer_cert_count: number;
tidy_expired_issuers: boolean;
issuer_safety_buffer: string;
tidy_move_legacy_ca_bundle: boolean;
tidy_revocation_queue: boolean;
revocation_queue_deleted_count: number;
tidy_cross_cluster_revoked_certs: boolean;
cross_revoked_cert_deleted_count: number;
revocation_queue_safety_buffer: string;
}
export default class PkiTidyStatusComponent extends Component<Args> {
@service declare readonly store: Store;
@service declare readonly secretMountPath: SecretMountPath;
@service declare readonly flashMessages: FlashMessageService;
@service declare readonly version: VersionService;
@service declare readonly router: RouterService;
@tracked tidyOptionsModal = false;
@tracked confirmCancelTidy = false;
tidyStatusGeneralFields = [
'time_started',
'time_finished',
'last_auto_tidy_finished',
'cert_store_deleted_count',
'missing_issuer_cert_count',
'revocation_queue_deleted_count',
];
tidyStatusConfigFields = [
'tidy_cert_store',
'tidy_revocation_queue',
'tidy_cross_cluster_revoked_certs',
'safety_buffer',
'pause_duration',
'tidy_expired_issuers',
'tidy_move_legacy_ca_bundle',
'issuer_safety_buffer',
];
crossClusterOperation = ['tidy_revocation_queue', 'revocation_queue_safety_buffer'];
get isEnterprise() {
return this.version.isEnterprise;
}
get tidyState() {
return this.args.tidyStatus?.state;
}
get hasTidyConfig() {
return !this.tidyStatusConfigFields.every(
(attr) => this.args.tidyStatus[attr as keyof TidyStatusParams] === null
);
}
get tidyStateAlertBanner() {
const tidyState = this.tidyState;
switch (tidyState) {
case 'Inactive':
return {
color: 'highlight',
title: 'Tidy is inactive',
message: this.args.tidyStatus?.message,
};
case 'Running':
return {
color: 'highlight',
title: 'Tidy in progress',
message: this.args.tidyStatus?.message,
shouldShowCancelTidy: true,
};
case 'Finished':
return {
color: 'success',
title: 'Tidy operation finished',
message: this.args.tidyStatus?.message,
};
case 'Error':
return {
color: 'warning',
title: 'Tidy operation failed',
message: this.args.tidyStatus?.error,
};
case 'Cancelling':
return {
color: 'warning',
title: 'Tidy operation cancelling',
icon: 'loading',
};
case 'Cancelled':
return {
color: 'warning',
title: 'Tidy operation cancelled',
message:
'Your tidy operation has been cancelled. If this was a mistake configure and run another tidy operation.',
};
default:
return {
color: 'warning',
title: 'Tidy status not found',
message: "The system reported no tidy status. It's recommended to perform a new tidy operation.",
};
}
}
@task
@waitFor
*cancelTidy() {
try {
const tidyAdapter = this.store.adapterFor('pki/tidy');
yield tidyAdapter.cancelTidy(this.secretMountPath.currentPath);
this.router.transitionTo('vault.cluster.secrets.backend.pki.tidy');
} catch (error) {
this.flashMessages.danger(errorMessage(error));
} finally {
this.confirmCancelTidy = false;
}
}
}