diff --git a/docs/source/action_system.rst b/docs/source/action_system.rst index ef0fbd40..11b74abf 100644 --- a/docs/source/action_system.rst +++ b/docs/source/action_system.rst @@ -5,7 +5,7 @@ Actions System ============== -``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``ActionManager`` and ``Action``. +``SimComponent``s in the simulation are decoupled from the agent training logic. However, they still need a managed means of accepting requests to perform actions. For this, they use ``RequestManager`` and ``Action``. Just like other aspects of SimComponent, the actions are not managed centrally for the whole simulation, but instead they are dynamically created and updated based on the nodes, links, and other components that currently exist. This was achieved with the following design decisions: @@ -16,7 +16,7 @@ Just like other aspects of SimComponent, the actions are not managed centrally f 2. ``context`` - optional extra information that can be used to decide how to process the action. This is formatted as a dictionary. For example, if the action requires authentication, the context can include information about the user that initiated the request to decide if their permissions are sufficient. - request - The request is a list of strings which help specify who should handle the request. The strings in the request list help ActionManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: + The request is a list of strings which help specify who should handle the request. The strings in the request list help RequestManagers traverse the 'ownership tree' of SimComponent. The example given above would be handled in the following way: 1. ``Simulation`` receives `['network', 'node', '', 'service', '', 'restart']`. The first element of the action is ``network``, therefore it passes the action down to its network. @@ -25,22 +25,22 @@ Just like other aspects of SimComponent, the actions are not managed centrally f 3. ``Node`` receives `['service', '', 'restart']`. The first element of the action is ``service``, therefore the node looks at the service uuid and passes the rest of the action to the service with that uuid. 4. ``Service`` receives ``['restart']``. - Since ``restart`` is a defined action in the service's own ActionManager, the service performs a restart. + Since ``restart`` is a defined action in the service's own RequestManager, the service performs a restart. Techincal Detail ================ -This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.ActionManager`. +This system was achieved by implementing two classes, :py:class:`primaite.simulator.core.Action`, and :py:class:`primaite.simulator.core.RequestManager`. Action ------ -The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_action_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. +The ``Action`` object stores a reference to a method that performs the action, for example a node could have an action that stores a reference to ``self.turn_on()``. Techincally, this can be any callable that accepts `request, context` as it's parameters. In practice, this is often defined using ``lambda`` functions within a component's ``self._init_request_manager()`` method. Optionally, the ``Action`` object can also hold a validator that will permit/deny the action depending on context. -ActionManager +RequestManager ------------- -The ``ActionManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``ActionManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. +The ``RequestManager`` object stores a mapping between strings and actions. It is responsible for processing the ``request`` and passing it down the ownership tree. Techincally, the ``RequestManager`` is itself a callable that accepts `request, context` tuple, and so it can be chained with other action managers. A simple example without chaining can be seen in the :py:class:`primaite.simulator.file_system.file_system.File` class. @@ -48,18 +48,18 @@ A simple example without chaining can be seen in the :py:class:`primaite.simulat class File(FileSystemItemABC): ... - def _init_action_manager(self): + def _init_request_manager(self): ... - action_manager.add_action("scan", Action(func=lambda request, context: self.scan())) - action_manager.add_action("repair", Action(func=lambda request, context: self.repair())) - action_manager.add_action("restore", Action(func=lambda request, context: self.restore())) + request_manager.add_action("scan", Action(func=lambda request, context: self.scan())) + request_manager.add_action("repair", Action(func=lambda request, context: self.repair())) + request_manager.add_action("restore", Action(func=lambda request, context: self.restore())) *ellipses (``...``) used to omit code impertinent to this explanation* -Chaining ActionManagers +Chaining RequestManagers ----------------------- -Since the method for performing an action needs to accept `request, context` as parameters, and ActionManager itself is a callable that accepts `request, context` as parameters, it possible to use ActionManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an ActionManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another ActionManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. +Since the method for performing an action needs to accept `request, context` as parameters, and RequestManager itself is a callable that accepts `request, context` as parameters, it possible to use RequestManager as an action. In fact, that is how PrimAITE deals with traversing the ownership tree. Each time an RequestManager accepts a request, it pops the first elements and uses it to decide to which Action it should send the remaining request. However, the Action could have another RequestManager as it's function, therefore the request will be routed again. Each time the request is passed to a new action manager, the first element is popped. An example of how this works is in the :py:class:`primaite.simulator.network.hardware.base.Node` class. @@ -67,22 +67,22 @@ An example of how this works is in the :py:class:`primaite.simulator.network.har class Node(SimComponent): ... - def _init_action_manager(self): + def _init_request_manager(self): ... # a regular action which is processed by the Node itself - action_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) + request_manager.add_action("turn_on", Action(func=lambda request, context: self.turn_on())) # if the Node receives a request where the first word is 'service', it will use a dummy manager - # called self._service_action_manager to pass on the reqeust to the relevant service. This dummy + # called self._service_request_manager to pass on the reqeust to the relevant service. This dummy # manager is simply here to map the service UUID that that service's own action manager. This is # done because the next string after "service" is always the uuid of that service, so we need an - # actionmanager to pop that string before sending it onto the relevant service's ActionManager. - self._service_action_manager = ActionManager() - action_manager.add_action("service", Action(func=self._service_action_manager)) + # RequestManager to pop that string before sending it onto the relevant service's RequestManager. + self._service_request_manager = RequestManager() + request_manager.add_action("service", Action(func=self._service_request_manager)) ... def install_service(self, service): self.services[service.uuid] = service ... # Here, the service UUID is registered to allow passing actions between the node and the service. - self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) + self._service_request_manager.add_action(service.uuid, Action(func=service._request_manager)) diff --git a/docs/source/simulation_structure.rst b/docs/source/simulation_structure.rst index f3ef866c..20d2d2d3 100644 --- a/docs/source/simulation_structure.rst +++ b/docs/source/simulation_structure.rst @@ -42,15 +42,15 @@ snippet demonstrates usage of the ``ActionPermissionValidator``. .. code:: python - from primaite.simulator.core import Action, ActionManager, SimComponent + from primaite.simulator.core import Action, RequestManager, SimComponent from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator class Smartphone(SimComponent): name: str apps = [] - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() am.add_action( "reset_factory_settings", Action( diff --git a/src/primaite/notebooks/scratch.ipynb b/src/primaite/notebooks/scratch.ipynb index 1b94c5e4..4e873460 100644 --- a/src/primaite/notebooks/scratch.ipynb +++ b/src/primaite/notebooks/scratch.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -13,27 +13,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-19 12:47:23,225: Added node d3242ce1-43b7-40b7-86f3-f0473f1bbaec to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,227: Added node 67a2f88b-448c-416d-9fbd-02629347aabd to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,232: Added node 8d69c19e-69ad-41bd-9525-bdefb680a9e2 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,237: Added node c29ebde3-9748-4a97-b8a0-1673cbd53b62 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,248: Added node f734ac26-40b3-4380-ad37-f8782202a628 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,256: Added node 23785fbc-7d27-4697-bd06-937fcbb63e87 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,262: Added node 1ceaff86-bccd-4a06-81e0-0c616c803eab to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,356: Added node 854b2562-1dc2-4dd4-9e50-8f079ba2971c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,371: Added node 211e8c06-b3f9-48f1-9627-62a7e81e34d3 to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,376: Added node b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c to Network 49f27f36-ea3d-4b3c-8e21-87c8ed489fff\n", - "2023-09-19 12:47:23,380::ERROR::primaite.simulator.network.hardware.base::175::NIC 84:42:75:c8:10:28/192.168.10.110 cannot be enabled as it is not connected to a Link\n" - ] - } - ], + "outputs": [], "source": [ "net = arcd_uc2_network()" ] @@ -47,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -56,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -65,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -74,335 +56,20 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-09-19 12:47:26,764: Added service 6a8c0179-3ea6-48c1-bc97-259bb5853118 to node 1ceaff86-bccd-4a06-81e0-0c616c803eab\n" - ] - } - ], + "outputs": [], "source": [ "db_serv.install_service(db_svc)" ] }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '1ceaff86-bccd-4a06-81e0-0c616c803eab',\n", - " 'hostname': 'database_server',\n", - " 'operating_state': 1,\n", - " 'NICs': {'4b53abce-74ca-4015-868e-3c7dc2f29117': {'uuid': '4b53abce-74ca-4015-868e-3c7dc2f29117',\n", - " 'ip_adress': '192.168.1.14',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'mac_address': '7b:9e:4e:29:2b:ca',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'enabled': True}},\n", - " 'file_system': {'uuid': '0b831f3b-a3df-40cc-ab5b-21a3f22f4b68',\n", - " 'folders': {'root': {'uuid': 'a388f22b-0a4d-465d-b5f6-e98ff9564483',\n", - " 'name': 'root',\n", - " 'files': {},\n", - " 'is_quarantined': False},\n", - " 'database': {'uuid': 'c13d8734-9e01-42f6-84d7-4ea36424663d',\n", - " 'name': 'database',\n", - " 'files': {'database.db': {'uuid': '213ed482-6028-44ff-a6ab-45e5800ac1a1',\n", - " 'name': 'database.db',\n", - " 'size': 12288,\n", - " 'file_type': 'DB'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {},\n", - " 'services': {'6a8c0179-3ea6-48c1-bc97-259bb5853118': {'uuid': '6a8c0179-3ea6-48c1-bc97-259bb5853118',\n", - " 'health_state': 'GOOD',\n", - " 'health_state_red_view': 'GOOD',\n", - " 'criticality': 'LOWEST',\n", - " 'patching_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 1,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'port': 5432,\n", - " 'operating_state': 'STOPPED'}},\n", - " 'process': {}}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "db_serv.describe_state()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "act_tree = net._action_manager.get_action_tree()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "175" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(act_tree)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule'], ['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon'], ['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon'], ['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon'], ['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon'], ['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon'], ['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon'], ['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon'], ['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon'], ['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon'], ['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']]\n" - ] - } - ], - "source": [ - "print(act_tree)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'cbb4c7b4-d218-41e0-a871-64cf087afbbf', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'b26668a8-3ac4-4a0f-8c85-f7776d773f4b', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '2cb97c78-2819-48be-8ab1-a938c67731e7', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', 'af5fd9d3-de73-4595-a3c5-c79530415a82', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'enable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'nic', '5c9195e7-82f9-4486-9747-162fbcc31f93', 'disable']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'scan']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'checkhash']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'repair']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'restore']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'delete']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'file_system', 'folder', '1fd6018b-6619-4408-8a38-acff04f6febe', 'corrupt']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'scan']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'shutdown']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'startup']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'reset']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logon']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'logoff']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'add_rule']\n", - "['node', 'd3242ce1-43b7-40b7-86f3-f0473f1bbaec', 'acl', 'remove_rule']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'scan']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'checkhash']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'repair']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'restore']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'delete']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'file_system', 'folder', '92080f30-ee19-4083-ae03-f9305201911d', 'corrupt']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'scan']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'shutdown']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'startup']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'reset']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logon']\n", - "['node', '67a2f88b-448c-416d-9fbd-02629347aabd', 'logoff']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'scan']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'checkhash']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'repair']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'restore']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'delete']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'file_system', 'folder', '7141f9fd-9727-4159-b489-c0f5bec703fb', 'corrupt']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'scan']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'shutdown']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'startup']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'reset']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logon']\n", - "['node', '8d69c19e-69ad-41bd-9525-bdefb680a9e2', 'logoff']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'enable']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'nic', '77c037a4-5d66-4275-b34a-3690f0df1fb3', 'disable']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'scan']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'checkhash']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'repair']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'restore']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'delete']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'file_system', 'folder', 'ac6ca8f7-c8c5-4fc6-8cb0-70c664c9095f', 'corrupt']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'scan']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'shutdown']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'startup']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'reset']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logon']\n", - "['node', 'c29ebde3-9748-4a97-b8a0-1673cbd53b62', 'logoff']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'enable']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'nic', 'b6bb225c-5782-4374-8e9c-f8ae611c6300', 'disable']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'scan']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'checkhash']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'repair']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'restore']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'delete']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'file_system', 'folder', '99089070-8984-41d1-b9bf-bcf9da9e859b', 'corrupt']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'scan']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'shutdown']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'startup']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'reset']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logon']\n", - "['node', 'f734ac26-40b3-4380-ad37-f8782202a628', 'logoff']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'enable']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'nic', 'b6b13073-88ff-4153-ac3d-89475aaa8974', 'disable']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'scan']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'checkhash']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'repair']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'restore']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'delete']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'file_system', 'folder', 'bcab8f58-4d62-48db-924a-a5a45fa215cf', 'corrupt']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'scan']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'shutdown']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'startup']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'reset']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logon']\n", - "['node', '23785fbc-7d27-4697-bd06-937fcbb63e87', 'logoff']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'compromise']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'stop']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'start']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'pause']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'resume']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'restart']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'disable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'service', '6a8c0179-3ea6-48c1-bc97-259bb5853118', 'enable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'enable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'nic', '4b53abce-74ca-4015-868e-3c7dc2f29117', 'disable']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'a388f22b-0a4d-465d-b5f6-e98ff9564483', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'folder', 'c13d8734-9e01-42f6-84d7-4ea36424663d', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', 'ab96a3a6-1779-4789-99a1-fa31dd252121', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'checkhash']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'delete']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'repair']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'restore']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'file_system', 'file', '213ed482-6028-44ff-a6ab-45e5800ac1a1', 'corrupt']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'scan']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'shutdown']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'startup']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'reset']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logon']\n", - "['node', '1ceaff86-bccd-4a06-81e0-0c616c803eab', 'logoff']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'enable']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'nic', '229b368c-55f5-463b-bafc-d6a804aa0e85', 'disable']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'scan']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'checkhash']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'repair']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'restore']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'delete']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'file_system', 'folder', '7147bb84-83cd-4c53-ae33-ffb28ac29f03', 'corrupt']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'scan']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'shutdown']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'startup']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'reset']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logon']\n", - "['node', '854b2562-1dc2-4dd4-9e50-8f079ba2971c', 'logoff']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'enable']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'nic', 'e291339e-d212-4807-b475-e779042de3f5', 'disable']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'scan']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'checkhash']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'repair']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'restore']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'delete']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'file_system', 'folder', '287266f2-395a-401c-85b3-4b67e05642d3', 'corrupt']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'scan']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'shutdown']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'startup']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'reset']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logon']\n", - "['node', '211e8c06-b3f9-48f1-9627-62a7e81e34d3', 'logoff']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'enable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '2b2a29e6-f56f-4328-9376-34d0cdb30d8d', 'disable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'enable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'nic', '3b2d0133-9fa0-4872-a449-9f2bb0337b49', 'disable']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'scan']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'checkhash']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'repair']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'restore']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'delete']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'file_system', 'folder', '34eb8fde-6450-4d87-8136-65c35f11b9a9', 'corrupt']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'scan']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'shutdown']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'startup']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'reset']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logon']\n", - "['node', 'b2aea8d0-a7fe-4d81-a63d-c40851ab1d9c', 'logoff']\n" - ] - } - ], - "source": [ - "for a in act_tree:\n", - " print(a)\n", - "# simController.apply_action(\n", - "# {\n", - "# 'network':'', \n", - "# 'node': '26e189bb-442e-4f73-ab7a-1c4dd162e986', \n", - "# 'nic': 'eb6dfd45-d688-47cf-b061-5f45820a6bc7', \n", - "# 'verb': 'enable', \n", - "# 'options':{'...':'...'}\n", - "# })\n", - "\n", - "# a = {\n", - "# 'target_type': 'network',\n", - "# 'target_options': {\n", - "# 'identifier': '',\n", - "# 'target_type': '',\n", - "# 'target_options': {\n", - "# 'identifier': '',\n", - " \n", - "# }\n", - "# }\n", - "# }\n", - "# # ^ do something like this where the requests are k:v pairs instead, have a simple/similar approach " + "db_serv.describe_state()" ] }, { diff --git a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb index a2e1550c..d9742b50 100644 --- a/src/primaite/simulator/_package_data/create-simulation_demo.ipynb +++ b/src/primaite/simulator/_package_data/create-simulation_demo.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -36,24 +36,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", - " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", - " 'nodes': {},\n", - " 'links': {}},\n", - " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6', 'accounts': {}}}" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim = Simulation()\n", "net = my_sim.network\n", @@ -69,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -78,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -97,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -106,20 +91,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-08-24 13:06:28,617: NIC cc:be:ec:43:a6:4c/130.1.1.1 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", - "2023-08-24 13:06:28,618: SwitchPort 79:2b:4a:70:c3:50 connected to Link cc:be:ec:43:a6:4c/130.1.1.1<-->79:2b:4a:70:c3:50\n", - "2023-08-24 13:06:28,619: NIC c2:1e:48:e1:a4:ad/130.1.1.2 connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n", - "2023-08-24 13:06:28,620: SwitchPort 1a:2d:12:38:80:2f connected to Link c2:1e:48:e1:a4:ad/130.1.1.2<-->1a:2d:12:38:80:2f\n" - ] - } - ], + "outputs": [], "source": [ "my_swtich = Switch(hostname=\"switch1\", num_ports=12)\n", "net.add_node(my_swtich)\n", @@ -145,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -155,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -165,20 +139,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "File(uuid='7d56a563-ecc0-4011-8c97-240dd6c885c0', name='favicon.ico', size=40.0, file_type=, action_manager=None)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_server_folder = my_server.file_system.create_folder(\"static\")\n", "my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)" @@ -193,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -209,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -218,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -234,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -243,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -260,193 +223,18 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'uuid': '2ef348c6-32e5-4c5c-83b7-3b82d0b6123b',\n", - " 'network': {'uuid': 'dd2d1a02-d461-4505-8bbd-fd0681750175',\n", - " 'nodes': {'2f03b32b-7290-4921-8670-faebe4a19d63': {'uuid': '2f03b32b-7290-4921-8670-faebe4a19d63',\n", - " 'hostname': 'primaite_pc',\n", - " 'operating_state': 0,\n", - " 'NICs': {'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b': {'uuid': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", - " 'ip_adress': '130.1.1.1',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'cc:be:ec:43:a6:4c',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': '0b7206af-3e0a-41b0-8115-ae9e0dbbcd81',\n", - " 'folders': {'c161bc7c-9abd-4666-9b49-2745fdb65ebe': {'uuid': 'c161bc7c-9abd-4666-9b49-2745fdb65ebe',\n", - " 'name': 'downloads',\n", - " 'size': 1000.0,\n", - " 'files': {'f807d777-d167-4f37-9f9b-ced634af6ed5': {'uuid': 'f807d777-d167-4f37-9f9b-ced634af6ed5',\n", - " 'name': 'firefox_installer.zip',\n", - " 'size': 1000.0,\n", - " 'file_type': 'ZIP'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {'ea466b2f-1ed5-49fd-9579-44852bff684d': {'uuid': 'ea466b2f-1ed5-49fd-9579-44852bff684d',\n", - " 'health_state': 'GOOD',\n", - " 'health_state_red_view': 'GOOD',\n", - " 'criticality': 'MEDIUM',\n", - " 'patching_count': 0,\n", - " 'scanning_count': 0,\n", - " 'revealed_to_red': False,\n", - " 'installing_count': 0,\n", - " 'max_sessions': 1,\n", - " 'tcp': True,\n", - " 'udp': True,\n", - " 'ports': ['HTTP'],\n", - " 'opearting_state': 'RUNNING',\n", - " 'execution_control_status': 'manual',\n", - " 'num_executions': 0,\n", - " 'groups': []}},\n", - " 'services': {},\n", - " 'process': {}},\n", - " 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc': {'uuid': 'e9afc0bc-fb21-48a3-9868-2ede6a3181dc',\n", - " 'hostname': 'google_server',\n", - " 'operating_state': 0,\n", - " 'NICs': {'956ce240-8fb3-4fde-8635-ac4ea601a582': {'uuid': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", - " 'ip_adress': '130.1.1.2',\n", - " 'subnet_mask': '255.255.255.0',\n", - " 'gateway': '130.1.1.255',\n", - " 'mac_address': 'c2:1e:48:e1:a4:ad',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'wake_on_lan': False,\n", - " 'dns_servers': [],\n", - " 'enabled': False}},\n", - " 'file_system': {'uuid': 'c3f99c30-b493-4fb6-b13e-d2005d851b59',\n", - " 'folders': {'869eda49-21f2-4fc1-8681-78725cdd5c70': {'uuid': '869eda49-21f2-4fc1-8681-78725cdd5c70',\n", - " 'name': 'static',\n", - " 'size': 0,\n", - " 'files': {},\n", - " 'is_quarantined': False},\n", - " '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e': {'uuid': '9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e',\n", - " 'name': 'root',\n", - " 'size': 40.0,\n", - " 'files': {'7d56a563-ecc0-4011-8c97-240dd6c885c0': {'uuid': '7d56a563-ecc0-4011-8c97-240dd6c885c0',\n", - " 'name': 'favicon.ico',\n", - " 'size': 40.0,\n", - " 'file_type': 'PNG'}},\n", - " 'is_quarantined': False}}},\n", - " 'applications': {},\n", - " 'services': {},\n", - " 'process': {}},\n", - " '47814452-ef47-4e6b-9087-796c438d4698': {'uuid': '47814452-ef47-4e6b-9087-796c438d4698',\n", - " 'num_ports': 12,\n", - " 'ports': {1: {'uuid': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", - " 'mac_address': '79:2b:4a:70:c3:50',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 2: {'uuid': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", - " 'mac_address': '1a:2d:12:38:80:2f',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 3: {'uuid': '1aa75a3c-01f1-4293-9894-5396fa412690',\n", - " 'mac_address': 'd1:7b:36:c1:82:c1',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 4: {'uuid': 'fe6c9f44-59d5-403e-973a-6f19fce7b9b9',\n", - " 'mac_address': 'e3:6b:cc:0c:98:9b',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 5: {'uuid': 'e9e83e37-8537-4884-98a6-87017540078f',\n", - " 'mac_address': '32:09:c0:4a:f1:20',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 6: {'uuid': '747f2cd3-8902-4da8-8829-b0b53fe79735',\n", - " 'mac_address': 'e8:20:0b:04:b8:76',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 7: {'uuid': '88ed129e-0ddb-4d29-ba3c-58d81efe240e',\n", - " 'mac_address': '7f:b4:f4:2e:b6:71',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 8: {'uuid': '6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3',\n", - " 'mac_address': 'f6:22:2d:24:b9:71',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 9: {'uuid': 'b2bfc006-6a6b-4701-a75a-27954592d429',\n", - " 'mac_address': 'b6:a5:92:a5:aa:1b',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 10: {'uuid': '3c607386-87a2-4d0b-ac04-449416ca5b1f',\n", - " 'mac_address': 'b3:75:7d:ce:88:0a',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 11: {'uuid': '590002c8-27fa-4c31-b17b-7b89dbf8cdf8',\n", - " 'mac_address': 'c0:25:a6:64:52:8e',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False},\n", - " 12: {'uuid': 'b7e25eed-547a-4c17-8cb9-8b976ce4bbd9',\n", - " 'mac_address': '98:50:96:47:ca:bc',\n", - " 'speed': 100,\n", - " 'mtu': 1500,\n", - " 'enabled': False}},\n", - " 'mac_address_table': {}}},\n", - " 'links': {'a51a4435-20ae-43cf-a151-26e824968b3d': {'uuid': 'a51a4435-20ae-43cf-a151-26e824968b3d',\n", - " 'endpoint_a': 'e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b',\n", - " 'endpoint_b': 'b76fe86f-bb92-4346-8e83-217a2fb0bc67',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0},\n", - " 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d': {'uuid': 'ae3486e5-f78e-4092-96d1-d7e8176f2b7d',\n", - " 'endpoint_a': '956ce240-8fb3-4fde-8635-ac4ea601a582',\n", - " 'endpoint_b': '6f8fc6e7-76a4-441a-b7af-441edbdcc6ac',\n", - " 'bandwidth': 100.0,\n", - " 'current_load': 0.0}}},\n", - " 'domain': {'uuid': 'ae0423ee-51fa-41e7-be80-c642b39707f6',\n", - " 'accounts': {'917eda28-9a67-4449-bddd-87e2141a3162': {'uuid': '917eda28-9a67-4449-bddd-87e2141a3162',\n", - " 'num_logons': 0,\n", - " 'num_logoffs': 0,\n", - " 'num_group_changes': 0,\n", - " 'username': 'admin',\n", - " 'password': 'admin12',\n", - " 'account_type': 'USER',\n", - " 'enabled': True}}}}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_sim.describe_state()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'{\"uuid\": \"2ef348c6-32e5-4c5c-83b7-3b82d0b6123b\", \"network\": {\"uuid\": \"dd2d1a02-d461-4505-8bbd-fd0681750175\", \"nodes\": {\"2f03b32b-7290-4921-8670-faebe4a19d63\": {\"uuid\": \"2f03b32b-7290-4921-8670-faebe4a19d63\", \"hostname\": \"primaite_pc\", \"operating_state\": 0, \"NICs\": {\"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\": {\"uuid\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"ip_adress\": \"130.1.1.1\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"cc:be:ec:43:a6:4c\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"0b7206af-3e0a-41b0-8115-ae9e0dbbcd81\", \"folders\": {\"c161bc7c-9abd-4666-9b49-2745fdb65ebe\": {\"uuid\": \"c161bc7c-9abd-4666-9b49-2745fdb65ebe\", \"name\": \"downloads\", \"size\": 1000.0, \"files\": {\"f807d777-d167-4f37-9f9b-ced634af6ed5\": {\"uuid\": \"f807d777-d167-4f37-9f9b-ced634af6ed5\", \"name\": \"firefox_installer.zip\", \"size\": 1000.0, \"file_type\": \"ZIP\"}}, \"is_quarantined\": false}}}, \"applications\": {\"ea466b2f-1ed5-49fd-9579-44852bff684d\": {\"uuid\": \"ea466b2f-1ed5-49fd-9579-44852bff684d\", \"health_state\": \"GOOD\", \"health_state_red_view\": \"GOOD\", \"criticality\": \"MEDIUM\", \"patching_count\": 0, \"scanning_count\": 0, \"revealed_to_red\": false, \"installing_count\": 0, \"max_sessions\": 1, \"tcp\": true, \"udp\": true, \"ports\": [\"HTTP\"], \"opearting_state\": \"RUNNING\", \"execution_control_status\": \"manual\", \"num_executions\": 0, \"groups\": []}}, \"services\": {}, \"process\": {}}, \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\": {\"uuid\": \"e9afc0bc-fb21-48a3-9868-2ede6a3181dc\", \"hostname\": \"google_server\", \"operating_state\": 0, \"NICs\": {\"956ce240-8fb3-4fde-8635-ac4ea601a582\": {\"uuid\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"ip_adress\": \"130.1.1.2\", \"subnet_mask\": \"255.255.255.0\", \"gateway\": \"130.1.1.255\", \"mac_address\": \"c2:1e:48:e1:a4:ad\", \"speed\": 100, \"mtu\": 1500, \"wake_on_lan\": false, \"dns_servers\": [], \"enabled\": false}}, \"file_system\": {\"uuid\": \"c3f99c30-b493-4fb6-b13e-d2005d851b59\", \"folders\": {\"869eda49-21f2-4fc1-8681-78725cdd5c70\": {\"uuid\": \"869eda49-21f2-4fc1-8681-78725cdd5c70\", \"name\": \"static\", \"size\": 0, \"files\": {}, \"is_quarantined\": false}, \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\": {\"uuid\": \"9fbe0e41-0d6a-4142-9c73-9c0de2dbde6e\", \"name\": \"root\", \"size\": 40.0, \"files\": {\"7d56a563-ecc0-4011-8c97-240dd6c885c0\": {\"uuid\": \"7d56a563-ecc0-4011-8c97-240dd6c885c0\", \"name\": \"favicon.ico\", \"size\": 40.0, \"file_type\": \"PNG\"}}, \"is_quarantined\": false}}}, \"applications\": {}, \"services\": {}, \"process\": {}}, \"47814452-ef47-4e6b-9087-796c438d4698\": {\"uuid\": \"47814452-ef47-4e6b-9087-796c438d4698\", \"num_ports\": 12, \"ports\": {\"1\": {\"uuid\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"mac_address\": \"79:2b:4a:70:c3:50\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"2\": {\"uuid\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"mac_address\": \"1a:2d:12:38:80:2f\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"3\": {\"uuid\": \"1aa75a3c-01f1-4293-9894-5396fa412690\", \"mac_address\": \"d1:7b:36:c1:82:c1\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"4\": {\"uuid\": \"fe6c9f44-59d5-403e-973a-6f19fce7b9b9\", \"mac_address\": \"e3:6b:cc:0c:98:9b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"5\": {\"uuid\": \"e9e83e37-8537-4884-98a6-87017540078f\", \"mac_address\": \"32:09:c0:4a:f1:20\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"6\": {\"uuid\": \"747f2cd3-8902-4da8-8829-b0b53fe79735\", \"mac_address\": \"e8:20:0b:04:b8:76\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"7\": {\"uuid\": \"88ed129e-0ddb-4d29-ba3c-58d81efe240e\", \"mac_address\": \"7f:b4:f4:2e:b6:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"8\": {\"uuid\": \"6c1a4c3c-25d8-46f6-98a8-54073d0ca0d3\", \"mac_address\": \"f6:22:2d:24:b9:71\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"9\": {\"uuid\": \"b2bfc006-6a6b-4701-a75a-27954592d429\", \"mac_address\": \"b6:a5:92:a5:aa:1b\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"10\": {\"uuid\": \"3c607386-87a2-4d0b-ac04-449416ca5b1f\", \"mac_address\": \"b3:75:7d:ce:88:0a\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"11\": {\"uuid\": \"590002c8-27fa-4c31-b17b-7b89dbf8cdf8\", \"mac_address\": \"c0:25:a6:64:52:8e\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}, \"12\": {\"uuid\": \"b7e25eed-547a-4c17-8cb9-8b976ce4bbd9\", \"mac_address\": \"98:50:96:47:ca:bc\", \"speed\": 100, \"mtu\": 1500, \"enabled\": false}}, \"mac_address_table\": {}}}, \"links\": {\"a51a4435-20ae-43cf-a151-26e824968b3d\": {\"uuid\": \"a51a4435-20ae-43cf-a151-26e824968b3d\", \"endpoint_a\": \"e07e2a7f-b09f-4bd8-8e92-cffbf1f2270b\", \"endpoint_b\": \"b76fe86f-bb92-4346-8e83-217a2fb0bc67\", \"bandwidth\": 100.0, \"current_load\": 0.0}, \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\": {\"uuid\": \"ae3486e5-f78e-4092-96d1-d7e8176f2b7d\", \"endpoint_a\": \"956ce240-8fb3-4fde-8635-ac4ea601a582\", \"endpoint_b\": \"6f8fc6e7-76a4-441a-b7af-441edbdcc6ac\", \"bandwidth\": 100.0, \"current_load\": 0.0}}}, \"domain\": {\"uuid\": \"ae0423ee-51fa-41e7-be80-c642b39707f6\", \"accounts\": {\"917eda28-9a67-4449-bddd-87e2141a3162\": {\"uuid\": \"917eda28-9a67-4449-bddd-87e2141a3162\", \"num_logons\": 0, \"num_logoffs\": 0, \"num_group_changes\": 0, \"username\": \"admin\", \"password\": \"admin12\", \"account_type\": \"USER\", \"enabled\": true}}}}'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import json\n", "json.dumps(my_sim.describe_state())" diff --git a/src/primaite/simulator/core.py b/src/primaite/simulator/core.py index a292be18..914b798e 100644 --- a/src/primaite/simulator/core.py +++ b/src/primaite/simulator/core.py @@ -11,9 +11,9 @@ from primaite import getLogger _LOGGER = getLogger(__name__) -class ActionPermissionValidator(BaseModel): +class RequestPermissionValidator(BaseModel): """ - Base class for action validators. + Base class for request validators. The permissions manager is designed to be generic. So, although in the first instance the permissions are evaluated purely on membership to AccountGroup, this class can support validating permissions based on any @@ -22,130 +22,127 @@ class ActionPermissionValidator(BaseModel): @abstractmethod def __call__(self, request: List[str], context: Dict) -> bool: - """Use the request and context paramters to decide whether the action should be permitted.""" + """Use the request and context paramters to decide whether the request should be permitted.""" pass -class AllowAllValidator(ActionPermissionValidator): - """Always allows the action.""" +class AllowAllValidator(RequestPermissionValidator): + """Always allows the request.""" def __call__(self, request: List[str], context: Dict) -> bool: - """Always allow the action.""" + """Always allow the request.""" return True -class Action(BaseModel): +class RequestType(BaseModel): """ - This object stores data related to a single action. + This object stores data related to a single request type. - This includes the callable that can execute the action request, and the validator that will decide whether - the action can be performed or not. + This includes the callable that can execute the request, and the validator that will decide whether + the request can be performed or not. """ func: Callable[[List[str], Dict], None] """ ``func`` is a function that accepts a request and a context dict. Typically this would be a lambda function - that invokes a class method of your SimComponent. For example if the component is a node and the action is for + that invokes a class method of your SimComponent. For example if the component is a node and the request type is for turning it off, then the SimComponent should have a turn_off(self) method that does not need to accept any args. - Then, this Action will be given something like ``func = lambda request, context: self.turn_off()``. + Then, this request will be given something like ``func = lambda request, context: self.turn_off()``. - ``func`` can also be another action manager, since ActionManager is a callable with a signature that matches what is + ``func`` can also be another request manager, since RequestManager is a callable with a signature that matches what is expected by ``func``. """ - validator: ActionPermissionValidator = AllowAllValidator() + validator: RequestPermissionValidator = AllowAllValidator() """ - ``validator`` is an instance of `ActionPermissionValidator`. This is essentially a callable that + ``validator`` is an instance of ``RequestPermissionValidator``. This is essentially a callable that accepts `request` and `context` and returns a boolean to represent whether the permission is granted to perform - the action. The default validator will allow + the request. The default validator will allow """ -# TODO: maybe this can be renamed to something like action selector? -# Because there are two ways it's used, to select from a list of action verbs, or to select a child object to which to -# forward the request. -class ActionManager(BaseModel): +class RequestManager(BaseModel): """ - ActionManager is used by `SimComponent` instances to keep track of actions. + RequestManager is used by `SimComponent` instances to keep track of requests. - Its main purpose is to be a lookup from action name to action function and corresponding validation function. This - class is responsible for providing a consistent API for processing actions as well as helpful error messages. + Its main purpose is to be a lookup from request name to request function and corresponding validation function. This + class is responsible for providing a consistent API for processing requests as well as helpful error messages. """ - actions: Dict[str, Action] = {} - """maps action verb to an action object.""" + request_types: Dict[str, RequestType] = {} + """maps request name to an RequestType object.""" def __call__(self, request: Callable[[List[str], Dict], None], context: Dict) -> None: """ - Process an action request. + Process an request request. - :param request: A list of strings which specify what action to take. The first string must be one of the allowed - actions, i.e. it must be a key of self.actions. The subsequent strings in the list are passed as parameters - to the action function. + :param request: A list of strings describing the request. The first string must be one of the allowed + request names, i.e. it must be a key of self.request_types. The subsequent strings in the list are passed as + parameters to the request function. :type request: List[str] :param context: Dictionary of additional information necessary to process or validate the request. :type context: Dict - :raises RuntimeError: If the request parameter does not have a valid action identifier as the first item. + :raises RuntimeError: If the request parameter does not have a valid request name as the first item. """ - action_key = request[0] + request_key = request[0] - if action_key not in self.actions: + if request_key not in self.request_types: msg = ( - f"Action request {request} could not be processed because {action_key} is not a valid action", - "within this ActionManager", + f"Request {request} could not be processed because {request_key} is not a valid request name", + "within this RequestManager", ) _LOGGER.error(msg) raise RuntimeError(msg) - action = self.actions[action_key] - action_options = request[1:] + request_type = self.request_types[request_key] + request_options = request[1:] - if not action.validator(action_options, context): - _LOGGER.debug(f"Action request {request} was denied due to insufficient permissions") + if not request_type.validator(request_options, context): + _LOGGER.debug(f"Request {request} was denied due to insufficient permissions") return - action.func(action_options, context) + request_type.func(request_options, context) - def add_action(self, name: str, action: Action) -> None: + def add_request(self, name: str, request_type: RequestType) -> None: """ - Add an action to this action manager. + Add a request type to this request manager. - :param name: The string associated to this action. + :param name: The string associated to this request. :type name: str - :param action: Action object. - :type action: Action + :param request_type: Request type object which contains information about how to resolve request. + :type request_type: RequestType """ - if name in self.actions: - msg = f"Attempted to register an action but the action name {name} is already taken." + if name in self.request_types: + msg = f"Attempted to register a request but the request name {name} is already taken." _LOGGER.error(msg) raise RuntimeError(msg) - self.actions[name] = action + self.request_types[name] = request_type - def remove_action(self, name: str) -> None: + def remove_request(self, name: str) -> None: """ - Remove an action from this manager. + Remove a request from this manager. - :param name: name identifier of the action + :param name: name identifier of the request :type name: str """ - if name not in self.actions: - msg = f"Attempted to remove action {name} from action manager, but it was not registered." + if name not in self.request_types: + msg = f"Attempted to remove request {name} from request manager, but it was not registered." _LOGGER.error(msg) raise RuntimeError(msg) - self.actions.pop(name) + self.request_types.pop(name) - def get_action_tree(self) -> List[List[str]]: - """Recursively generate action tree for this component.""" - actions = [] - for act_name, act in self.actions.items(): - if isinstance(act.func, ActionManager): - sub_actions = act.func.get_action_tree() - sub_actions = [[act_name] + a for a in sub_actions] - actions.extend(sub_actions) + def get_request_types_recursively(self) -> List[List[str]]: + """Recursively generate request tree for this component.""" + requests = [] + for req_name, req in self.request_types.items(): + if isinstance(req.func, RequestManager): + sub_requests = req.func.get_request_types_recursively() + sub_requests = [[req_name] + a for a in sub_requests] + requests.extend(sub_requests) else: - actions.append([act_name]) - return actions + requests.append([req_name]) + return requests class SimComponent(BaseModel): @@ -161,30 +158,30 @@ class SimComponent(BaseModel): if not kwargs.get("uuid"): kwargs["uuid"] = str(uuid4()) super().__init__(**kwargs) - self._action_manager: ActionManager = self._init_action_manager() + self._request_manager: RequestManager = self._init_request_manager() self._parent: Optional["SimComponent"] = None - def _init_action_manager(self) -> ActionManager: + def _init_request_manager(self) -> RequestManager: """ - Initialise the action manager for this component. + Initialise the request manager for this component. - When using a hierarchy of components, the child classes should call the parent class's _init_action_manager and - add additional actions on top of the existing generic ones. + When using a hierarchy of components, the child classes should call the parent class's _init_request_manager and + add additional requests on top of the existing generic ones. Example usage for inherited classes: ..code::python class WebBrowser(Application): - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() # all actions generic to any Application get initialised - am.add_action(...) # initialise any actions specific to the web browser + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # all requests generic to any Application get initialised + am.add_request(...) # initialise any requests specific to the web browser return am - :return: Actiona manager object belonging to this sim component. - :rtype: ActionManager + :return: Request manager object belonging to this sim component. + :rtype: RequestManager """ - return ActionManager() + return RequestManager() @abstractmethod def describe_state(self) -> Dict: @@ -200,27 +197,27 @@ class SimComponent(BaseModel): } return state - def apply_action(self, action: List[str], context: Dict = {}) -> None: + def apply_request(self, request: List[str], context: Dict = {}) -> None: """ - Apply an action to a simulation component. Action data is passed in as a 'namespaced' list of strings. + Apply a request to a simulation component. Request data is passed in as a 'namespaced' list of strings. - If the list only has one element, the action is intended to be applied directly to this object. If the list has - multiple entries, the action is passed to the child of this object specified by the first one or two entries. + If the list only has one element, the request is intended to be applied directly to this object. If the list has + multiple entries, the request is passed to the child of this object specified by the first one or two entries. This is essentially a namespace. - For example, ["turn_on",] is meant to apply an action of 'turn on' to this component. + For example, ["turn_on",] is meant to apply a request of 'turn on' to this component. However, ["services", "email_client", "turn_on"] is meant to 'turn on' this component's email client service. - :param action: List describing the action to apply to this object. - :type action: List[str] + :param request: List describing the request to apply to this object. + :type request: List[str] - :param: context: Dict containing context for actions + :param: context: Dict containing context for requests :type context: Dict """ - if self._action_manager is None: + if self._request_manager is None: return - self._action_manager(action, context) + self._request_manager(request, context) def apply_timestep(self, timestep: int) -> None: """ diff --git a/src/primaite/simulator/domain/controller.py b/src/primaite/simulator/domain/controller.py index cd0fe9de..66900327 100644 --- a/src/primaite/simulator/domain/controller.py +++ b/src/primaite/simulator/domain/controller.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Dict, Final, List, Literal, Tuple -from primaite.simulator.core import Action, ActionManager, ActionPermissionValidator, SimComponent +from primaite.simulator.core import RequestManager, RequestPermissionValidator, RequestType, SimComponent from primaite.simulator.domain.account import Account, AccountType @@ -43,10 +43,10 @@ class AccountGroup(Enum): "For full access" -class GroupMembershipValidator(ActionPermissionValidator): +class GroupMembershipValidator(RequestPermissionValidator): """Permit actions based on group membership.""" - allowed_groups:List[AccountGroup] + allowed_groups: List[AccountGroup] def __call__(self, request: List[str], context: Dict) -> bool: """Permit the action if the request comes from an account which belongs to the right group.""" @@ -79,14 +79,14 @@ class DomainController(SimComponent): def __init__(self, **kwargs): super().__init__(**kwargs) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # Action 'account' matches requests like: # ['account', '', *account_action] - am.add_action( + am.add_request( "account", - Action( - func=lambda request, context: self.accounts[request.pop(0)].apply_action(request, context), + RequestType( + func=lambda request, context: self.accounts[request.pop(0)].apply_request(request, context), validator=GroupMembershipValidator(allowed_groups=[AccountGroup.DOMAIN_ADMIN]), ), ) diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 8d981100..5da4eca8 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -9,7 +9,7 @@ from typing import Dict, Optional from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_type import FileType, get_file_type_from_extension from primaite.simulator.system.core.sys_log import SysLog @@ -94,14 +94,14 @@ class FileSystem(SimComponent): if not self.folders: self.create_folder("root") - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - self._folder_action_manager = ActionManager() - am.add_action("folder", Action(func=self._folder_action_manager)) + self._folder_request_manager = RequestManager() + am.add_request("folder", RequestType(func=self._folder_request_manager)) - self._file_action_manager = ActionManager() - am.add_action("file", Action(func=self._file_action_manager)) + self._file_request_manager = RequestManager() + am.add_request("file", RequestType(func=self._file_request_manager)) return am @@ -165,7 +165,7 @@ class FileSystem(SimComponent): self.folders[folder.uuid] = folder self._folders_by_name[folder.name] = folder self.sys_log.info(f"Created folder /{folder.name}") - self._folder_action_manager.add_action(folder.uuid, Action(func=folder._action_manager)) + self._folder_request_manager.add_request(folder.uuid, RequestType(func=folder._request_manager)) return folder def delete_folder(self, folder_name: str): @@ -184,7 +184,7 @@ class FileSystem(SimComponent): self.folders.pop(folder.uuid) self._folders_by_name.pop(folder.name) self.sys_log.info(f"Deleted folder /{folder.name} and its contents") - self._folder_action_manager.remove_action(folder.uuid) + self._folder_request_manager.remove_request(folder.uuid) else: _LOGGER.debug(f"Cannot delete folder as it does not exist: {folder_name}") @@ -226,7 +226,7 @@ class FileSystem(SimComponent): ) folder.add_file(file) self.sys_log.info(f"Created file /{file.path}") - self._file_action_manager.add_action(file.uuid, Action(func=file._action_manager)) + self._file_request_manager.add_request(file.uuid, RequestType(func=file._request_manager)) return file def get_file(self, folder_name: str, file_name: str) -> Optional[File]: @@ -254,7 +254,7 @@ class FileSystem(SimComponent): file = folder.get_file(file_name) if file: folder.remove_file(file) - self._file_action_manager.remove_action(file.uuid) + self._file_request_manager.remove_request(file.uuid) self.sys_log.info(f"Deleted file /{file.path}") def move_file(self, src_folder_name: str, src_file_name: str, dst_folder_name: str): @@ -332,15 +332,15 @@ class Folder(FileSystemItemABC): is_quarantined: bool = False "Flag that marks the folder as quarantined if true." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request return am @@ -509,15 +509,15 @@ class File(FileSystemItemABC): with open(self.sim_path, mode="a"): pass - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("checkhash", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("delete", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("repair", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("restore", Action(func=lambda request, context: ...)) # TODO implement action - am.add_action("corrupt", Action(func=lambda request, context: ...)) # TODO implement action + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("checkhash", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("delete", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("repair", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("restore", RequestType(func=lambda request, context: ...)) # TODO implement request + am.add_request("corrupt", RequestType(func=lambda request, context: ...)) # TODO implement request return am diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index e0384b5e..bc717641 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -6,7 +6,7 @@ from networkx import MultiGraph from prettytable import MARKDOWN, PrettyTable from primaite import getLogger -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.router import Router @@ -37,18 +37,18 @@ class Network(SimComponent): Initialise the network. Constructs the network and sets up its initial state including - the action manager and an empty MultiGraph for topology representation. + the request manager and an empty MultiGraph for topology representation. """ super().__init__(**kwargs) self._nx_graph = MultiGraph() - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - self._node_action_manager = ActionManager() - am.add_action( + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + self._node_request_manager = RequestManager() + am.add_request( "node", - Action(func=self._node_action_manager), + RequestType(func=self._node_request_manager), ) return am @@ -182,7 +182,7 @@ class Network(SimComponent): node.parent = self self._nx_graph.add_node(node.hostname) _LOGGER.info(f"Added node {node.uuid} to Network {self.uuid}") - self._node_action_manager.add_action(name=node.uuid, action=Action(func=node._action_manager)) + self._node_request_manager.add_request(name=node.uuid, request_type=RequestType(func=node._request_manager)) def get_node_by_hostname(self, hostname: str) -> Optional[Node]: """ @@ -216,7 +216,7 @@ class Network(SimComponent): break node.parent = None _LOGGER.info(f"Removed node {node.uuid} from network {self.uuid}") - self._node_action_manager.remove_action(name=node.uuid) + self._node_request_manager.remove_request(name=node.uuid) def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None: """ diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 2fa917a5..cb3e398b 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -12,7 +12,7 @@ from prettytable import MARKDOWN, PrettyTable from primaite import getLogger from primaite.exceptions import NetworkError from primaite.simulator import SIM_OUTPUT -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.account import Account from primaite.simulator.file_system.file_system import FileSystem from primaite.simulator.network.protocols.arp import ARPEntry, ARPPacket @@ -144,11 +144,11 @@ class NIC(SimComponent): ) return state - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() - am.add_action("enable", Action(func=lambda request, context: self.enable())) - am.add_action("disable", Action(func=lambda request, context: self.disable())) + am.add_request("enable", RequestType(func=lambda request, context: self.enable())) + am.add_request("disable", RequestType(func=lambda request, context: self.disable())) return am @@ -946,31 +946,31 @@ class Node(SimComponent): self.session_manager.software_manager = self.software_manager self._install_system_software() - def _init_action_manager(self) -> ActionManager: + def _init_request_manager(self) -> RequestManager: # TODO: I see that this code is really confusing and hard to read right now... I think some of these things will # need a better name and better documentation. - am = super()._init_action_manager() - # since there are potentially many services, create an action manager that can map service name - self._service_action_manager = ActionManager() - am.add_action("service", Action(func=self._service_action_manager)) - self._nic_action_manager = ActionManager() - am.add_action("nic", Action(func=self._nic_action_manager)) + am = super()._init_request_manager() + # since there are potentially many services, create an request manager that can map service name + self._service_request_manager = RequestManager() + am.add_request("service", RequestType(func=self._service_request_manager)) + self._nic_request_manager = RequestManager() + am.add_request("nic", RequestType(func=self._nic_request_manager)) - am.add_action("file_system", Action(func=self.file_system._action_manager)) + am.add_request("file_system", RequestType(func=self.file_system._request_manager)) # currently we don't have any applications nor processes, so these will be empty - self._process_action_manager = ActionManager() - am.add_action("process", Action(func=self._process_action_manager)) - self._application_action_manager = ActionManager() - am.add_action("application", Action(func=self._application_action_manager)) + self._process_request_manager = RequestManager() + am.add_request("process", RequestType(func=self._process_request_manager)) + self._application_request_manager = RequestManager() + am.add_request("application", RequestType(func=self._application_request_manager)) - am.add_action("scan", Action(func=lambda request, context: ...)) # TODO implement OS scan + am.add_request("scan", RequestType(func=lambda request, context: ...)) # TODO implement OS scan - am.add_action("shutdown", Action(func=lambda request, context: self.power_off())) - am.add_action("startup", Action(func=lambda request, context: self.power_on())) - am.add_action("reset", Action(func=lambda request, context: ...)) # TODO implement node reset - am.add_action("logon", Action(func=lambda request, context: ...)) # TODO implement logon action - am.add_action("logoff", Action(func=lambda request, context: ...)) # TODO implement logoff action + am.add_request("shutdown", RequestType(func=lambda request, context: self.power_off())) + am.add_request("startup", RequestType(func=lambda request, context: self.power_on())) + am.add_request("reset", RequestType(func=lambda request, context: ...)) # TODO implement node reset + am.add_request("logon", RequestType(func=lambda request, context: ...)) # TODO implement logon request + am.add_request("logoff", RequestType(func=lambda request, context: ...)) # TODO implement logoff request return am @@ -1071,7 +1071,7 @@ class Node(SimComponent): self.sys_log.info(f"Connected NIC {nic}") if self.operating_state == NodeOperatingState.ON: nic.enable() - self._nic_action_manager.add_action(nic.uuid, Action(func=nic._action_manager)) + self._nic_request_manager.add_request(nic.uuid, RequestType(func=nic._request_manager)) else: msg = f"Cannot connect NIC {nic} as it is already connected" self.sys_log.logger.error(msg) @@ -1096,7 +1096,7 @@ class Node(SimComponent): nic.parent = None nic.disable() self.sys_log.info(f"Disconnected NIC {nic}") - self._nic_action_manager.remove_action(nic.uuid) + self._nic_request_manager.remove_request(nic.uuid) else: msg = f"Cannot disconnect NIC {nic} as it is not connected" self.sys_log.logger.error(msg) @@ -1194,7 +1194,7 @@ class Node(SimComponent): service.install() # Perform any additional setup, such as creating files for this service on the node. self.sys_log.info(f"Installed service {service.name}") _LOGGER.info(f"Added service {service.uuid} to node {self.uuid}") - self._service_action_manager.add_action(service.uuid, Action(func=service._action_manager)) + self._service_request_manager.add_request(service.uuid, RequestType(func=service._request_manager)) def uninstall_service(self, service: Service) -> None: """Uninstall and completely remove service from this node. @@ -1210,7 +1210,7 @@ class Node(SimComponent): service.parent = None self.sys_log.info(f"Uninstalled service {service.name}") _LOGGER.info(f"Removed service {service.uuid} from node {self.uuid}") - self._service_action_manager.remove_action(service.uuid) + self._service_request_manager.remove_request(service.uuid) def __contains__(self, item: Any) -> bool: if isinstance(item, Service): diff --git a/src/primaite/simulator/network/hardware/nodes/router.py b/src/primaite/simulator/network/hardware/nodes/router.py index 53b9b176..c56bf538 100644 --- a/src/primaite/simulator/network/hardware/nodes/router.py +++ b/src/primaite/simulator/network/hardware/nodes/router.py @@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Tuple, Union from prettytable import MARKDOWN, PrettyTable -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.network.hardware.base import ARPCache, ICMP, NIC, Node from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame from primaite.simulator.network.transmission.network_layer import ICMPPacket, ICMPType, IPPacket, IPProtocol @@ -43,7 +43,7 @@ class ACLRule(SimComponent): def __str__(self) -> str: rule_strings = [] - for key, value in self.model_dump(exclude={"uuid", "action_manager"}).items(): + for key, value in self.model_dump(exclude={"uuid", "request_manager"}).items(): if value is None: value = "ANY" if isinstance(value, Enum): @@ -87,8 +87,8 @@ class AccessControlList(SimComponent): super().__init__(**kwargs) self._acl = [None] * (self.max_acl_rules - 1) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() # When the request reaches this action, it should now contain solely positional args for the 'add_rule' action. # POSITIONAL ARGUMENTS: @@ -99,9 +99,9 @@ class AccessControlList(SimComponent): # 4: destination ip address (str castable to IPV4Address (e.g. '10.10.1.2')) # 5: destination port (str name of a Port (e.g. "HTTP")) # 6: position (int) - am.add_action( + am.add_request( "add_rule", - Action( + RequestType( func=lambda request, context: self.add_rule( ACLAction[request[0]], IPProtocol[request[1]], @@ -114,7 +114,7 @@ class AccessControlList(SimComponent): ), ) - am.add_action("remove_rule", Action(func=lambda request, context: self.remove_rule(int(request[0])))) + am.add_request("remove_rule", RequestType(func=lambda request, context: self.remove_rule(int(request[0])))) return am def describe_state(self) -> Dict: @@ -626,9 +626,9 @@ class Router(Node): self.arp.nics = self.nics self.icmp.arp = self.arp - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action("acl", Action(func=self.acl._action_manager)) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request("acl", RequestType(func=self.acl._request_manager)) return am def _get_port_of_nic(self, target_nic: NIC) -> Optional[int]: diff --git a/src/primaite/simulator/sim_container.py b/src/primaite/simulator/sim_container.py index d647b0bc..2e88f3b4 100644 --- a/src/primaite/simulator/sim_container.py +++ b/src/primaite/simulator/sim_container.py @@ -1,6 +1,6 @@ from typing import Dict -from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.domain.controller import DomainController from primaite.simulator.network.container import Network @@ -21,12 +21,12 @@ class Simulation(SimComponent): super().__init__(**kwargs) - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - # pass through network actions to the network objects - am.add_action("network", Action(func=self.network._action_manager)) - # pass through domain actions to the domain object - am.add_action("domain", Action(func=self.domain._action_manager)) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + # pass through network requests to the network objects + am.add_request("network", RequestType(func=self.network._request_manager)) + # pass through domain requests to the domain object + am.add_request("domain", RequestType(func=self.domain._request_manager)) return am def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/system/services/service.py b/src/primaite/simulator/system/services/service.py index 20b92027..f48c9449 100644 --- a/src/primaite/simulator/system/services/service.py +++ b/src/primaite/simulator/system/services/service.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Any, Dict, Optional from primaite import getLogger -from primaite.simulator.core import Action, ActionManager +from primaite.simulator.core import RequestManager, RequestType from primaite.simulator.system.software import IOSoftware _LOGGER = getLogger(__name__) @@ -39,15 +39,15 @@ class Service(IOSoftware): _restart_countdown: Optional[int] = None "If currently restarting, how many timesteps remain until the restart is finished." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action("stop", Action(func=lambda request, context: self.stop())) - am.add_action("start", Action(func=lambda request, context: self.start())) - am.add_action("pause", Action(func=lambda request, context: self.pause())) - am.add_action("resume", Action(func=lambda request, context: self.resume())) - am.add_action("restart", Action(func=lambda request, context: self.restart())) - am.add_action("disable", Action(func=lambda request, context: self.disable())) - am.add_action("enable", Action(func=lambda request, context: self.enable())) + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request("stop", RequestType(func=lambda request, context: self.stop())) + am.add_request("start", RequestType(func=lambda request, context: self.start())) + am.add_request("pause", RequestType(func=lambda request, context: self.pause())) + am.add_request("resume", RequestType(func=lambda request, context: self.resume())) + am.add_request("restart", RequestType(func=lambda request, context: self.restart())) + am.add_request("disable", RequestType(func=lambda request, context: self.disable())) + am.add_request("enable", RequestType(func=lambda request, context: self.enable())) return am def describe_state(self) -> Dict: diff --git a/src/primaite/simulator/system/software.py b/src/primaite/simulator/system/software.py index a112eccf..16c614c5 100644 --- a/src/primaite/simulator/system/software.py +++ b/src/primaite/simulator/system/software.py @@ -2,7 +2,7 @@ from abc import abstractmethod from enum import Enum from typing import Any, Dict, Optional -from primaite.simulator.core import Action, ActionManager, SimComponent +from primaite.simulator.core import RequestManager, RequestType, SimComponent from primaite.simulator.file_system.file_system import FileSystem, Folder from primaite.simulator.network.transmission.transport_layer import Port from primaite.simulator.system.core.sys_log import SysLog @@ -85,15 +85,15 @@ class Software(SimComponent): folder: Optional[Folder] = None "The folder on the file system the Software uses." - def _init_action_manager(self) -> ActionManager: - am = super()._init_action_manager() - am.add_action( + def _init_request_manager(self) -> RequestManager: + am = super()._init_request_manager() + am.add_request( "compromise", - Action( + RequestType( func=lambda request, context: self.set_health_state(SoftwareHealthState.COMPROMISED), ), ) - am.add_action("scan", Action(func=lambda request, context: self.scan())) + am.add_request("scan", RequestType(func=lambda request, context: self.scan())) return am @abstractmethod diff --git a/tests/integration_tests/component_creation/test_action_integration.py b/tests/integration_tests/component_creation/test_action_integration.py index ef04ec41..a2be923b 100644 --- a/tests/integration_tests/component_creation/test_action_integration.py +++ b/tests/integration_tests/component_creation/test_action_integration.py @@ -1,6 +1,6 @@ import pytest -from primaite.simulator.core import Action +from primaite.simulator.core import RequestType from primaite.simulator.network.hardware.nodes.computer import Computer from primaite.simulator.network.hardware.nodes.server import Server from primaite.simulator.network.hardware.nodes.switch import Switch @@ -32,7 +32,7 @@ def test_passing_actions_down(monkeypatch) -> None: sim.network.connect(s1.switch_ports[3], srv.ethernet_port[1]) # call this method to make sure no errors occur. - sim._action_manager.get_action_tree() + sim._request_manager.get_request_types_recursively() # patch the action to do something which we can check the result of. action_invoked = False @@ -42,13 +42,13 @@ def test_passing_actions_down(monkeypatch) -> None: action_invoked = True monkeypatch.setitem( - downloads_folder._action_manager.actions, "repair", Action(func=lambda request, context: succeed()) + downloads_folder._request_manager.request_types, "repair", RequestType(func=lambda request, context: succeed()) ) assert not action_invoked # call the patched method - sim.apply_action( + sim.apply_request( ["network", "node", pc1.uuid, "file_system", "folder", pc1.file_system.get_folder("downloads").uuid, "repair"] ) diff --git a/tests/integration_tests/component_creation/test_permission_system.py b/tests/integration_tests/component_creation/test_permission_system.py index 57e0b35a..bcadebb4 100644 --- a/tests/integration_tests/component_creation/test_permission_system.py +++ b/tests/integration_tests/component_creation/test_permission_system.py @@ -3,7 +3,7 @@ from typing import Dict, List, Literal import pytest -from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent +from primaite.simulator.core import AllowAllValidator, RequestManager, RequestType, SimComponent from primaite.simulator.domain.controller import AccountGroup, GroupMembershipValidator @@ -29,11 +29,11 @@ def test_group_action_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self._action_manager = ActionManager() + self._request_manager = RequestManager() - self._action_manager.add_action( + self._request_manager.add_request( "create_folder", - Action( + RequestType( func=lambda request, context: self.create_folder(request[0]), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), @@ -52,13 +52,13 @@ def test_group_action_validation() -> None: # check that the folder is created when a local admin tried to do it permitted_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_ADMIN"]}} my_node = Node(uuid="0000-0000-1234", name="pc") - my_node.apply_action(["create_folder", "memes"], context=permitted_context) + my_node.apply_request(["create_folder", "memes"], context=permitted_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" # check that the number of folders is still 1 even after attempting to create a second one without permissions invalid_context = {"request_source": {"agent": "BLUE", "account": "User1", "groups": ["LOCAL_USER", "DOMAIN_USER"]}} - my_node.apply_action(["create_folder", "memes2"], context=invalid_context) + my_node.apply_request(["create_folder", "memes2"], context=invalid_context) assert len(my_node.folders) == 1 assert my_node.folders[0].name == "memes" @@ -79,32 +79,32 @@ def test_hierarchical_action_with_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() + self.request_manager = RequestManager() - self.action_manager.add_action( + self.request_manager.add_request( "turn_on", - Action( + RequestType( func=lambda request, context: self.turn_on(), validator=AllowAllValidator(), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "turn_off", - Action( + RequestType( func=lambda request, context: self.turn_off(), validator=AllowAllValidator(), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "disable", - Action( + RequestType( func=lambda request, context: self.disable(), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), ) - self.action_manager.add_action( + self.request_manager.add_request( "enable", - Action( + RequestType( func=lambda request, context: self.enable(), validator=GroupMembershipValidator([AccountGroup.LOCAL_ADMIN, AccountGroup.DOMAIN_ADMIN]), ), @@ -135,11 +135,11 @@ def test_hierarchical_action_with_validation() -> None: def __init__(self, **kwargs): super().__init__(**kwargs) - self.action_manager = ActionManager() + self.request_manager = RequestManager() - self.action_manager.add_action( + self.request_manager.add_request( "apps", - Action( + RequestType( func=lambda request, context: self.send_action_to_app(request.pop(0), request, context), validator=AllowAllValidator(), ), @@ -155,7 +155,7 @@ def test_hierarchical_action_with_validation() -> None: def send_action_to_app(self, app_name: str, options: List[str], context: Dict): for app in self.apps: if app_name == app.name: - app.apply_action(options, context) + app.apply_request(options, context) break else: msg = f"Node has no app with name {app_name}" @@ -178,15 +178,15 @@ def test_hierarchical_action_with_validation() -> None: } # check that a non-admin can't disable this app - my_node.apply_action(["apps", "Chrome", "disable"], non_admin_context) + my_node.apply_request(["apps", "Chrome", "disable"], non_admin_context) assert my_node.apps[0].name == "Chrome" # if failure occurs on this line, the test itself is broken assert my_node.apps[0].state == "off" # check that a non-admin can turn this app on - my_node.apply_action(["apps", "Firefox", "turn_on"], non_admin_context) + my_node.apply_request(["apps", "Firefox", "turn_on"], non_admin_context) assert my_node.apps[1].name == "Firefox" # if failure occurs on this line, the test itself is broken assert my_node.apps[1].state == "on" # check that an admin can disable this app - my_node.apply_action(["apps", "Chrome", "disable"], admin_context) + my_node.apply_request(["apps", "Chrome", "disable"], admin_context) assert my_node.apps[0].state == "disabled" diff --git a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py index b5632ea7..96c34996 100644 --- a/tests/unit_tests/_primaite/_simulator/_domain/test_account.py +++ b/tests/unit_tests/_primaite/_simulator/_domain/test_account.py @@ -13,6 +13,6 @@ def test_account_deserialise(): """Test that an account can be deserialised. The test fails if pydantic throws an error.""" acct_json = ( '{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,' - '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}' + '"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"request_manager":null}' ) acct = Account.model_validate_json(acct_json)