outposts: add API for default config

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-03-29 22:52:08 +02:00
parent 21ea527623
commit e5ff416c2d
5 changed files with 71 additions and 5 deletions

View File

@ -31,7 +31,6 @@ from authentik.flows.transfer.common import DataclassEncoder
from authentik.flows.transfer.exporter import FlowExporter from authentik.flows.transfer.exporter import FlowExporter
from authentik.flows.transfer.importer import FlowImporter from authentik.flows.transfer.importer import FlowImporter
from authentik.flows.views import SESSION_KEY_PLAN from authentik.flows.views import SESSION_KEY_PLAN
from authentik.lib.utils.urls import redirect_with_qs
from authentik.lib.views import bad_request_message from authentik.lib.views import bad_request_message
LOGGER = get_logger() LOGGER = get_logger()

View File

@ -9,7 +9,7 @@ from rest_framework.serializers import JSONField, ModelSerializer, Serializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from authentik.core.api.providers import ProviderSerializer from authentik.core.api.providers import ProviderSerializer
from authentik.outposts.models import Outpost from authentik.outposts.models import Outpost, default_outpost_config
class OutpostSerializer(ModelSerializer): class OutpostSerializer(ModelSerializer):
@ -32,6 +32,18 @@ class OutpostSerializer(ModelSerializer):
] ]
class OutpostDefaultConfigSerializer(Serializer):
"""Global default outpost config"""
config = JSONField(read_only=True)
def create(self, validated_data: dict) -> Model:
raise NotImplementedError
def update(self, instance: Model, validated_data: dict) -> Model:
raise NotImplementedError
class OutpostHealthSerializer(Serializer): class OutpostHealthSerializer(Serializer):
"""Outpost health status""" """Outpost health status"""
@ -78,3 +90,9 @@ class OutpostViewSet(ModelViewSet):
} }
) )
return Response(OutpostHealthSerializer(states, many=True).data) return Response(OutpostHealthSerializer(states, many=True).data)
@swagger_auto_schema(responses={200: OutpostDefaultConfigSerializer(many=False)})
@action(detail=False, methods=["GET"])
def default_settings(self, request: Request) -> Response:
"""Global default outpost config"""
return Response({"config": default_outpost_config(request._request.get_host())})

View File

@ -80,9 +80,9 @@ class OutpostType(models.TextChoices):
PROXY = "proxy" PROXY = "proxy"
def default_outpost_config(): def default_outpost_config(host: Optional[str] = None):
"""Get default outpost config""" """Get default outpost config"""
return asdict(OutpostConfig(authentik_host="")) return asdict(OutpostConfig(authentik_host=host or ""))
@dataclass @dataclass

View File

@ -4496,6 +4496,48 @@ paths:
tags: tags:
- outposts - outposts
parameters: [] parameters: []
/outposts/outposts/default_settings/:
get:
operationId: outposts_outposts_default_settings
description: Global default outpost config
parameters:
- name: providers__isnull
in: query
description: ''
required: false
type: string
- name: ordering
in: query
description: Which field to use when ordering the results.
required: false
type: string
- name: search
in: query
description: A search term.
required: false
type: string
- name: page
in: query
description: Page Index
required: false
type: integer
- name: page_size
in: query
description: Page Size
required: false
type: integer
responses:
'200':
description: ''
schema:
$ref: '#/definitions/OutpostDefaultConfig'
'403':
description: Authentication credentials were invalid, absent or insufficient.
schema:
$ref: '#/definitions/GenericError'
tags:
- outposts
parameters: []
/outposts/outposts/{uuid}/: /outposts/outposts/{uuid}/:
get: get:
operationId: outposts_outposts_read operationId: outposts_outposts_read
@ -15658,6 +15700,13 @@ definitions:
_config: _config:
title: config title: config
type: object type: object
OutpostDefaultConfig:
type: object
properties:
config:
title: Config
type: object
readOnly: true
OutpostHealth: OutpostHealth:
type: object type: object
properties: properties:

View File

@ -71,7 +71,7 @@ export class GroupForm extends Form<Group> {
label=${gettext("Members")} label=${gettext("Members")}
?required=${true} ?required=${true}
name="users"> name="users">
<select name="users" class="pf-c-form-control" multiple> <select class="pf-c-form-control" multiple>
${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({}).then(users => { ${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({}).then(users => {
return users.results.map(user => { return users.results.map(user => {
const selected = Array.from(this.group?.users || []).some(su => { const selected = Array.from(this.group?.users || []).some(su => {