-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathbulk.py
More file actions
57 lines (43 loc) · 1.85 KB
/
bulk.py
File metadata and controls
57 lines (43 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any
from ai.backend.manager.actions.action import BaseActionTriggerMeta
from ai.backend.manager.actions.action.bulk import BaseBulkAction
@dataclass(frozen=True)
class DeniedEntity:
"""A bulk entity that a validator rejected, paired with its reason."""
entity_id: str
deny_reason: str
@dataclass(frozen=True)
class BulkValidationResult:
"""Per-entity validation outcome for a bulk action.
``BulkActionProcessor`` intersects ``allowed_entity_ids`` across
validators and records each ``DeniedEntity`` — with its reason — on the
corresponding ``ValidatorDecision`` so the final response can
surface *why* each ID was filtered out.
"""
allowed_entity_ids: list[str]
denied_entities: list[DeniedEntity]
class BulkActionValidator(ABC):
@classmethod
@abstractmethod
def name(cls) -> str:
"""Stable identifier used in ``ValidatorDecision.validator_name``.
Chosen by the implementation so logs and partial-success responses can
attribute denials to a specific validator independently of the Python
class name.
"""
raise NotImplementedError
@abstractmethod
async def validate(
self, action: BaseBulkAction[Any], meta: BaseActionTriggerMeta
) -> BulkValidationResult:
"""Validate the bulk action and return per-entity permission results.
Implementations must classify every ID in ``action.entity_ids`` as
either allowed or denied. Validators that cannot make a decision for
an ID should treat it as allowed.
The processor wraps each call in its own async context manager so
cross-cutting concerns (timing, audit) live in one place — validators
do not need to own them.
"""
raise NotImplementedError