Connect actions of top-level sim components

This commit is contained in:
Marek Wolan
2023-08-16 16:45:52 +01:00
parent d972fcc07e
commit ced45d4275
3 changed files with 72 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
from enum import Enum from enum import Enum
from typing import Dict, Final, List, Literal, Tuple from typing import Dict, Final, List, Literal, Tuple
from primaite.simulator.core import ActionPermissionValidator, SimComponent from primaite.simulator.core import Action, ActionManager, ActionPermissionValidator, SimComponent
from primaite.simulator.domain.account import Account, AccountType from primaite.simulator.domain.account import Account, AccountType
@@ -82,6 +82,20 @@ class DomainController(SimComponent):
folders: List[temp_folder] = {} folders: List[temp_folder] = {}
files: List[temp_file] = {} files: List[temp_file] = {}
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.action_manager = ActionManager()
# Action 'account' matches requests like:
# ['account', '<account-uuid>', *account_action]
self.action_manager.add_action(
"account",
Action(
func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context),
validator=GroupMembershipValidator([AccountGroup.DOMAIN_ADMIN]),
),
)
def _register_account(self, account: Account) -> None: def _register_account(self, account: Account) -> None:
"""TODO.""" """TODO."""
... ...

View File

@@ -0,0 +1,23 @@
from typing import Dict
from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent
from primaite.simulator.network.hardware.base import Link, Node
class NetworkContainer(SimComponent):
"""TODO."""
nodes: Dict[str, Node] = {}
links: Dict[str, Link] = {}
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.action_manager = ActionManager()
self.action_manager.add_action(
"node",
Action(
func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context),
validator=AllowAllValidator(),
),
)

View File

@@ -0,0 +1,34 @@
from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent
from primaite.simulator.domain.controller import DomainController
class __TempNetwork:
"""TODO."""
pass
class SimulationContainer(SimComponent):
"""TODO."""
network: __TempNetwork
domain: DomainController
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.action_manager = ActionManager()
# pass through network actions to the network objects
self.action_manager.add_action(
"network",
Action(
func=lambda request, context: self.network.apply_action(request, context), validator=AllowAllValidator()
),
)
# pass through domain actions to the domain object
self.action_manager.add_action(
"domain",
Action(
func=lambda request, context: self.domain.apply_action(request, context), validator=AllowAllValidator()
),
)