2021-04-26 12:45:14 +00:00
|
|
|
import { Outpost, OutpostsApi, OutpostTypeEnum, ProvidersApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-05-11 10:12:31 +00:00
|
|
|
import { customElement } from "lit-element";
|
2021-03-29 21:12:31 +00:00
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
import { until } from "lit-html/directives/until";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../elements/forms/HorizontalFormElement";
|
|
|
|
import "../../elements/CodeMirror";
|
|
|
|
import YAML from "yaml";
|
2021-05-11 09:48:34 +00:00
|
|
|
import { ModelForm } from "../../elements/forms/ModelForm";
|
2021-03-29 21:12:31 +00:00
|
|
|
|
|
|
|
@customElement("ak-outpost-form")
|
2021-05-11 09:48:34 +00:00
|
|
|
export class OutpostForm extends ModelForm<Outpost, string> {
|
2021-03-29 21:12:31 +00:00
|
|
|
|
2021-05-11 09:48:34 +00:00
|
|
|
loadInstance(pk: string): Promise<Outpost> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesRetrieve({
|
2021-05-11 09:48:34 +00:00
|
|
|
uuid: pk
|
|
|
|
});
|
|
|
|
}
|
2021-03-29 21:12:31 +00:00
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated outpost.`;
|
2021-03-29 21:12:31 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created outpost.`;
|
2021-03-29 21:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: Outpost): Promise<Outpost> => {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-05-16 16:38:19 +00:00
|
|
|
return new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesUpdate({
|
2021-05-11 09:48:34 +00:00
|
|
|
uuid: this.instance.pk || "",
|
2021-05-16 16:24:15 +00:00
|
|
|
outpostRequest: data
|
2021-03-29 21:12:31 +00:00
|
|
|
});
|
|
|
|
} else {
|
2021-05-16 16:38:19 +00:00
|
|
|
return new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesCreate({
|
2021-05-16 16:24:15 +00:00
|
|
|
outpostRequest: data
|
2021-03-29 21:12:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Name`}
|
2021-03-29 21:12:31 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
2021-03-29 21:12:31 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Type`}
|
2021-03-29 21:12:31 +00:00
|
|
|
?required=${true}
|
|
|
|
name="type">
|
|
|
|
<select class="pf-c-form-control">
|
2021-05-11 09:48:34 +00:00
|
|
|
<option value=${OutpostTypeEnum.Proxy} ?selected=${this.instance?.type === OutpostTypeEnum.Proxy}>${t`Proxy`}</option>
|
|
|
|
<option value=${OutpostTypeEnum.Ldap} ?selected=${this.instance?.type === OutpostTypeEnum.Ldap}>${t`LDAP (Technical preview)`}</option>
|
2021-03-29 21:12:31 +00:00
|
|
|
</select>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Service connection`}
|
2021-03-29 21:12:31 +00:00
|
|
|
name="serviceConnection">
|
|
|
|
<select class="pf-c-form-control">
|
2021-05-11 09:48:34 +00:00
|
|
|
<option value="" ?selected=${this.instance?.serviceConnection === undefined}>---------</option>
|
2021-03-29 21:12:31 +00:00
|
|
|
${until(new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsAllList({
|
|
|
|
ordering: "pk"
|
|
|
|
}).then(scs => {
|
|
|
|
return scs.results.map(sc => {
|
2021-05-11 09:48:34 +00:00
|
|
|
return html`<option value=${ifDefined(sc.pk)} ?selected=${this.instance?.serviceConnection === sc.pk}>
|
2021-04-04 16:58:52 +00:00
|
|
|
${sc.name} (${sc.verboseName})
|
|
|
|
</option>`;
|
2021-03-29 21:12:31 +00:00
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-03-29 21:12:31 +00:00
|
|
|
</select>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Selecting a service-connection enables the management of the outpost by authentik.`}</p>
|
2021-04-03 12:52:12 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
2021-04-03 17:26:43 +00:00
|
|
|
See <a target="_blank" href="https://goauthentik.io/docs/outposts/outposts">documentation</a>.
|
2021-04-03 12:52:12 +00:00
|
|
|
</p>
|
2021-03-29 21:12:31 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Providers`}
|
2021-03-29 21:12:31 +00:00
|
|
|
?required=${true}
|
|
|
|
name="providers">
|
|
|
|
<select class="pf-c-form-control" multiple>
|
|
|
|
${until(new ProvidersApi(DEFAULT_CONFIG).providersProxyList({
|
|
|
|
ordering: "pk"
|
|
|
|
}).then(providers => {
|
|
|
|
return providers.results.map(provider => {
|
2021-05-11 09:48:34 +00:00
|
|
|
const selected = Array.from(this.instance?.providers || []).some(sp => {
|
2021-03-29 21:12:31 +00:00
|
|
|
return sp == provider.pk;
|
|
|
|
});
|
|
|
|
return html`<option value=${ifDefined(provider.pk)} ?selected=${selected}>${provider.verboseName} ${provider.name}</option>`;
|
2021-04-26 12:46:29 +00:00
|
|
|
});
|
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
|
|
|
${until(new ProvidersApi(DEFAULT_CONFIG).providersLdapList({
|
|
|
|
ordering: "pk"
|
|
|
|
}).then(providers => {
|
|
|
|
return providers.results.map(provider => {
|
2021-05-11 09:48:34 +00:00
|
|
|
const selected = Array.from(this.instance?.providers || []).some(sp => {
|
2021-04-26 12:46:29 +00:00
|
|
|
return sp == provider.pk;
|
|
|
|
});
|
|
|
|
return html`<option value=${ifDefined(provider.pk)} ?selected=${selected}>${provider.verboseName} ${provider.name}</option>`;
|
2021-03-29 21:12:31 +00:00
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-03-29 21:12:31 +00:00
|
|
|
</select>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Hold control/command to select multiple items.`}</p>
|
2021-03-29 21:12:31 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-05-10 17:24:42 +00:00
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Configuration`}
|
|
|
|
name="config">
|
2021-05-16 16:38:19 +00:00
|
|
|
<ak-codemirror mode="yaml" value="${until(new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesDefaultSettingsRetrieve().then(config => {
|
2021-05-10 17:24:42 +00:00
|
|
|
let fc = config.config;
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
|
|
|
fc = this.instance.config;
|
2021-05-10 17:24:42 +00:00
|
|
|
}
|
|
|
|
return YAML.stringify(fc);
|
|
|
|
}))}"></ak-codemirror>
|
|
|
|
<p class="pf-c-form__helper-text">${t`Set custom attributes using YAML or JSON.`}</p>
|
|
|
|
</ak-form-element-horizontal>
|
2021-03-29 21:12:31 +00:00
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|