import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { SentryIgnoredError } from "@goauthentik/common/errors"; import { PFColor } from "@goauthentik/elements/Label"; import { Form } from "@goauthentik/elements/forms/Form"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import { Flow, FlowImportResult, FlowsApi } from "@goauthentik/api"; @customElement("ak-flow-import-form") export class FlowImportForm extends Form { @state() result?: FlowImportResult; getSuccessMessage(): string { return t`Successfully imported flow.`; } static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } // eslint-disable-next-line send = (data: Flow): Promise => { const file = this.getFormFiles()["flow"]; if (!file) { throw new SentryIgnoredError("No form data"); } return new FlowsApi(DEFAULT_CONFIG) .flowsInstancesImportCreate({ file: file, }) .then((result) => { if (!result.success) { this.result = result; throw new SentryIgnoredError("Failed to import flow"); } return result; }); }; renderResult(): TemplateResult { return html`
${this.result?.success ? t`Yes` : t`No`}
${(this.result?.logs || []).length > 0 ? this.result?.logs?.map((m) => { return html`
${m.log_level}
${m.event}
`; }) : html`
${t`No log messages.`}
`}
`; } renderForm(): TemplateResult { return html`

${t`.yaml files, which can be found on goauthentik.io and can be exported by authentik.`}

${this.result ? this.renderResult() : html``}
`; } }