outposts: include outposts build hash in state

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-30 15:16:31 +01:00
parent c249b55ff5
commit d03b0b8152
3 changed files with 25 additions and 1 deletions

View file

@ -1,4 +1,6 @@
"""Outpost API Views"""
from os import environ
from dacite.core import from_dict
from dacite.exceptions import DaciteError
from django_filters.filters import ModelMultipleChoiceFilter
@ -12,6 +14,7 @@ from rest_framework.response import Response
from rest_framework.serializers import JSONField, ModelSerializer, ValidationError
from rest_framework.viewsets import ModelViewSet
from authentik import ENV_GIT_HASH_KEY
from authentik.core.api.providers import ProviderSerializer
from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import PassiveSerializer, is_dict
@ -98,8 +101,12 @@ class OutpostHealthSerializer(PassiveSerializer):
last_seen = DateTimeField(read_only=True)
version = CharField(read_only=True)
version_should = CharField(read_only=True)
version_outdated = BooleanField(read_only=True)
build_hash = CharField(read_only=True, required=False)
build_hash_should = CharField(read_only=True, required=False)
class OutpostFilter(FilterSet):
"""Filter for Outposts"""
@ -146,6 +153,8 @@ class OutpostViewSet(UsedByMixin, ModelViewSet):
"version": state.version,
"version_should": state.version_should,
"version_outdated": state.version_outdated,
"build_hash": state.build_hash,
"build_hash_should": environ.get(ENV_GIT_HASH_KEY, ""),
}
)
return Response(OutpostHealthSerializer(states, many=True).data)

View file

@ -23525,7 +23525,15 @@ components:
version_outdated:
type: boolean
readOnly: true
build_hash:
type: string
readOnly: true
build_hash_should:
type: string
readOnly: true
required:
- build_hash
- build_hash_should
- last_seen
- version
- version_outdated

View file

@ -32,6 +32,13 @@ export class OutpostHealthElement extends LitElement {
if (!this.outpostHealth) {
return html`<ak-spinner></ak-spinner>`;
}
let versionString = this.outpostHealth.version;
if (this.outpostHealth.buildHash) {
versionString = `${versionString} (build ${this.outpostHealth.buildHash.substring(
0,
8,
)})`;
}
return html` <ul>
<li>
<ak-label color=${PFColor.Green}>
@ -44,7 +51,7 @@ export class OutpostHealthElement extends LitElement {
>${t`${this.outpostHealth.version}, should be ${this.outpostHealth.versionShould}`}
</ak-label>`
: html`<ak-label color=${PFColor.Green}
>${t`Version: ${this.outpostHealth.version || ""}`}
>${t`Version: ${versionString}`}
</ak-label>`}
</li>
</ul>`;