#2912 - Mid-day commit. Actions moving across from actions.py to game.agent.actions

This commit is contained in:
Charlie Crane
2024-10-17 12:22:30 +01:00
parent 861cfe2c0a
commit cd30e2d084
9 changed files with 743 additions and 244 deletions

View File

@@ -0,0 +1,79 @@
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
from typing import ClassVar
from primaite.game.agent.actions.manager import AbstractAction
from primaite.interface.request import RequestFormat
class NodeFileAbstractAction(AbstractAction):
"""Abstract base class for file actions.
Any action which applies to a file and uses node_name, folder_name, and file_name as its only three parameters can inherit
from this base class.
"""
class ConfigSchema(AbstractAction.ConfigSchema):
node_name: str
folder_name: str
file_name: str
verb: ClassVar[str]
@classmethod
def form_request(cls, config: ConfigSchema) -> RequestFormat:
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
if config.node_name is None or config.folder_name is None or config.file_name is None:
return ["do_nothing"]
return [
"network",
"node",
config.node_name,
"file_system",
"folder",
config.folder_name,
"file",
config.file_name,
cls.verb,
]
class NodeFileCreateAction(NodeFileAbstractAction, identifier="node_file_create"):
"""Action which creates a new file in a given folder."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "create"
class NodeFileScanAction(NodeFileAbstractAction, identifier="node_file_scan"):
"""Action which scans a file."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "scan"
class NodeFileDeleteAction(NodeFileAbstractAction, identifier="node_file_delete"):
"""Action which deletes a file."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "delete"
class NodeFileRestoreAction(NodeFileAbstractAction, identifier="node_file_restore"):
"""Action which restores a file."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "restore"
class NodeFileCorruptAction(NodeFileAbstractAction, identifier="node_file_corrupt"):
"""Action which corrupts a file."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "corrupt"
class NodeFileAccessAction(NodeFileAbstractAction, identifier="node_file_access"):
"""Action which increases a file's access count."""
class ConfigSchema(NodeFileAbstractAction.ConfigSchema):
verb: str = "access"