import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import { CertificateKeyPair, CryptoApi } from "@goauthentik/api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; import { uiConfig } from "../../common/config"; import { PFColor } from "../../elements/Label"; 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); } async apiEndpoint(page: number): Promise> { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, 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[] { let managedSubText = t`Managed by authentik`; if (item.managed && item.managed.startsWith("goauthentik.io/crypto/discovered")) { managedSubText = t`Managed by authentik (Discovered)`; } return [ html`
${item.name}
${item.managed ? html`${managedSubText}` : html``}`, html` ${item.privateKeyAvailable ? t`Yes (${item.privateKeyType?.toUpperCase()})` : t`No`} `, html` new Date() ? PFColor.Green : PFColor.Orange}> ${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``}
`; } renderObjectCreate(): TemplateResult { return html` ${t`Create`} ${t`Create Certificate-Key Pair`} ${t`Generate`} ${t`Generate Certificate-Key Pair`} `; } }