web: fix system status being degraded when embedded outpost is disabled

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2024-01-12 02:58:41 +01:00
parent 687a7e0c16
commit ca956aa70b
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
3 changed files with 15 additions and 2 deletions

View File

@ -13,6 +13,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from authentik.core.api.utils import PassiveSerializer from authentik.core.api.utils import PassiveSerializer
from authentik.lib.config import CONFIG
from authentik.lib.utils.reflection import get_env from authentik.lib.utils.reflection import get_env
from authentik.outposts.apps import MANAGED_OUTPOST from authentik.outposts.apps import MANAGED_OUTPOST
from authentik.outposts.models import Outpost from authentik.outposts.models import Outpost
@ -39,6 +40,7 @@ class SystemInfoSerializer(PassiveSerializer):
runtime = SerializerMethodField() runtime = SerializerMethodField()
brand = SerializerMethodField() brand = SerializerMethodField()
server_time = SerializerMethodField() server_time = SerializerMethodField()
embedded_outpost_disabled = SerializerMethodField()
embedded_outpost_host = SerializerMethodField() embedded_outpost_host = SerializerMethodField()
def get_http_headers(self, request: Request) -> dict[str, str]: def get_http_headers(self, request: Request) -> dict[str, str]:
@ -77,6 +79,10 @@ class SystemInfoSerializer(PassiveSerializer):
"""Current server time""" """Current server time"""
return now() return now()
def get_embedded_outpost_disabled(self, request: Request) -> bool:
"""Whether the embedded outpost is disabled"""
return CONFIG.get_bool("outposts.disable_embedded_outpost", False)
def get_embedded_outpost_host(self, request: Request) -> str: def get_embedded_outpost_host(self, request: Request) -> str:
"""Get the FQDN configured on the embedded outpost""" """Get the FQDN configured on the embedded outpost"""
outposts = Outpost.objects.filter(managed=MANAGED_OUTPOST) outposts = Outpost.objects.filter(managed=MANAGED_OUTPOST)

View File

@ -43495,8 +43495,12 @@ components:
type: string type: string
description: Get the FQDN configured on the embedded outpost description: Get the FQDN configured on the embedded outpost
readOnly: true readOnly: true
embedded_outpost_disabled:
type: boolean
readOnly: true
required: required:
- brand - brand
- embedded_outpost_disabled
- embedded_outpost_host - embedded_outpost_host
- http_headers - http_headers
- http_host - http_host

View File

@ -22,7 +22,10 @@ export class SystemStatusCard extends AdminStatusCard<SystemInfo> {
async getPrimaryValue(): Promise<SystemInfo> { async getPrimaryValue(): Promise<SystemInfo> {
this.now = new Date(); this.now = new Date();
let status = await new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve(); let status = await new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve();
if (status.embeddedOutpostHost === "" || !status.embeddedOutpostHost.includes("http")) { if (
!status.embeddedOutpostDisabled &&
(status.embeddedOutpostHost === "" || !status.embeddedOutpostHost.includes("http"))
) {
// First install, ensure the embedded outpost host is set // First install, ensure the embedded outpost host is set
// also run when outpost host does not contain http // also run when outpost host does not contain http
// (yes it's called host and requires a URL, i know) // (yes it's called host and requires a URL, i know)
@ -51,7 +54,7 @@ export class SystemStatusCard extends AdminStatusCard<SystemInfo> {
} }
getStatus(value: SystemInfo): Promise<AdminStatus> { getStatus(value: SystemInfo): Promise<AdminStatus> {
if (value.embeddedOutpostHost === "") { if (!value.embeddedOutpostDisabled && value.embeddedOutpostHost === "") {
this.statusSummary = msg("Warning"); this.statusSummary = msg("Warning");
return Promise.resolve<AdminStatus>({ return Promise.resolve<AdminStatus>({
icon: "fa fa-exclamation-triangle pf-m-warning", icon: "fa fa-exclamation-triangle pf-m-warning",