Skip to content

Схемы, связанные с HWM

HWMResponseV1

Bases: BaseModel

HWM response.

Source code in horizon/commons/schemas/v1/hwm.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class HWMResponseV1(BaseModel):
    """HWM response."""

    id: int = Field(description="HWM id")
    namespace_id: int = Field(description="Namespace id HWM is bound to")
    name: str = Field(description="HWM name, unique in the namespace")
    description: str = Field(description="HWM description")
    type: str = Field(description="HWM type, any non-empty string")
    value: Any = Field(description="HWM value, any JSON serializable value")
    entity: Optional[str] = Field(default=None, description="Name of entity associated with the HWM. Can be any string")
    expression: Optional[str] = Field(
        default=None,
        description="Expression used to calculate HWM value. Can be any string",
    )
    changed_at: datetime = Field(description="Timestamp of last change of the HWM data")
    changed_by: Optional[str] = Field(default=None, description="Latest user who changed the HWM data")

    class Config:
        if pydantic_version >= "2":
            from_attributes = True
        else:
            orm_mode = True

HWMListResponseV1

Bases: BaseModel

Source code in horizon/commons/schemas/v1/hwm.py
40
41
class HWMListResponseV1(BaseModel):
    hwms: List[HWMResponseV1]

HWMPaginateQueryV1

Bases: PaginateQueryV1

Query params for HWM pagination request.

Source code in horizon/commons/schemas/v1/hwm.py
44
45
46
47
48
class HWMPaginateQueryV1(PaginateQueryV1):
    """Query params for HWM pagination request."""

    namespace_id: int
    name: Optional[str] = Field(default=None, min_length=1, max_length=MAX_NAME_LENGTH)

HWMCreateRequestV1

Bases: BaseModel

Request body for HWM create request.

Source code in horizon/commons/schemas/v1/hwm.py
53
54
55
56
57
58
59
60
61
62
class HWMCreateRequestV1(BaseModel):
    """Request body for HWM create request."""

    namespace_id: int
    name: str = Field(min_length=1, max_length=MAX_NAME_LENGTH)
    description: str = ""
    type: str = Field(min_length=1, max_length=MAX_TYPE_LENGTH)
    value: Any
    entity: Optional[str] = None
    expression: Optional[str] = None

HWMUpdateRequestV1

Bases: BaseModel

Request body for HWM update request.

If field value is not set, it will not be updated.

Source code in horizon/commons/schemas/v1/hwm.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class HWMUpdateRequestV1(BaseModel):
    """Request body for HWM update request.

    If field value is not set, it will not be updated.
    """

    name: str = Field(default=Unset(), min_length=1, max_length=MAX_NAME_LENGTH)  # type: ignore[assignment]
    description: str = Unset()  # type: ignore[assignment]
    type: str = Field(default=Unset(), min_length=1, max_length=MAX_TYPE_LENGTH)  # type: ignore[assignment]
    value: Any = Unset()  # type: ignore[assignment]
    entity: Optional[str] = Unset()  # type: ignore[assignment]
    expression: Optional[str] = Unset()  # type: ignore[assignment]

    class Config:
        arbitrary_types_allowed = True

    @root_validator(skip_on_failure=True)
    def _any_field_set(cls, values):  # noqa: N805
        """Validate that at least one field is set."""
        values_set = {k for k, v in values.items() if not isinstance(v, Unset)}
        if not values_set:
            msg = "At least one field must be set."
            raise ValueError(msg)
        return values

HWMBulkCopyRequestV1

Bases: BaseModel

Schema for request body of HWM copy operation.

Source code in horizon/commons/schemas/v1/hwm.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class HWMBulkCopyRequestV1(BaseModel):
    """Schema for request body of HWM copy operation."""

    source_namespace_id: int = Field(description="Source namespace ID from which HWMs are copied.")
    target_namespace_id: int = Field(description="Target namespace ID to which HWMs are copied.")
    hwm_ids: List[int] = Field(description="List of HWM IDs to be copied.")
    with_history: bool = Field(default=False, description="Whether to copy HWM history.")

    @validator("hwm_ids", pre=True, always=True)
    def _check_hwm_ids_not_empty(cls, v):  # noqa: N805
        if not len(v):
            msg = "List should have at least 1 item after validation, not 0"
            raise ValueError(msg)
        return v

    @root_validator(skip_on_failure=True)
    def _check_namespace_ids(cls, values):  # noqa: N805
        """Validator to ensure source and target namespace IDs are different."""
        source_namespace_id, target_namespace_id = values.get("source_namespace_id"), values.get("target_namespace_id")
        if source_namespace_id == target_namespace_id:
            msg = "Source and target namespace IDs must not be the same."
            raise ValueError(msg)
        return values

HWMBulkDeleteRequestV1

Bases: BaseModel

Schema for request body of bulk delete HWM operation.

Source code in horizon/commons/schemas/v1/hwm.py
116
117
118
119
120
121
122
123
124
125
126
127
class HWMBulkDeleteRequestV1(BaseModel):
    """Schema for request body of bulk delete HWM operation."""

    namespace_id: int
    hwm_ids: List[int]

    @validator("hwm_ids", pre=True, always=True)
    def _check_hwm_ids_not_empty(cls, v):  # noqa: N805
        if not len(v):
            msg = "List should have at least 1 item after validation, not 0"
            raise ValueError(msg)
        return v