web/admin: auto set the embedded outpost's authentik_host on first view

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-19 13:27:04 +01:00
parent 8e6fcfe350
commit 8599d9efe0
6 changed files with 56 additions and 4 deletions

View File

@ -116,6 +116,7 @@ class OutpostFilter(FilterSet):
"providers": ["isnull"], "providers": ["isnull"],
"name": ["iexact", "icontains"], "name": ["iexact", "icontains"],
"service_connection__name": ["iexact", "icontains"], "service_connection__name": ["iexact", "icontains"],
"managed": ["iexact", "icontains"]
} }

View File

@ -5723,6 +5723,14 @@ paths:
operationId: outposts_instances_list operationId: outposts_instances_list
description: Outpost Viewset description: Outpost Viewset
parameters: parameters:
- in: query
name: managed__icontains
schema:
type: string
- in: query
name: managed__iexact
schema:
type: string
- in: query - in: query
name: name__icontains name: name__icontains
schema: schema:
@ -5931,6 +5939,14 @@ paths:
operationId: outposts_instances_health_list operationId: outposts_instances_health_list
description: Get outposts current health description: Get outposts current health
parameters: parameters:
- in: query
name: managed__icontains
schema:
type: string
- in: query
name: managed__iexact
schema:
type: string
- in: query - in: query
name: name__icontains name: name__icontains
schema: schema:

View File

@ -3199,6 +3199,10 @@ msgstr "OAuth Authorization Codes"
msgid "OAuth Refresh Codes" msgid "OAuth Refresh Codes"
msgstr "OAuth Refresh Codes" msgstr "OAuth Refresh Codes"
#: src/pages/admin-overview/cards/SystemStatusCard.ts
msgid "OK"
msgstr "OK"
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
msgid "Object" msgid "Object"

View File

@ -3175,6 +3175,10 @@ msgstr "Code d'autorisation OAuth"
msgid "OAuth Refresh Codes" msgid "OAuth Refresh Codes"
msgstr "Code de rafraîchissement OAuth" msgstr "Code de rafraîchissement OAuth"
#: src/pages/admin-overview/cards/SystemStatusCard.ts
msgid "OK"
msgstr ""
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
msgid "Object" msgid "Object"

View File

@ -3189,6 +3189,10 @@ msgstr ""
msgid "OAuth Refresh Codes" msgid "OAuth Refresh Codes"
msgstr "" msgstr ""
#: src/pages/admin-overview/cards/SystemStatusCard.ts
msgid "OK"
msgstr ""
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
msgid "Object" msgid "Object"

View File

@ -3,7 +3,7 @@ import { t } from "@lingui/macro";
import { TemplateResult, html } from "lit"; import { TemplateResult, html } from "lit";
import { customElement } from "lit/decorators.js"; import { customElement } from "lit/decorators.js";
import { AdminApi, System } from "@goauthentik/api"; import { AdminApi, OutpostsApi, System } from "@goauthentik/api";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { AdminStatus, AdminStatusCard } from "./AdminStatusCard"; import { AdminStatus, AdminStatusCard } from "./AdminStatusCard";
@ -12,11 +12,34 @@ import { AdminStatus, AdminStatusCard } from "./AdminStatusCard";
export class SystemStatusCard extends AdminStatusCard<System> { export class SystemStatusCard extends AdminStatusCard<System> {
now?: Date; now?: Date;
header = "OK"; header = t`OK`;
getPrimaryValue(): Promise<System> { async getPrimaryValue(): Promise<System> {
this.now = new Date(); this.now = new Date();
return new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve(); let status = await new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve();
if (status.embeddedOutpostHost === "") {
// First install, ensure the embedded outpost host is set
await this.setOutpostHost();
status = await new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve();
}
return status;
}
// Called on fresh installations and whenever the embedded outpost is deleted
// automatically send the login URL when the user first visits the admin dashboard.
async setOutpostHost(): Promise<void> {
const outposts = await new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesList({
managedIexact: "goauthentik.io/outposts/embedded",
});
if (outposts.results.length < 1) {
return;
}
const outpost = outposts.results[0];
outpost.config["authentik_host"] = window.location.origin;
await new OutpostsApi(DEFAULT_CONFIG).outpostsInstancesUpdate({
uuid: outpost.pk,
outpostRequest: outpost,
});
} }
getStatus(value: System): Promise<AdminStatus> { getStatus(value: System): Promise<AdminStatus> {