import { t } from "@lingui/macro"; import { CSSResult, html, TemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import { CryptoApi, CertificateKeyPair } from "@goauthentik/api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; import { PAGE_SIZE } from "../../constants"; import "../../elements/buttons/SpinnerButton"; import "../../elements/forms/DeleteBulkForm"; import "../../elements/forms/ModalForm"; import { TableColumn } from "../../elements/table/Table"; import { TablePage } from "../../elements/table/TablePage"; import "./CertificateGenerateForm"; import "./CertificateKeyPairForm"; @customElement("ak-crypto-certificate-list") export class CertificateKeyPairListPage extends TablePage { expandable = true; checkbox = true; searchEnabled(): boolean { return true; } pageTitle(): string { return t`Certificate-Key Pairs`; } pageDescription(): string { return t`Import certificates of external providers or create certificates to sign requests with.`; } pageIcon(): string { return "pf-icon pf-icon-key"; } @property() order = "name"; static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } apiEndpoint(page: number): Promise> { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsList({ ordering: this.order, page: page, pageSize: PAGE_SIZE, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "name"), new TableColumn(t`Private key available?`), new TableColumn(t`Expiry date`), new TableColumn(t`Actions`), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return [ { key: t`Name`, value: item.name }, { key: t`Expiry`, value: item.certExpiry.toLocaleString() }, ]; }} .usedBy=${(item: CertificateKeyPair) => { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsUsedByList({ kpUuid: item.pk, }); }} .delete=${(item: CertificateKeyPair) => { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsDestroy({ kpUuid: item.pk, }); }} > `; } row(item: CertificateKeyPair): TemplateResult[] { return [ html`${item.name}`, html`${item.privateKeyAvailable ? t`Yes` : t`No`}`, html`${item.certExpiry?.toLocaleString()}`, html` ${t`Update`} ${t`Update Certificate-Key Pair`} `, ]; } renderExpanded(item: CertificateKeyPair): TemplateResult { return html`
${t`Certificate Fingerprint (SHA1)`}
${item.fingerprintSha1}
${t`Certificate Fingerprint (SHA256)`}
${item.fingerprintSha256}
${t`Certificate Subject`}
${item.certSubject}
${t`Download`}
${t`Download Certificate`} ${item.privateKeyAvailable ? html` ${t`Download Private key`} ` : html``}
`; } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create Certificate-Key Pair`} ${t`Generate`} ${t`Generate Certificate-Key Pair`} ${super.renderToolbar()} `; } }