Merged PR 523: #2782: initial impl of files in nodes
## Summary Added ability to add folders and files to nodes via configuration ## Test process https://dev.azure.com/ma-dev-uk/PrimAITE/_git/PrimAITE/pullrequest/523?_a=files&path=/tests/integration_tests/configuration_file_parsing/test_node_file_system_config.py ## Checklist - [X] PR is linked to a **work item** - [X] **acceptance criteria** of linked ticket are met - [X] performed **self-review** of the code - [X] written **tests** for any new functionality added with this PR - [X] updated the **documentation** if this PR changes or adds functionality - [ ] written/updated **design docs** if this PR implements new functionality - [ ] updated the **change log** - [X] ran **pre-commit** checks for code style - [ ] attended to any **TO-DOs** left in the code #2782: initial impl of files in nodes Related work items: #2782
This commit is contained in:
@@ -843,7 +843,6 @@ simulation:
|
||||
dns_server: 192.168.1.10
|
||||
services:
|
||||
- type: FTPServer
|
||||
|
||||
- hostname: security_suite
|
||||
type: server
|
||||
ip_address: 192.168.1.110
|
||||
|
||||
@@ -17,6 +17,7 @@ from primaite.game.agent.scripted_agents.random_agent import PeriodicAgent
|
||||
from primaite.game.agent.scripted_agents.tap001 import TAP001
|
||||
from primaite.game.science import graph_has_cycle, topological_sort
|
||||
from primaite.simulator import SIM_OUTPUT
|
||||
from primaite.simulator.file_system.file_type import FileType
|
||||
from primaite.simulator.network.airspace import AirSpaceFrequency
|
||||
from primaite.simulator.network.hardware.base import NetworkInterface, NodeOperatingState, UserManager
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
@@ -330,6 +331,26 @@ class PrimaiteGame:
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
|
||||
# handle node file system
|
||||
if node_cfg.get("file_system"):
|
||||
for folder_idx, folder_obj in enumerate(node_cfg.get("file_system")):
|
||||
# if the folder is not a Dict, create an empty folder
|
||||
if not isinstance(folder_obj, Dict):
|
||||
new_node.file_system.create_folder(folder_name=folder_obj)
|
||||
else:
|
||||
folder_name = next(iter(folder_obj))
|
||||
for file_idx, file_obj in enumerate(node_cfg["file_system"][folder_idx][folder_name]):
|
||||
if not isinstance(file_obj, Dict):
|
||||
new_node.file_system.create_file(folder_name=folder_name, file_name=file_obj)
|
||||
else:
|
||||
file_name = next(iter(file_obj))
|
||||
new_node.file_system.create_file(
|
||||
folder_name=folder_name,
|
||||
file_name=file_name,
|
||||
size=file_obj[file_name].get("size", 0),
|
||||
file_type=FileType[file_obj[file_name].get("type", "UNKNOWN").upper()],
|
||||
)
|
||||
|
||||
if "users" in node_cfg and new_node.software_manager.software.get("UserManager"):
|
||||
user_manager: UserManager = new_node.software_manager.software["UserManager"] # noqa
|
||||
for user_cfg in node_cfg["users"]:
|
||||
|
||||
Reference in New Issue
Block a user