2024-10-17 12:22:30 +01:00
|
|
|
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
|
|
|
|
from abc import abstractmethod
|
|
|
|
|
from typing import ClassVar, Dict
|
|
|
|
|
|
|
|
|
|
from primaite.game.agent.actions.manager import AbstractAction
|
|
|
|
|
from primaite.interface.request import RequestFormat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderAbstractAction(AbstractAction):
|
|
|
|
|
"""
|
|
|
|
|
Base class for folder actions.
|
|
|
|
|
|
|
|
|
|
Any action which applies to a folder and uses node_id and folder_id as its only two parameters can inherit from
|
|
|
|
|
this base class.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(AbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Base configuration schema for NodeFolder actions."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
node_name: str
|
|
|
|
|
folder_name: str
|
|
|
|
|
|
|
|
|
|
verb: ClassVar[str]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2024-10-18 12:07:53 +01:00
|
|
|
def form_request(cls, config: ConfigSchema) -> RequestFormat:
|
2024-10-17 12:22:30 +01:00
|
|
|
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
2024-10-18 12:07:53 +01:00
|
|
|
if config.node_name is None or config.folder_name is None:
|
2024-10-17 12:22:30 +01:00
|
|
|
return ["do_nothing"]
|
2024-10-18 12:07:53 +01:00
|
|
|
return ["network", "node", config.node_name, "file_system", "folder", config.folder_name, cls.verb]
|
2024-10-17 12:22:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderScanAction(NodeFolderAbstractAction, identifier="node_folder_scan"):
|
|
|
|
|
"""Action which scans a folder."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeFolderAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeFolderScanAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "scan"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderCheckhashAction(NodeFolderAbstractAction, identifier="node_folder_checkhash"):
|
|
|
|
|
"""Action which checks the hash of a folder."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeFolderAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeFolderCheckhashAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "checkhash"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderRepairAction(NodeFolderAbstractAction, identifier="node_folder_repair"):
|
|
|
|
|
"""Action which repairs a folder."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeFolderAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeFolderRepairAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "repair"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderRestoreAction(NodeFolderAbstractAction, identifier="node_folder_restore"):
|
|
|
|
|
"""Action which restores a folder."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeFolderAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeFolderRestoreAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "restore"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeFolderCreateAction(AbstractAction, identifier="node_folder_create"):
|
|
|
|
|
"""Action which creates a new folder."""
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(NodeFolderAbstractAction.ConfigSchema):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Configuration schema for NodeFolderCreateAction."""
|
|
|
|
|
|
2024-10-17 12:22:30 +01:00
|
|
|
verb: str = "create"
|