*: ensure TaskResult uid is slugified to prevent URL errors

This commit is contained in:
Jens Langhammer 2020-10-16 21:31:12 +02:00
parent 96846220c3
commit 3454760731
2 changed files with 10 additions and 4 deletions

View file

@ -4,6 +4,7 @@ from typing import Any
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.db.models.base import Model
from django.utils.text import slugify
from structlog import get_logger
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
@ -45,10 +46,14 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str):
logs = ProxyDockerController(outpost).run_with_logs()
except ControllerException as exc:
self.set_status(
TaskResult(TaskResultStatus.ERROR, uid=outpost.name).with_error(exc)
TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error(
exc
)
)
else:
self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=outpost.name))
self.set_status(
TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=slugify(outpost.name))
)
@CELERY_APP.task()

View file

@ -2,6 +2,7 @@
from time import time
from django.core.cache import cache
from django.utils.text import slugify
from ldap3.core.exceptions import LDAPException
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
@ -32,10 +33,10 @@ def ldap_sync(self: MonitoredTask, source_pk: int):
TaskResult(
TaskResultStatus.SUCCESSFUL,
[f"Synced {user_count} users", f"Synced {group_count} groups"],
uid=source.name,
uid=slugify(source.name),
)
)
except LDAPException as exc:
self.set_status(
TaskResult(TaskResultStatus.ERROR, uid=source.name).with_error(exc)
TaskResult(TaskResultStatus.ERROR, uid=slugify(source.name)).with_error(exc)
)