*: ensure TaskResult uid is slugified to prevent URL errors
This commit is contained in:
parent
96846220c3
commit
3454760731
|
@ -4,6 +4,7 @@ from typing import Any
|
||||||
from asgiref.sync import async_to_sync
|
from asgiref.sync import async_to_sync
|
||||||
from channels.layers import get_channel_layer
|
from channels.layers import get_channel_layer
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
|
from django.utils.text import slugify
|
||||||
from structlog import get_logger
|
from structlog import get_logger
|
||||||
|
|
||||||
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
|
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()
|
logs = ProxyDockerController(outpost).run_with_logs()
|
||||||
except ControllerException as exc:
|
except ControllerException as exc:
|
||||||
self.set_status(
|
self.set_status(
|
||||||
TaskResult(TaskResultStatus.ERROR, uid=outpost.name).with_error(exc)
|
TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error(
|
||||||
|
exc
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else:
|
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()
|
@CELERY_APP.task()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.utils.text import slugify
|
||||||
from ldap3.core.exceptions import LDAPException
|
from ldap3.core.exceptions import LDAPException
|
||||||
|
|
||||||
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
|
from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
|
||||||
|
@ -32,10 +33,10 @@ def ldap_sync(self: MonitoredTask, source_pk: int):
|
||||||
TaskResult(
|
TaskResult(
|
||||||
TaskResultStatus.SUCCESSFUL,
|
TaskResultStatus.SUCCESSFUL,
|
||||||
[f"Synced {user_count} users", f"Synced {group_count} groups"],
|
[f"Synced {user_count} users", f"Synced {group_count} groups"],
|
||||||
uid=source.name,
|
uid=slugify(source.name),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except LDAPException as exc:
|
except LDAPException as exc:
|
||||||
self.set_status(
|
self.set_status(
|
||||||
TaskResult(TaskResultStatus.ERROR, uid=source.name).with_error(exc)
|
TaskResult(TaskResultStatus.ERROR, uid=slugify(source.name)).with_error(exc)
|
||||||
)
|
)
|
||||||
|
|
Reference in New Issue