2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
|
|
|
import { first } from "@goauthentik/common/utils";
|
2022-12-29 21:28:54 +00:00
|
|
|
import "@goauthentik/elements/SearchSelect";
|
2022-09-14 22:05:21 +00:00
|
|
|
import "@goauthentik/elements/forms/FormGroup";
|
|
|
|
import "@goauthentik/elements/forms/HorizontalFormElement";
|
|
|
|
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
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 } 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
|
|
|
|
2022-12-29 21:28:54 +00:00
|
|
|
import { AdminApi, EventMatcherPolicy, EventsApi, PoliciesApi, TypeCreate } from "@goauthentik/api";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
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">
|
2022-12-29 21:28:54 +00:00
|
|
|
<ak-search-select
|
|
|
|
.fetchObjects=${async (query?: string): Promise<TypeCreate[]> => {
|
|
|
|
const items = await new EventsApi(
|
|
|
|
DEFAULT_CONFIG,
|
|
|
|
).eventsEventsActionsList();
|
|
|
|
return items.filter((item) =>
|
|
|
|
query ? item.name.includes(query) : true,
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
.renderElement=${(item: TypeCreate): string => {
|
|
|
|
return item.name;
|
|
|
|
}}
|
|
|
|
.value=${(item: TypeCreate | undefined): string | undefined => {
|
|
|
|
return item?.component;
|
|
|
|
}}
|
|
|
|
.selected=${(item: TypeCreate): boolean => {
|
|
|
|
return this.instance?.action === item.component;
|
|
|
|
}}
|
|
|
|
?blankable=${true}
|
|
|
|
>
|
|
|
|
</ak-search-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>`;
|
|
|
|
}
|
|
|
|
}
|