import YAML from "yaml"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { Outpost, OutpostTypeEnum, OutpostsApi, ProvidersApi } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/CodeMirror"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; @customElement("ak-outpost-form") export class OutpostForm extends ModelForm { @property() type: OutpostTypeEnum = OutpostTypeEnum.Proxy; @property({ type: Boolean }) embedded = false; loadInstance(pk: string): Promise { return new OutpostsApi(DEFAULT_CONFIG) .outpostsInstancesRetrieve({ uuid: pk, }) .then((o) => { this.type = o.type || OutpostTypeEnum.Proxy; return o; }); } getSuccessMessage(): string { if (this.instance) { return t`Successfully updated outpost.`; } else { return t`Successfully created outpost.`; } } send = (data: Outpost): Promise => { if (this.instance) { return new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesUpdate({ uuid: this.instance.pk || "", outpostRequest: data, }); } else { return new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesCreate({ outpostRequest: data, }); } }; renderProviders(): Promise { switch (this.type) { case OutpostTypeEnum.Proxy: return new ProvidersApi(DEFAULT_CONFIG) .providersProxyList({ ordering: "name", applicationIsnull: false, }) .then((providers) => { return providers.results.map((provider) => { const selected = Array.from(this.instance?.providers || []).some( (sp) => { return sp == provider.pk; }, ); return html``; }); }); case OutpostTypeEnum.Ldap: return new ProvidersApi(DEFAULT_CONFIG) .providersLdapList({ ordering: "name", applicationIsnull: false, }) .then((providers) => { return providers.results.map((provider) => { const selected = Array.from(this.instance?.providers || []).some( (sp) => { return sp == provider.pk; }, ); return html``; }); }); } } renderForm(): TemplateResult { return html`

${t`Selecting an integration enables the management of the outpost by authentik.`}

See documentation.

${t`You can only select providers that match the type of the outpost.`}

${t`Hold control/command to select multiple items.`}

${t`Set custom attributes using YAML or JSON.`}

See documentation.

`; } }