2021-09-21 09:31:37 +00:00
|
|
|
import YAML from "yaml";
|
|
|
|
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
|
|
import { until } from "lit/directives/until.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { Outpost, OutpostTypeEnum, OutpostsApi, ProvidersApi } from "@goauthentik/api";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
2021-03-29 21:12:31 +00:00
|
|
|
import "../../elements/CodeMirror";
|
2021-09-21 09:31:37 +00:00
|
|
|
import "../../elements/forms/HorizontalFormElement";
|
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-06-01 21:35:22 +00:00
|
|
|
@property()
|
2021-06-08 21:10:17 +00:00
|
|
|
type: OutpostTypeEnum = OutpostTypeEnum.Proxy;
|
2021-06-01 21:35:22 +00:00
|
|
|
|
2021-08-07 20:32:53 +00:00
|
|
|
@property({ type: Boolean })
|
2021-08-10 11:54:59 +00:00
|
|
|
embedded = false;
|
2021-08-07 20:26:36 +00:00
|
|
|
|
2021-05-11 09:48:34 +00:00
|
|
|
loadInstance(pk: string): Promise<Outpost> {
|
2021-08-03 15:52:21 +00:00
|
|
|
return new OutpostsApi(DEFAULT_CONFIG)
|
|
|
|
.outpostsInstancesRetrieve({
|
|
|
|
uuid: pk,
|
|
|
|
})
|
|
|
|
.then((o) => {
|
|
|
|
this.type = o.type || OutpostTypeEnum.Proxy;
|
|
|
|
return o;
|
|
|
|
});
|
2021-05-11 09:48:34 +00:00
|
|
|
}
|
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-08-03 15:52:21 +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-08-03 15:52:21 +00:00
|
|
|
outpostRequest: data,
|
2021-03-29 21:12:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-01 21:35:22 +00:00
|
|
|
renderProviders(): Promise<TemplateResult[]> {
|
|
|
|
switch (this.type) {
|
|
|
|
case OutpostTypeEnum.Proxy:
|
2021-08-03 15:52:21 +00:00
|
|
|
return new ProvidersApi(DEFAULT_CONFIG)
|
|
|
|
.providersProxyList({
|
2021-11-11 21:47:10 +00:00
|
|
|
ordering: "name",
|
2021-09-03 08:43:21 +00:00
|
|
|
applicationIsnull: false,
|
2021-08-03 15:52:21 +00:00
|
|
|
})
|
|
|
|
.then((providers) => {
|
|
|
|
return providers.results.map((provider) => {
|
|
|
|
const selected = Array.from(this.instance?.providers || []).some(
|
|
|
|
(sp) => {
|
|
|
|
return sp == provider.pk;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return html`<option
|
|
|
|
value=${ifDefined(provider.pk)}
|
|
|
|
?selected=${selected}
|
|
|
|
>
|
2021-11-13 21:44:52 +00:00
|
|
|
${provider.assignedApplicationName} (${provider.externalHost})
|
2021-08-03 15:52:21 +00:00
|
|
|
</option>`;
|
2021-06-01 21:35:22 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
case OutpostTypeEnum.Ldap:
|
2021-08-03 15:52:21 +00:00
|
|
|
return new ProvidersApi(DEFAULT_CONFIG)
|
|
|
|
.providersLdapList({
|
2021-11-11 21:47:10 +00:00
|
|
|
ordering: "name",
|
2021-09-03 08:43:21 +00:00
|
|
|
applicationIsnull: false,
|
2021-08-03 15:52:21 +00:00
|
|
|
})
|
|
|
|
.then((providers) => {
|
|
|
|
return providers.results.map((provider) => {
|
|
|
|
const selected = Array.from(this.instance?.providers || []).some(
|
|
|
|
(sp) => {
|
|
|
|
return sp == provider.pk;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return html`<option
|
|
|
|
value=${ifDefined(provider.pk)}
|
|
|
|
?selected=${selected}
|
|
|
|
>
|
2021-09-03 08:43:21 +00:00
|
|
|
${provider.assignedApplicationName} (${provider.name})
|
2021-08-03 15:52:21 +00:00
|
|
|
</option>`;
|
2021-06-01 21:35:22 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 21:12:31 +00:00
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
|
|
|
<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>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Type`} ?required=${true} name="type">
|
|
|
|
<select
|
|
|
|
class="pf-c-form-control"
|
|
|
|
@change=${(ev: Event) => {
|
|
|
|
const target = ev.target as HTMLSelectElement;
|
|
|
|
this.type = target.selectedOptions[0].value as OutpostTypeEnum;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<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>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Integration`} name="serviceConnection">
|
2021-03-29 21:12:31 +00:00
|
|
|
<select class="pf-c-form-control">
|
2021-08-03 15:52:21 +00:00
|
|
|
<option value="" ?selected=${this.instance?.serviceConnection === undefined}>
|
|
|
|
---------
|
|
|
|
</option>
|
|
|
|
${until(
|
|
|
|
new OutpostsApi(DEFAULT_CONFIG)
|
|
|
|
.outpostsServiceConnectionsAllList({
|
2021-11-11 21:47:10 +00:00
|
|
|
ordering: "name",
|
2021-08-03 15:52:21 +00:00
|
|
|
})
|
|
|
|
.then((scs) => {
|
|
|
|
return scs.results.map((sc) => {
|
|
|
|
let selected = this.instance?.serviceConnection === sc.pk;
|
|
|
|
if (scs.results.length === 1 && !this.instance) {
|
|
|
|
selected = true;
|
|
|
|
}
|
|
|
|
return html`<option
|
|
|
|
value=${ifDefined(sc.pk)}
|
|
|
|
?selected=${selected}
|
|
|
|
>
|
|
|
|
${sc.name} (${sc.verboseName})
|
|
|
|
</option>`;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
html`<option>${t`Loading...`}</option>`,
|
|
|
|
)}
|
2021-03-29 21:12:31 +00:00
|
|
|
</select>
|
2021-07-31 11:48:26 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Selecting an integration 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-08-03 15:52:21 +00:00
|
|
|
See
|
2021-10-20 14:31:10 +00:00
|
|
|
<a
|
|
|
|
target="_blank"
|
2021-12-30 15:27:16 +00:00
|
|
|
href="https://goauthentik.io/docs/outposts?utm_source=authentik"
|
2021-08-03 15:52:21 +00:00
|
|
|
>documentation</a
|
|
|
|
>.
|
2021-04-03 12:52:12 +00:00
|
|
|
</p>
|
2021-03-29 21:12:31 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-07 20:26:36 +00:00
|
|
|
<ak-form-element-horizontal
|
2021-09-03 08:43:21 +00:00
|
|
|
label=${t`Applications`}
|
2021-08-07 20:26:36 +00:00
|
|
|
?required=${!this.embedded}
|
|
|
|
name="providers"
|
|
|
|
>
|
2021-03-29 21:12:31 +00:00
|
|
|
<select class="pf-c-form-control" multiple>
|
2021-06-01 21:35:22 +00:00
|
|
|
${until(this.renderProviders(), html`<option>${t`Loading...`}</option>`)}
|
2021-03-29 21:12:31 +00:00
|
|
|
</select>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`You can only select providers that match the type of the outpost.`}
|
|
|
|
</p>
|
|
|
|
<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-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Configuration`} name="config">
|
2021-09-21 09:19:26 +00:00
|
|
|
<!-- @ts-ignore -->
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-codemirror
|
|
|
|
mode="yaml"
|
|
|
|
value="${until(
|
|
|
|
new OutpostsApi(DEFAULT_CONFIG)
|
|
|
|
.outpostsInstancesDefaultSettingsRetrieve()
|
|
|
|
.then((config) => {
|
|
|
|
let fc = config.config;
|
|
|
|
if (this.instance) {
|
|
|
|
fc = this.instance.config;
|
|
|
|
}
|
|
|
|
return YAML.stringify(fc);
|
|
|
|
}),
|
|
|
|
)}"
|
|
|
|
></ak-codemirror>
|
2021-06-13 21:56:38 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
2021-08-03 15:52:21 +00:00
|
|
|
${t`Set custom attributes using YAML or JSON.`}
|
|
|
|
</p>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
See
|
|
|
|
<a
|
|
|
|
target="_blank"
|
2021-12-30 15:27:16 +00:00
|
|
|
href="https://goauthentik.io/docs/outposts?utm_source=authentik#configuration"
|
2021-08-03 15:52:21 +00:00
|
|
|
>documentation</a
|
|
|
|
>.
|
2021-06-13 21:56:38 +00:00
|
|
|
</p>
|
2021-05-10 17:24:42 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-03-29 21:12:31 +00:00
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|