2021-03-31 20:40:48 +00:00
|
|
|
import { KubernetesServiceConnection, OutpostsApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-03-31 20:40:48 +00:00
|
|
|
import { customElement, property } from "lit-element";
|
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
import { Form } from "../../elements/forms/Form";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../elements/forms/HorizontalFormElement";
|
|
|
|
import "../../elements/CodeMirror";
|
|
|
|
import YAML from "yaml";
|
|
|
|
|
|
|
|
@customElement("ak-service-connection-kubernetes-form")
|
|
|
|
export class ServiceConnectionKubernetesForm extends Form<KubernetesServiceConnection> {
|
|
|
|
|
|
|
|
set scUUID(value: string) {
|
|
|
|
new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesRead({
|
|
|
|
uuid: value,
|
|
|
|
}).then(sc => {
|
|
|
|
this.sc = sc;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
sc?: KubernetesServiceConnection;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
if (this.sc) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated service-connection.`;
|
2021-03-31 20:40:48 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created service-connection.`;
|
2021-03-31 20:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: KubernetesServiceConnection): Promise<KubernetesServiceConnection> => {
|
|
|
|
if (this.sc) {
|
|
|
|
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesUpdate({
|
|
|
|
uuid: this.sc.pk || "",
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new OutpostsApi(DEFAULT_CONFIG).outpostsServiceConnectionsKubernetesCreate({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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-31 20:40:48 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
|
|
|
<input type="text" value="${ifDefined(this.sc?.name)}" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="local">
|
|
|
|
<div class="pf-c-check">
|
|
|
|
<input type="checkbox" class="pf-c-check__input" ?checked=${this.sc?.local || false}>
|
|
|
|
<label class="pf-c-check__label">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Local`}
|
2021-03-31 20:40:48 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`If enabled, use the local connection. Required Docker socket/Kubernetes Integration.`}</p>
|
2021-03-31 20:40:48 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Kubeconfig`}
|
2021-03-31 20:40:48 +00:00
|
|
|
name="kubeconfig">
|
|
|
|
<ak-codemirror mode="yaml" value="${YAML.stringify(this.sc?.kubeconfig)}">
|
|
|
|
</ak-codemirror>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|