blueprints: webui (#3356)
This commit is contained in:
@ -300,6 +300,9 @@ export class AdminInterface extends LitElement {
|
||||
<ak-sidebar-item path="/crypto/certificates">
|
||||
<span slot="label">${t`Certificates`}</span>
|
||||
</ak-sidebar-item>
|
||||
<ak-sidebar-item path="/blueprints/instances">
|
||||
<span slot="label">${t`Blueprints`}</span>
|
||||
</ak-sidebar-item>
|
||||
</ak-sidebar-item>
|
||||
`;
|
||||
}
|
||||
|
105
web/src/pages/blueprints/BlueprintForm.ts
Normal file
105
web/src/pages/blueprints/BlueprintForm.ts
Normal file
@ -0,0 +1,105 @@
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/web/api/Config";
|
||||
import "@goauthentik/web/elements/CodeMirror";
|
||||
import "@goauthentik/web/elements/forms/FormGroup";
|
||||
import "@goauthentik/web/elements/forms/HorizontalFormElement";
|
||||
import { ModelForm } from "@goauthentik/web/elements/forms/ModelForm";
|
||||
import { first } from "@goauthentik/web/utils";
|
||||
import YAML from "yaml";
|
||||
|
||||
import { t } from "@lingui/macro";
|
||||
|
||||
import { TemplateResult, html } from "lit";
|
||||
import { customElement } from "lit/decorators.js";
|
||||
import { until } from "lit/directives/until.js";
|
||||
|
||||
import { BlueprintInstance, ManagedApi } from "@goauthentik/api";
|
||||
|
||||
@customElement("ak-blueprint-form")
|
||||
export class BlueprintForm extends ModelForm<BlueprintInstance, string> {
|
||||
loadInstance(pk: string): Promise<BlueprintInstance> {
|
||||
return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsRetrieve({
|
||||
instanceUuid: pk,
|
||||
});
|
||||
}
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated instance.`;
|
||||
} else {
|
||||
return t`Successfully created instance.`;
|
||||
}
|
||||
}
|
||||
|
||||
send = (data: BlueprintInstance): Promise<BlueprintInstance> => {
|
||||
if (this.instance?.pk) {
|
||||
return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsUpdate({
|
||||
instanceUuid: this.instance.pk,
|
||||
blueprintInstanceRequest: data,
|
||||
});
|
||||
} else {
|
||||
return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsCreate({
|
||||
blueprintInstanceRequest: data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
renderForm(): TemplateResult {
|
||||
return html`<form class="pf-c-form pf-m-horizontal">
|
||||
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
||||
<input
|
||||
type="text"
|
||||
value="${first(this.instance?.name)}"
|
||||
class="pf-c-form-control"
|
||||
required
|
||||
/>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="enabled">
|
||||
<div class="pf-c-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="pf-c-check__input"
|
||||
?checked=${first(this.instance?.enabled, false)}
|
||||
/>
|
||||
<label class="pf-c-check__label"> ${t`Enabled`} </label>
|
||||
</div>
|
||||
<p class="pf-c-form__helper-text">${t`Disabled blueprints are never applied.`}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal label=${t`Path`} name="path">
|
||||
<select class="pf-c-form-control">
|
||||
${until(
|
||||
new ManagedApi(DEFAULT_CONFIG)
|
||||
.managedBlueprintsAvailableList()
|
||||
.then((files) => {
|
||||
return files.map((file) => {
|
||||
let name = file.path;
|
||||
if (file.meta && file.meta.name) {
|
||||
name = `${name} (${file.meta.name})`;
|
||||
}
|
||||
const selected = file.path === this.instance?.path;
|
||||
return html`<option ?selected=${selected} value=${file.path}>
|
||||
${name}
|
||||
</option>`;
|
||||
});
|
||||
}),
|
||||
html`<option>${t`Loading...`}</option>`,
|
||||
)}
|
||||
</select>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-group>
|
||||
<span slot="header">${t`Additional settings`}</span>
|
||||
<div slot="body" class="pf-c-form">
|
||||
<ak-form-element-horizontal label=${t`Context`} name="context">
|
||||
<ak-codemirror
|
||||
mode="yaml"
|
||||
value="${YAML.stringify(first(this.instance?.context, {}))}"
|
||||
>
|
||||
</ak-codemirror>
|
||||
<p class="pf-c-form__helper-text">
|
||||
${t`Configure the blueprint context, used for templating.`}
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
</ak-form-group>
|
||||
</form>`;
|
||||
}
|
||||
}
|
148
web/src/pages/blueprints/BlueprintListPage.ts
Normal file
148
web/src/pages/blueprints/BlueprintListPage.ts
Normal file
@ -0,0 +1,148 @@
|
||||
import { AKResponse } from "@goauthentik/web/api/Client";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/web/api/Config";
|
||||
import { uiConfig } from "@goauthentik/web/common/config";
|
||||
import { EVENT_REFRESH } from "@goauthentik/web/constants";
|
||||
import { PFColor } from "@goauthentik/web/elements/Label";
|
||||
import "@goauthentik/web/elements/buttons/ActionButton";
|
||||
import "@goauthentik/web/elements/buttons/SpinnerButton";
|
||||
import "@goauthentik/web/elements/forms/DeleteBulkForm";
|
||||
import "@goauthentik/web/elements/forms/ModalForm";
|
||||
import { TableColumn } from "@goauthentik/web/elements/table/Table";
|
||||
import { TablePage } from "@goauthentik/web/elements/table/TablePage";
|
||||
import "@goauthentik/web/pages/blueprints/BlueprintForm";
|
||||
|
||||
import { t } from "@lingui/macro";
|
||||
|
||||
import { TemplateResult, html } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
|
||||
import { BlueprintInstance, BlueprintInstanceStatusEnum, ManagedApi } from "@goauthentik/api";
|
||||
|
||||
export function BlueprintStatus(blueprint?: BlueprintInstance): string {
|
||||
if (!blueprint) return "";
|
||||
switch (blueprint.status) {
|
||||
case BlueprintInstanceStatusEnum.Successful:
|
||||
return t`Successful`;
|
||||
case BlueprintInstanceStatusEnum.Orphaned:
|
||||
return t`Orphaned`;
|
||||
case BlueprintInstanceStatusEnum.Unknown:
|
||||
return t`Unknown`;
|
||||
case BlueprintInstanceStatusEnum.Warning:
|
||||
return t`Warning`;
|
||||
case BlueprintInstanceStatusEnum.Error:
|
||||
return t`Error`;
|
||||
}
|
||||
}
|
||||
@customElement("ak-blueprint-list")
|
||||
export class BlueprintListPage extends TablePage<BlueprintInstance> {
|
||||
searchEnabled(): boolean {
|
||||
return true;
|
||||
}
|
||||
pageTitle(): string {
|
||||
return t`Blueprints`;
|
||||
}
|
||||
pageDescription(): string {
|
||||
return t`Automate and template configuration within authentik.`;
|
||||
}
|
||||
pageIcon(): string {
|
||||
return "pf-icon pf-icon-blueprint";
|
||||
}
|
||||
|
||||
checkbox = true;
|
||||
|
||||
@property()
|
||||
order = "name";
|
||||
|
||||
async apiEndpoint(page: number): Promise<AKResponse<BlueprintInstance>> {
|
||||
return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsList({
|
||||
ordering: this.order,
|
||||
page: page,
|
||||
pageSize: (await uiConfig()).pagination.perPage,
|
||||
search: this.search || "",
|
||||
});
|
||||
}
|
||||
|
||||
columns(): TableColumn[] {
|
||||
return [
|
||||
new TableColumn(t`Name`, "name"),
|
||||
new TableColumn(t`Status`, "status"),
|
||||
new TableColumn(t`Last applied`, "last_applied"),
|
||||
new TableColumn(t`Enabled`, "enabled"),
|
||||
new TableColumn(t`Actions`),
|
||||
];
|
||||
}
|
||||
|
||||
renderToolbarSelected(): TemplateResult {
|
||||
const disabled = this.selectedElements.length < 1;
|
||||
return html`<ak-forms-delete-bulk
|
||||
objectLabel=${t`Blueprint(s)`}
|
||||
.objects=${this.selectedElements}
|
||||
.metadata=${(item: BlueprintInstance) => {
|
||||
return [{ key: t`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,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
||||
${t`Delete`}
|
||||
</button>
|
||||
</ak-forms-delete-bulk>`;
|
||||
}
|
||||
|
||||
row(item: BlueprintInstance): TemplateResult[] {
|
||||
return [
|
||||
html`${item.name}`,
|
||||
html`${BlueprintStatus(item)}`,
|
||||
html`${item.lastApplied.toLocaleString()}`,
|
||||
html`<ak-label color=${item.enabled ? PFColor.Green : PFColor.Red}>
|
||||
${item.enabled ? t`Yes` : t`No`}
|
||||
</ak-label>`,
|
||||
html`<ak-action-button
|
||||
class="pf-m-plain"
|
||||
.apiRequest=${() => {
|
||||
return new ManagedApi(DEFAULT_CONFIG)
|
||||
.managedBlueprintsApplyCreate({
|
||||
instanceUuid: item.pk,
|
||||
})
|
||||
.then(() => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent(EVENT_REFRESH, {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<i class="fas fa-play" aria-hidden="true"></i>
|
||||
</ak-action-button>
|
||||
<ak-forms-modal>
|
||||
<span slot="submit"> ${t`Update`} </span>
|
||||
<span slot="header"> ${t`Update Blueprint`} </span>
|
||||
<ak-blueprint-form slot="form" .instancePk=${item.pk}> </ak-blueprint-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-plain">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
</ak-forms-modal>`,
|
||||
];
|
||||
}
|
||||
|
||||
renderObjectCreate(): TemplateResult {
|
||||
return html`
|
||||
<ak-forms-modal>
|
||||
<span slot="submit"> ${t`Create`} </span>
|
||||
<span slot="header"> ${t`Create Blueprint Instance`} </span>
|
||||
<ak-blueprint-form slot="form"> </ak-blueprint-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-primary">${t`Create`}</button>
|
||||
</ak-forms-modal>
|
||||
`;
|
||||
}
|
||||
}
|
@ -124,7 +124,7 @@ export class SystemTaskListPage extends TablePage<Task> {
|
||||
});
|
||||
}}
|
||||
>
|
||||
<i class="fas fa-sync-alt" aria-hidden="true"></i>
|
||||
<i class="fas fa-play" aria-hidden="true"></i>
|
||||
</ak-action-button>`,
|
||||
];
|
||||
}
|
||||
|
@ -129,4 +129,8 @@ export const ROUTES: Route[] = [
|
||||
await import("@goauthentik/web/pages/crypto/CertificateKeyPairListPage");
|
||||
return html`<ak-crypto-certificate-list></ak-crypto-certificate-list>`;
|
||||
}),
|
||||
new Route(new RegExp("^/blueprints/instances$"), async () => {
|
||||
await import("@goauthentik/web/pages/blueprints/BlueprintListPage");
|
||||
return html`<ak-blueprint-list></ak-blueprint-list>`;
|
||||
}),
|
||||
];
|
||||
|
Reference in New Issue
Block a user