mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
refactor(computes): the lock helpers take claims instead of file locks
This commit is contained in:
parent
fca4a5d91c
commit
68812ddbdf
18 changed files with 545 additions and 318 deletions
|
|
@ -1,7 +1,15 @@
|
|||
"""Secrets never reach a job record, a response or a log line."""
|
||||
"""Secrets never reach a job record, a response or a log line. What a refused
|
||||
request says about the job holding the resource: details for its owner and
|
||||
superusers, a minimal summary for everyone else."""
|
||||
|
||||
import re
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.timesince import timesince
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from . import jobs
|
||||
|
||||
_NAMES = r"(?:pass|secret|token|key)\w*"
|
||||
_PATTERNS = [
|
||||
(re.compile(r"(://[^:/@\s]+:)[^@\s]+@"), r"\1***@"),
|
||||
|
|
@ -30,3 +38,25 @@ def check_params(params):
|
|||
elif isinstance(params, (list, tuple)):
|
||||
for value in params:
|
||||
check_params(value)
|
||||
|
||||
|
||||
def may_see(op, user):
|
||||
return user.is_superuser or (op.user_id is not None and op.user_id == user.pk)
|
||||
|
||||
|
||||
def summary(op, user):
|
||||
base = {"kind": op.kind, "label": str(_(jobs.label_of(op.kind))), "state": op.state, "since": op.created_at}
|
||||
if may_see(op, user):
|
||||
base.update({"id": str(op.id), "user": op.username})
|
||||
return base
|
||||
|
||||
|
||||
def busy_message(busy, user):
|
||||
op = busy.blocker
|
||||
if op is None:
|
||||
return _("A short operation is in progress on this resource; try again in a moment.")
|
||||
values = {"label": _(jobs.label_of(op.kind)), "state": op.state, "since": timesince(op.created_at, timezone.now())}
|
||||
if may_see(op, user):
|
||||
return _("%(label)s is %(state)s on this resource (started by %(user)s, %(since)s ago); "
|
||||
"see the Jobs page.") % {**values, "user": op.username}
|
||||
return _("%(label)s is %(state)s on this resource (since %(since)s).") % values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue