import "@goauthentik/admin/blueprints/BlueprintForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { uiConfig } from "@goauthentik/common/ui/config"; import { PFColor } from "@goauthentik/elements/Label"; import "@goauthentik/elements/buttons/ActionButton"; 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 } 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 { BlueprintInstance, BlueprintInstanceStatusEnum, ManagedApi } from "@goauthentik/api"; export function BlueprintStatus(blueprint?: BlueprintInstance): string { if (!blueprint) return ""; switch (blueprint.status) { case BlueprintInstanceStatusEnum.Successful: return msg("Successful"); case BlueprintInstanceStatusEnum.Orphaned: return msg("Orphaned"); case BlueprintInstanceStatusEnum.Warning: return msg("Warning"); case BlueprintInstanceStatusEnum.Error: return msg("Error"); } return msg("Unknown"); } @customElement("ak-blueprint-list") export class BlueprintListPage extends TablePage { searchEnabled(): boolean { return true; } pageTitle(): string { return msg("Blueprints"); } pageDescription(): string { return msg("Automate and template configuration within authentik."); } pageIcon(): string { return "pf-icon pf-icon-blueprint"; } expandable = true; checkbox = true; @property() order = "name"; static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } async apiEndpoint(page: number): Promise> { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(msg("Name"), "name"), new TableColumn(msg("Status"), "status"), new TableColumn(msg("Last applied"), "last_applied"), new TableColumn(msg("Enabled"), "enabled"), new TableColumn(msg("Actions")), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return [{ key: msg("Name"), value: item.name }]; }} .usedBy=${(item: BlueprintInstance) => { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsUsedByList({ instanceUuid: item.pk, }); }} .delete=${(item: BlueprintInstance) => { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsDestroy({ instanceUuid: item.pk, }); }} > `; } renderExpanded(item: BlueprintInstance): TemplateResult { return html`
${msg("Path")}
${item.path}
`; } row(item: BlueprintInstance): TemplateResult[] { let description = undefined; const descKey = "blueprints.goauthentik.io/description"; if ( item.metadata && item.metadata.labels && Object.hasOwn(item.metadata?.labels, descKey) ) { description = item.metadata?.labels[descKey]; } return [ html`
${item.name}
${description ? html`${description}` : html``}`, html`${BlueprintStatus(item)}`, html`${item.lastApplied.toLocaleString()}`, html` ${item.enabled ? msg("Yes") : msg("No")} `, html` ${msg("Update")} ${msg("Update Blueprint")} { return new ManagedApi(DEFAULT_CONFIG) .managedBlueprintsApplyCreate({ instanceUuid: item.pk, }) .then(() => { this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); }); }} > `, ]; } renderObjectCreate(): TemplateResult { return html` ${msg("Create")} ${msg("Create Blueprint Instance")} `; } }