openc2lib.core.command

OpenC2 Command structure

This module defines the OpenC2 Command structure, as defined in Sec. 3.2 of the Language Specification.

 1"""OpenC2 Command structure
 2
 3This module defines the OpenC2 Command structure, as defined
 4in Sec. 3.2 of the Language Specification.
 5
 6"""
 7
 8import dataclasses
 9
10from openc2lib.types.base import Record
11from openc2lib.core.content import MessageType, Content
12from openc2lib.core.actions import Actions 
13from openc2lib.core.target import Target
14from openc2lib.core.args import Args
15from openc2lib.core.actuator import Actuator
16
17
18# Init and other standard methods are automatically created
19@dataclasses.dataclass
20class Command(Content, Record):
21	"""OpenC2 Command
22
23	This class defines the structure of the OpenC2 Command. The name, meaning, and restrictions for
24	the fields are described in Sec. 3.3.1 of the Specification.
25
26	The `target` object is implicitely initialized by passing any valid `Target`.
27	"""
28	action: Actions
29	target: Target
30	args: Args = None
31	actuator: Actuator = None
32	command_id: str = None
33	msg_type = MessageType.command
34
35	# Mind that the __post_init__ hides Exceptions!!!! 
36	# If something fails in its code, it returns with no errors but does 
37	# not complete the code
38	def __post_init__(self):
39		if not isinstance(self.target, Target):
40			self.target = Target(self.target)
41		if not isinstance(self.actuator, Actuator) and self.actuator is not None:
42			self.actuator = Actuator(self.actuator)
@dataclasses.dataclass
class Command(openc2lib.core.content.Content, openc2lib.types.base.record.Record):
20@dataclasses.dataclass
21class Command(Content, Record):
22	"""OpenC2 Command
23
24	This class defines the structure of the OpenC2 Command. The name, meaning, and restrictions for
25	the fields are described in Sec. 3.3.1 of the Specification.
26
27	The `target` object is implicitely initialized by passing any valid `Target`.
28	"""
29	action: Actions
30	target: Target
31	args: Args = None
32	actuator: Actuator = None
33	command_id: str = None
34	msg_type = MessageType.command
35
36	# Mind that the __post_init__ hides Exceptions!!!! 
37	# If something fails in its code, it returns with no errors but does 
38	# not complete the code
39	def __post_init__(self):
40		if not isinstance(self.target, Target):
41			self.target = Target(self.target)
42		if not isinstance(self.actuator, Actuator) and self.actuator is not None:
43			self.actuator = Actuator(self.actuator)

OpenC2 Command

This class defines the structure of the OpenC2 Command. The name, meaning, and restrictions for the fields are described in Sec. 3.3.1 of the Specification.

The target object is implicitely initialized by passing any valid Target.

Command( action: openc2lib.core.actions.Actions, target: openc2lib.core.target.Target, args: openc2lib.core.args.Args = None, actuator: openc2lib.core.actuator.Actuator = None, command_id: str = None)
command_id: str = None
msg_type = <MessageType.command: 1>

The type of Content (MessageType)