2024-08-06 18:07:12 -04:00
|
|
|
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
|
# or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
|
# 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
|
# 2.0.
|
|
|
|
|
|
|
|
|
|
"""Dataclasses for Action."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from pathlib import Path
|
2025-07-01 15:20:55 +02:00
|
|
|
from typing import Any
|
2024-08-06 18:07:12 -04:00
|
|
|
|
|
|
|
|
from .mixins import MarshmallowDataclassMixin
|
|
|
|
|
from .schemas import definitions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class ActionMeta(MarshmallowDataclassMixin):
|
|
|
|
|
"""Data stored in an exception's [metadata] section of TOML."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
creation_date: definitions.Date
|
2025-07-01 15:20:55 +02:00
|
|
|
rule_id: list[definitions.UUIDString]
|
2024-08-06 18:07:12 -04:00
|
|
|
rule_name: str
|
|
|
|
|
updated_date: definitions.Date
|
|
|
|
|
|
|
|
|
|
# Optional fields
|
2025-07-01 15:20:55 +02:00
|
|
|
deprecation_date: definitions.Date | None = None
|
|
|
|
|
comments: str | None = None
|
|
|
|
|
maturity: definitions.Maturity | None = None
|
2024-08-06 18:07:12 -04:00
|
|
|
|
|
|
|
|
|
2025-07-01 15:20:55 +02:00
|
|
|
@dataclass(frozen=True)
|
2024-08-06 18:07:12 -04:00
|
|
|
class Action(MarshmallowDataclassMixin):
|
|
|
|
|
"""Data object for rule Action."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
@dataclass
|
|
|
|
|
class ActionParams:
|
|
|
|
|
"""Data object for rule Action params."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
body: str
|
|
|
|
|
|
|
|
|
|
action_type_id: definitions.ActionTypeId
|
|
|
|
|
group: str
|
|
|
|
|
params: ActionParams
|
2025-07-01 15:20:55 +02:00
|
|
|
|
|
|
|
|
id: str | None = None
|
|
|
|
|
frequency: dict[str, Any] | None = None
|
|
|
|
|
alerts_filter: dict[str, Any] | None = None
|
2024-08-06 18:07:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class TOMLActionContents(MarshmallowDataclassMixin):
|
|
|
|
|
"""Object for action from TOML file."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
metadata: ActionMeta
|
2025-07-01 15:20:55 +02:00
|
|
|
actions: list[Action]
|
2024-08-06 18:07:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class TOMLAction:
|
|
|
|
|
"""Object for action from TOML file."""
|
2025-07-01 15:20:55 +02:00
|
|
|
|
2024-08-06 18:07:12 -04:00
|
|
|
contents: TOMLActionContents
|
|
|
|
|
path: Path
|
|
|
|
|
|
|
|
|
|
@property
|
2025-07-01 15:20:55 +02:00
|
|
|
def name(self) -> str:
|
2024-08-06 18:07:12 -04:00
|
|
|
return self.contents.metadata.rule_name
|
|
|
|
|
|
|
|
|
|
@property
|
2025-07-01 15:20:55 +02:00
|
|
|
def id(self) -> list[definitions.UUIDString]:
|
2024-08-06 18:07:12 -04:00
|
|
|
return self.contents.metadata.rule_id
|