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-09-21 09:31:37 +00:00
|
|
|
import { customElement } from "lit/decorators";
|
2021-09-21 09:19:26 +00:00
|
|
|
import { ifDefined } from "lit/directives/if-defined";
|
|
|
|
import { until } from "lit/directives/until";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { AdminApi, EventMatcherPolicy, EventsApi, PoliciesApi } from "@goauthentik/api";
|
|
|
|
|
|
|
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
|
|
|
import "../../../elements/forms/FormGroup";
|
|
|
|
import "../../../elements/forms/HorizontalFormElement";
|
2021-05-11 10:19:35 +00:00
|
|
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import { first } from "../../../utils";
|
2021-04-02 14:32:03 +00:00
|
|
|
|
|
|
|
@customElement("ak-policy-event-matcher-form")
|
2021-05-11 10:19:35 +00:00
|
|
|
export class EventMatcherPolicyForm extends ModelForm<EventMatcherPolicy, string> {
|
|
|
|
loadInstance(pk: string): Promise<EventMatcherPolicy> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRetrieve({
|
2021-05-11 10:19:35 +00:00
|
|
|
policyUuid: pk,
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 10:19:35 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated policy.`;
|
2021-04-02 14:32:03 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created policy.`;
|
2021-04-02 14:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: EventMatcherPolicy): Promise<EventMatcherPolicy> => {
|
2021-05-11 10:19:35 +00:00
|
|
|
if (this.instance) {
|
2021-04-02 14:32:03 +00:00
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherUpdate({
|
2021-05-11 10:19:35 +00:00
|
|
|
policyUuid: this.instance.pk || "",
|
2021-08-03 15:52:21 +00:00
|
|
|
eventMatcherPolicyRequest: data,
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherCreate({
|
2021-08-03 15:52:21 +00:00
|
|
|
eventMatcherPolicyRequest: data,
|
2021-04-02 14:32:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-04-10 10:37:08 +00:00
|
|
|
<div class="form-help-text">
|
|
|
|
${t`Matches an event against a set of criteria. If any of the configured values match, the policy passes.`}
|
|
|
|
</div>
|
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-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="executionLogging">
|
|
|
|
<div class="pf-c-check">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="pf-c-check__input"
|
|
|
|
?checked=${first(this.instance?.executionLogging, false)}
|
|
|
|
/>
|
|
|
|
<label class="pf-c-check__label"> ${t`Execution logging`} </label>
|
2021-04-02 14:32:03 +00:00
|
|
|
</div>
|
2021-04-10 10:37:08 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.`}
|
|
|
|
</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-group .expanded=${true}>
|
2021-08-03 15:52:21 +00:00
|
|
|
<span slot="header"> ${t`Policy-specific settings`} </span>
|
2021-04-02 14:32:03 +00:00
|
|
|
<div slot="body" class="pf-c-form">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Action`} name="action">
|
2021-04-02 14:32:03 +00:00
|
|
|
<select class="pf-c-form-control">
|
2021-08-03 15:52:21 +00:00
|
|
|
<option value="" ?selected=${this.instance?.action === undefined}>
|
|
|
|
---------
|
|
|
|
</option>
|
|
|
|
${until(
|
|
|
|
new EventsApi(DEFAULT_CONFIG)
|
|
|
|
.eventsEventsActionsList()
|
|
|
|
.then((actions) => {
|
|
|
|
return actions.map((action) => {
|
|
|
|
return html`<option
|
|
|
|
value=${action.component}
|
|
|
|
?selected=${this.instance?.action ===
|
|
|
|
action.component}
|
|
|
|
>
|
|
|
|
${action.name}
|
|
|
|
</option>`;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
html`<option>${t`Loading...`}</option>`,
|
|
|
|
)}
|
2021-04-02 14:32:03 +00:00
|
|
|
</select>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Match created events with this action type. When left empty, all action types will be matched.`}
|
|
|
|
</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Client IP`} name="clientIp">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.clientIp || "")}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Matches Event's Client IP (strict matching, for network matching use an Expression Policy.`}
|
|
|
|
</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`App`} name="app">
|
2021-04-02 14:32:03 +00:00
|
|
|
<select class="pf-c-form-control">
|
2021-08-03 15:52:21 +00:00
|
|
|
<option value="" ?selected=${this.instance?.app === undefined}>
|
|
|
|
---------
|
|
|
|
</option>
|
|
|
|
${until(
|
|
|
|
new AdminApi(DEFAULT_CONFIG).adminAppsList().then((apps) => {
|
|
|
|
return apps.map((app) => {
|
|
|
|
return html`<option
|
|
|
|
value=${app.name}
|
|
|
|
?selected=${this.instance?.app === app.name}
|
|
|
|
>
|
|
|
|
${app.label}
|
|
|
|
</option>`;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
html`<option>${t`Loading...`}</option>`,
|
|
|
|
)}
|
2021-04-02 14:32:03 +00:00
|
|
|
</select>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Match events created by selected application. When left empty, all applications are matched.`}
|
|
|
|
</p>
|
2021-04-02 14:32:03 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|