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 { msg } from "@lit/localize"; 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 msg("Successfully imported flow."); } static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } async send(): Promise { const file = this.getFormFiles()["flow"]; if (!file) { throw new SentryIgnoredError("No form data"); } const result = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesImportCreate({ file: file, }); if (!result.success) { this.result = result; throw new SentryIgnoredError("Failed to import flow"); } return result; } renderResult(): TemplateResult { return html`
${this.result?.success ? msg("Yes") : msg("No")}
${(this.result?.logs || []).length > 0 ? this.result?.logs?.map((m) => { return html`
${m.log_level}
${m.event}
`; }) : html`
${msg("No log messages.")}
`}
`; } renderInlineForm(): TemplateResult { return html`

${msg( ".yaml files, which can be found on goauthentik.io and can be exported by authentik.", )}

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