From e5ff416c2d0f046814bffb7cfcc40e89aa2223fc Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 29 Mar 2021 22:52:08 +0200 Subject: [PATCH] outposts: add API for default config Signed-off-by: Jens Langhammer --- authentik/flows/api/flows.py | 1 - authentik/outposts/api/outposts.py | 20 +++++++++++- authentik/outposts/models.py | 4 +-- swagger.yaml | 49 ++++++++++++++++++++++++++++++ web/src/pages/groups/GroupForm.ts | 2 +- 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/authentik/flows/api/flows.py b/authentik/flows/api/flows.py index c27878e9a..0923d6c88 100644 --- a/authentik/flows/api/flows.py +++ b/authentik/flows/api/flows.py @@ -31,7 +31,6 @@ from authentik.flows.transfer.common import DataclassEncoder from authentik.flows.transfer.exporter import FlowExporter from authentik.flows.transfer.importer import FlowImporter 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 LOGGER = get_logger() diff --git a/authentik/outposts/api/outposts.py b/authentik/outposts/api/outposts.py index cd185bb96..5734e4057 100644 --- a/authentik/outposts/api/outposts.py +++ b/authentik/outposts/api/outposts.py @@ -9,7 +9,7 @@ from rest_framework.serializers import JSONField, ModelSerializer, Serializer from rest_framework.viewsets import ModelViewSet 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): @@ -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): """Outpost health status""" @@ -78,3 +90,9 @@ class OutpostViewSet(ModelViewSet): } ) 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())}) diff --git a/authentik/outposts/models.py b/authentik/outposts/models.py index a7538eab7..9b0680010 100644 --- a/authentik/outposts/models.py +++ b/authentik/outposts/models.py @@ -80,9 +80,9 @@ class OutpostType(models.TextChoices): PROXY = "proxy" -def default_outpost_config(): +def default_outpost_config(host: Optional[str] = None): """Get default outpost config""" - return asdict(OutpostConfig(authentik_host="")) + return asdict(OutpostConfig(authentik_host=host or "")) @dataclass diff --git a/swagger.yaml b/swagger.yaml index 33d0dee8f..2a2122f1d 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -4496,6 +4496,48 @@ paths: tags: - outposts 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}/: get: operationId: outposts_outposts_read @@ -15658,6 +15700,13 @@ definitions: _config: title: config type: object + OutpostDefaultConfig: + type: object + properties: + config: + title: Config + type: object + readOnly: true OutpostHealth: type: object properties: diff --git a/web/src/pages/groups/GroupForm.ts b/web/src/pages/groups/GroupForm.ts index c994bed48..03ee52647 100644 --- a/web/src/pages/groups/GroupForm.ts +++ b/web/src/pages/groups/GroupForm.ts @@ -71,7 +71,7 @@ export class GroupForm extends Form { label=${gettext("Members")} ?required=${true} name="users"> - ${until(new CoreApi(DEFAULT_CONFIG).coreUsersList({}).then(users => { return users.results.map(user => { const selected = Array.from(this.group?.users || []).some(su => {