Revert "blueprints: fix issue in prod setups with encoding dataclasses via celery"

This reverts commit ff788edd9b.
This commit is contained in:
Jens Langhammer 2022-08-16 21:21:47 +02:00
parent ff788edd9b
commit 3da0233c40
2 changed files with 9 additions and 19 deletions

View file

@ -1,4 +1,6 @@
"""Serializer mixin for managed models""" """Serializer mixin for managed models"""
from dataclasses import asdict
from drf_spectacular.utils import extend_schema, inline_serializer from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import CharField, DateTimeField, JSONField from rest_framework.fields import CharField, DateTimeField, JSONField
@ -84,7 +86,7 @@ class BlueprintInstanceViewSet(UsedByMixin, ModelViewSet):
def available(self, request: Request) -> Response: def available(self, request: Request) -> Response:
"""Get blueprints""" """Get blueprints"""
files: list[BlueprintFile] = blueprints_find.delay().get() files: list[BlueprintFile] = blueprints_find.delay().get()
return Response([sanitize_dict(file) for file in files]) return Response([sanitize_dict(asdict(file)) for file in files])
@permission_required("authentik_blueprints.view_blueprintinstance") @permission_required("authentik_blueprints.view_blueprintinstance")
@extend_schema( @extend_schema(

View file

@ -21,7 +21,6 @@ from authentik.events.monitored_tasks import (
TaskResultStatus, TaskResultStatus,
prefill_task, prefill_task,
) )
from authentik.events.utils import sanitize_dict
from authentik.lib.config import CONFIG from authentik.lib.config import CONFIG
from authentik.root.celery import CELERY_APP from authentik.root.celery import CELERY_APP
@ -36,17 +35,6 @@ class BlueprintFile:
last_m: int last_m: int
meta: Optional[BlueprintMetadata] = field(default=None) meta: Optional[BlueprintMetadata] = field(default=None)
@staticmethod
def from_raw(raw: dict, path: Path) -> "BlueprintFile":
"""Create blueprint file from raw YAML"""
root = Path(CONFIG.y("blueprints_dir"))
metadata = raw.get("metadata", None)
version = raw.get("version", 1)
file_hash = sha512(path.read_bytes()).hexdigest()
blueprint = BlueprintFile(path.relative_to(root), version, file_hash, path.stat().st_mtime)
blueprint.meta = from_dict(BlueprintMetadata, metadata) if metadata else None
return blueprint
@CELERY_APP.task( @CELERY_APP.task(
throws=(DatabaseError, ProgrammingError, InternalError), throws=(DatabaseError, ProgrammingError, InternalError),
@ -64,11 +52,14 @@ def blueprints_find():
raw_blueprint = None raw_blueprint = None
if not raw_blueprint: if not raw_blueprint:
continue continue
metadata = raw_blueprint.get("metadata", None)
version = raw_blueprint.get("version", 1) version = raw_blueprint.get("version", 1)
if version != 1: if version != 1:
continue continue
blueprint = BlueprintFile.from_raw(raw_blueprint, path) file_hash = sha512(path.read_bytes()).hexdigest()
blueprints.append(sanitize_dict(asdict(blueprint))) blueprint = BlueprintFile(path.relative_to(root), version, file_hash, path.stat().st_mtime)
blueprint.meta = from_dict(BlueprintMetadata, metadata) if metadata else None
blueprints.append(blueprint)
return blueprints return blueprints
@ -79,11 +70,8 @@ def blueprints_find():
def blueprints_discover(self: MonitoredTask): def blueprints_discover(self: MonitoredTask):
"""Find blueprints and check if they need to be created in the database""" """Find blueprints and check if they need to be created in the database"""
count = 0 count = 0
root = Path(CONFIG.y("blueprints_dir"))
for blueprint in blueprints_find(): for blueprint in blueprints_find():
check_blueprint_v1_file( check_blueprint_v1_file(blueprint)
BlueprintFile.from_raw(blueprint, Path(root, blueprint.get("path")))
)
count += 1 count += 1
self.set_status( self.set_status(
TaskResult( TaskResult(