import "@goauthentik/admin/crypto/CertificateGenerateForm"; import "@goauthentik/admin/crypto/CertificateKeyPairForm"; import "@goauthentik/admin/rbac/ObjectPermissionModal"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/components/ak-status-label"; import { PFColor } from "@goauthentik/elements/Label"; import "@goauthentik/elements/buttons/SpinnerButton"; import "@goauthentik/elements/forms/DeleteBulkForm"; import "@goauthentik/elements/forms/ModalForm"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { TableColumn } from "@goauthentik/elements/table/Table"; import { TablePage } from "@goauthentik/elements/table/TablePage"; import "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import { msg, str } from "@lit/localize"; 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, RbacPermissionsAssignedByUsersListModelEnum, } from "@goauthentik/api"; @customElement("ak-crypto-certificate-list") export class CertificateKeyPairListPage extends TablePage { expandable = true; checkbox = true; clearOnRefresh = true; searchEnabled(): boolean { return true; } pageTitle(): string { return msg("Certificate-Key Pairs"); } pageDescription(): string { return msg( "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(): Promise> { return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsList( await this.defaultEndpointConfig(), ); } columns(): TableColumn[] { return [ new TableColumn(msg("Name"), "name"), new TableColumn(msg("Private key available?")), new TableColumn(msg("Expiry date")), new TableColumn(msg("Actions")), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return [ { key: msg("Name"), value: item.name }, { key: msg("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 = msg("Managed by authentik"); if (item.managed && item.managed.startsWith("goauthentik.io/crypto/discovered")) { managedSubText = msg("Managed by authentik (Discovered)"); } let color = PFColor.Green; if (item.certExpiry) { const now = new Date(); const inAMonth = new Date(); inAMonth.setDate(inAMonth.getDate() + 30); if (item.certExpiry <= inAMonth) { color = PFColor.Orange; } if (item.certExpiry <= now) { color = PFColor.Red; } } return [ html`
${item.name}
${item.managed ? html`${managedSubText}` : html``}`, html` `, html` ${item.certExpiry?.toLocaleString()} `, html` ${msg("Update")} ${msg("Update Certificate-Key Pair")} `, ]; } renderExpanded(item: CertificateKeyPair): TemplateResult { return html`
${msg("Certificate Fingerprint (SHA1)")}
${item.fingerprintSha1}
${msg("Certificate Fingerprint (SHA256)")}
${item.fingerprintSha256}
${msg("Certificate Subject")}
${item.certSubject}
${msg("Download")}
${msg("Download Certificate")} ${item.privateKeyAvailable ? html` ${msg("Download Private key")} ` : html``}
`; } renderObjectCreate(): TemplateResult { return html` ${msg("Create")} ${msg("Create Certificate-Key Pair")} ${msg("Generate")} ${msg("Generate Certificate-Key Pair")} `; } }