#1355 - Carried out full renaming in node.py, active_node.py, passive_node.py, and service_node.py to make params and variable names explicit.
- Made the same renaming in the yaml laydown config files. - Added Type hints wherever I've been. - Added a custom NodeType in custom_typing.py to encompass the Union of ActiveNode, PassiveNode, ServiceNode.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"""The config class."""
|
||||
|
||||
|
||||
class config_values_main(object):
|
||||
class ConfigValuesMain(object):
|
||||
"""Class to hold main config values."""
|
||||
|
||||
def __init__(self):
|
||||
@@ -23,7 +23,7 @@ class config_values_main(object):
|
||||
# Reward values
|
||||
# Generic
|
||||
self.all_ok = 0
|
||||
# Node Operating State
|
||||
# Node Hardware State
|
||||
self.off_should_be_on = 0
|
||||
self.off_should_be_resetting = 0
|
||||
self.on_should_be_off = 0
|
||||
@@ -31,7 +31,7 @@ class config_values_main(object):
|
||||
self.resetting_should_be_on = 0
|
||||
self.resetting_should_be_off = 0
|
||||
self.resetting = 0
|
||||
# Node O/S or Service State
|
||||
# Node Software or Service State
|
||||
self.good_should_be_patching = 0
|
||||
self.good_should_be_compromised = 0
|
||||
self.good_should_be_overwhelmed = 0
|
||||
|
||||
8
src/primaite/common/custom_typing.py
Normal file
8
src/primaite/common/custom_typing.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from typing import Type, Union
|
||||
|
||||
from primaite.nodes.active_node import ActiveNode
|
||||
from primaite.nodes.passive_node import PassiveNode
|
||||
from primaite.nodes.service_node import ServiceNode
|
||||
|
||||
NodeType: Type = Union[ActiveNode, PassiveNode, ServiceNode]
|
||||
"""A Union of ActiveNode, PassiveNode, and ServiceNode."""
|
||||
@@ -4,7 +4,7 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class TYPE(Enum):
|
||||
class NodeType(Enum):
|
||||
"""Node type enumeration."""
|
||||
|
||||
CCTV = 1
|
||||
@@ -19,7 +19,7 @@ class TYPE(Enum):
|
||||
SERVER = 10
|
||||
|
||||
|
||||
class PRIORITY(Enum):
|
||||
class Priority(Enum):
|
||||
"""Node priority enumeration."""
|
||||
|
||||
P1 = 1
|
||||
@@ -29,7 +29,7 @@ class PRIORITY(Enum):
|
||||
P5 = 5
|
||||
|
||||
|
||||
class HARDWARE_STATE(Enum):
|
||||
class HardwareState(Enum):
|
||||
"""Node hardware state enumeration."""
|
||||
|
||||
ON = 1
|
||||
@@ -37,8 +37,8 @@ class HARDWARE_STATE(Enum):
|
||||
RESETTING = 3
|
||||
|
||||
|
||||
class SOFTWARE_STATE(Enum):
|
||||
"""O/S or Service state enumeration."""
|
||||
class SoftwareState(Enum):
|
||||
"""Software or Service state enumeration."""
|
||||
|
||||
GOOD = 1
|
||||
PATCHING = 2
|
||||
@@ -46,7 +46,7 @@ class SOFTWARE_STATE(Enum):
|
||||
OVERWHELMED = 4
|
||||
|
||||
|
||||
class NODE_POL_TYPE(Enum):
|
||||
class NodePOLType(Enum):
|
||||
"""Node Pattern of Life type enumeration."""
|
||||
|
||||
OPERATING = 1
|
||||
@@ -55,7 +55,7 @@ class NODE_POL_TYPE(Enum):
|
||||
FILE = 4
|
||||
|
||||
|
||||
class NODE_POL_INITIATOR(Enum):
|
||||
class NodePOLInitiator(Enum):
|
||||
"""Node Pattern of Life initiator enumeration."""
|
||||
|
||||
DIRECT = 1
|
||||
@@ -63,7 +63,7 @@ class NODE_POL_INITIATOR(Enum):
|
||||
SERVICE = 3
|
||||
|
||||
|
||||
class PROTOCOL(Enum):
|
||||
class Protocol(Enum):
|
||||
"""Service protocol enumeration."""
|
||||
|
||||
LDAP = 0
|
||||
@@ -76,14 +76,14 @@ class PROTOCOL(Enum):
|
||||
NONE = 7
|
||||
|
||||
|
||||
class ACTION_TYPE(Enum):
|
||||
class ActionType(Enum):
|
||||
"""Action type enumeration."""
|
||||
|
||||
NODE = 0
|
||||
ACL = 1
|
||||
|
||||
|
||||
class FILE_SYSTEM_STATE(Enum):
|
||||
class FileSystemState(Enum):
|
||||
"""File System State."""
|
||||
|
||||
GOOD = 1
|
||||
|
||||
@@ -1,83 +1,28 @@
|
||||
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
|
||||
"""The Service class."""
|
||||
|
||||
from primaite.common.enums import SOFTWARE_STATE
|
||||
from primaite.common.enums import SoftwareState
|
||||
|
||||
|
||||
class Service(object):
|
||||
"""Service class."""
|
||||
|
||||
def __init__(self, _name, _port, _state):
|
||||
def __init__(self, name: str, port: str, software_state: SoftwareState):
|
||||
"""
|
||||
Init.
|
||||
|
||||
Args:
|
||||
_name: The service name
|
||||
_port: The service port
|
||||
_state: The service state
|
||||
:param name: The service name.
|
||||
:param port: The service port.
|
||||
:param software_state: The service SoftwareState.
|
||||
"""
|
||||
self.name = _name
|
||||
self.port = _port
|
||||
self.state = _state
|
||||
self.name = name
|
||||
self.port = port
|
||||
self.software_state = software_state
|
||||
self.patching_count = 0
|
||||
|
||||
def set_name(self, _name):
|
||||
"""
|
||||
Sets the service name.
|
||||
|
||||
Args:
|
||||
_name: The service name
|
||||
"""
|
||||
self.name = _name
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
Gets the service name.
|
||||
|
||||
Returns:
|
||||
The service name
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def set_port(self, _port):
|
||||
"""
|
||||
Sets the service port.
|
||||
|
||||
Args:
|
||||
_port: The service port
|
||||
"""
|
||||
self.port = _port
|
||||
|
||||
def get_port(self):
|
||||
"""
|
||||
Gets the service port.
|
||||
|
||||
Returns:
|
||||
The service port
|
||||
"""
|
||||
return self.port
|
||||
|
||||
def set_state(self, _state):
|
||||
"""
|
||||
Sets the service state.
|
||||
|
||||
Args:
|
||||
_state: The service state
|
||||
"""
|
||||
self.state = _state
|
||||
|
||||
def get_state(self):
|
||||
"""
|
||||
Gets the service state.
|
||||
|
||||
Returns:
|
||||
The service state
|
||||
"""
|
||||
return self.state
|
||||
|
||||
def reduce_patching_count(self):
|
||||
"""Reduces the patching count for the service."""
|
||||
self.patching_count -= 1
|
||||
if self.patching_count <= 0:
|
||||
self.patching_count = 0
|
||||
self.state = SOFTWARE_STATE.GOOD
|
||||
self.software_state = SoftwareState.GOOD
|
||||
|
||||
Reference in New Issue
Block a user