openc2lib.core.response

OpenC2 Response elements

This module defines the elements beard by a Response.

  1""" OpenC2 Response elements
  2
  3	This module defines the elements beard by a `Response`.
  4"""
  5from openc2lib.types.basetypes import EnumeratedID, Map, ArrayOf
  6from openc2lib.types.datatypes import Version, ActionTargets, Nsid
  7
  8class StatusCode(EnumeratedID):
  9	""" Status codes
 10
 11		Status codes provide indication about the processing of the OpenC2 Command.
 12		They follow the same logic and values of HTTP status code, since they are copied
 13		in HTTP headers.
 14"""
 15	PROCESSING = 102
 16	OK = 200
 17	BADREQUEST = 400
 18	UNAUTHORIZED = 401
 19	FORBIDDEN = 403
 20	NOTFOUND = 404
 21	INTERNALERROR =500
 22	NOTIMPLEMENTED = 501
 23	SERVICEUNAVAILABLE = 503
 24
 25StatusCodeDescription = {StatusCode.PROCESSING: 'Processing', 
 26										StatusCode.OK: 'OK',
 27										StatusCode.BADREQUEST: 'Bad Request',
 28										StatusCode.UNAUTHORIZED: 'Unauthorized',
 29										StatusCode.FORBIDDEN: 'Forbidden',
 30										StatusCode.NOTFOUND: 'Not Found',
 31										StatusCode.INTERNALERROR: 'Internal Error',
 32										StatusCode.NOTIMPLEMENTED: 'Not Implemented',
 33										StatusCode.SERVICEUNAVAILABLE: 'Service Unavailable'}
 34""" Status code description
 35
 36	Human-readable description of `StatusCode`s. The values are only provided as base values, since any `Actuator`
 37	can freely use different descriptions.
 38"""
 39
 40class ExtResultsDict(dict):
 41	""" Extended Results
 42
 43		This class is used to extend the basic `Results` definition. If follows the same logic as 
 44		other extended class in the openc2lib. 
 45	"""
 46	def add(self, profile: str, extresults):
 47		""" Add extension
 48
 49			Add a new extension for a given `Profile`. The extension must be registered only once.
 50			:param profile: The name of the profile for which the extension is registered.
 51			:param extresults: The Extension to be registered.
 52			:return: None
 53		"""
 54		if profile in self:
 55			raise ValueError("ExtResults already registered")
 56		self[profile] = extresults
 57	
 58ExtendedResults = ExtResultsDict()
 59""" List of Extended Results
 60
 61	List of registered extensions to `Results`. It is only used internally the openc2lib to correctly
 62	parse incoming Rensponses.
 63"""
 64
 65class Results(Map):
 66	""" OpenC2 Response Results
 67
 68		This class implements the definition in Sec. 3.3.2.2 of the Language Specification. The `Results` carry
 69		the output of an OpenC2 Command. This definition only includes basic fields and it is expected to
 70		be extended for each `Profile`.
 71
 72		Extensions must be derived class that define the following member:
 73			- `fieldtypes`
 74			- `extend`
 75			- `nsid`
 76		`nsid` must be set to the profile name.
 77	"""
 78	fieldtypes = dict(versions= ArrayOf(Version), profiles= ArrayOf(Nsid), pairs= ActionTargets, rate_limit= int)
 79	""" Field types
 80	
 81		This is the definition of the fields beard by the `Results`. This definition is for internal use only,
 82		to parse OpenC2 messages. Extensions must include these fields and add additional definitions.
 83	"""
 84	extend = None
 85	""" Extension
 86
 87		This field must be set to None in the base class, and to `Results` in the derived class that defines an extension.
 88	"""
 89	regext = ExtendedResults
 90	""" Extended NameSpace
 91
 92		This field is for internal use only and must not be set by any derived class.
 93	"""
 94
 95	def set(self, version=None, profiles=None, pairs=None, rate_limit=None):
 96		""" Set values
 97
 98			This function may be used to set specific values of the `Results`, with a key=value syntax.
 99			:param version: List of OpenC2 Versions supported by the Actuator.
100			:param profiles: List of OpenC2 Profiles supported by the Actuator.
101			:param pairs: List of `Targets` applicable to each supported `Action`.
102			:param rate_limit: Maximum number of requests per minute supported by design or policy.
103			:return: None
104		"""
105		self['version']=version
106		self['profiles']=profiles
107		self['pairs']=pairs
108		self['rate_limit']=rate_limit
class StatusCode(openc2lib.types.basetypes.EnumeratedID):
 9class StatusCode(EnumeratedID):
10	""" Status codes
11
12		Status codes provide indication about the processing of the OpenC2 Command.
13		They follow the same logic and values of HTTP status code, since they are copied
14		in HTTP headers.
15"""
16	PROCESSING = 102
17	OK = 200
18	BADREQUEST = 400
19	UNAUTHORIZED = 401
20	FORBIDDEN = 403
21	NOTFOUND = 404
22	INTERNALERROR =500
23	NOTIMPLEMENTED = 501
24	SERVICEUNAVAILABLE = 503

Status codes

Status codes provide indication about the processing of the OpenC2 Command. They follow the same logic and values of HTTP status code, since they are copied in HTTP headers.

PROCESSING = <StatusCode.PROCESSING: 102>
OK = <StatusCode.OK: 200>
BADREQUEST = <StatusCode.BADREQUEST: 400>
UNAUTHORIZED = <StatusCode.UNAUTHORIZED: 401>
FORBIDDEN = <StatusCode.FORBIDDEN: 403>
NOTFOUND = <StatusCode.NOTFOUND: 404>
INTERNALERROR = <StatusCode.INTERNALERROR: 500>
NOTIMPLEMENTED = <StatusCode.NOTIMPLEMENTED: 501>
SERVICEUNAVAILABLE = <StatusCode.SERVICEUNAVAILABLE: 503>
Inherited Members
openc2lib.types.basetypes.EnumeratedID
todict
fromdict
aenum._enum.Enum
name
value
values
StatusCodeDescription = {<StatusCode.PROCESSING: 102>: 'Processing', <StatusCode.OK: 200>: 'OK', <StatusCode.BADREQUEST: 400>: 'Bad Request', <StatusCode.UNAUTHORIZED: 401>: 'Unauthorized', <StatusCode.FORBIDDEN: 403>: 'Forbidden', <StatusCode.NOTFOUND: 404>: 'Not Found', <StatusCode.INTERNALERROR: 500>: 'Internal Error', <StatusCode.NOTIMPLEMENTED: 501>: 'Not Implemented', <StatusCode.SERVICEUNAVAILABLE: 503>: 'Service Unavailable'}

Status code description

Human-readable description of StatusCodes. The values are only provided as base values, since any Actuator can freely use different descriptions.

class ExtResultsDict(builtins.dict):
41class ExtResultsDict(dict):
42	""" Extended Results
43
44		This class is used to extend the basic `Results` definition. If follows the same logic as 
45		other extended class in the openc2lib. 
46	"""
47	def add(self, profile: str, extresults):
48		""" Add extension
49
50			Add a new extension for a given `Profile`. The extension must be registered only once.
51			:param profile: The name of the profile for which the extension is registered.
52			:param extresults: The Extension to be registered.
53			:return: None
54		"""
55		if profile in self:
56			raise ValueError("ExtResults already registered")
57		self[profile] = extresults

Extended Results

This class is used to extend the basic Results definition. If follows the same logic as other extended class in the openc2lib.

def add(self, profile: str, extresults):
47	def add(self, profile: str, extresults):
48		""" Add extension
49
50			Add a new extension for a given `Profile`. The extension must be registered only once.
51			:param profile: The name of the profile for which the extension is registered.
52			:param extresults: The Extension to be registered.
53			:return: None
54		"""
55		if profile in self:
56			raise ValueError("ExtResults already registered")
57		self[profile] = extresults

Add extension

Add a new extension for a given Profile. The extension must be registered only once.

Parameters
  • profile: The name of the profile for which the extension is registered.
  • extresults: The Extension to be registered.
Returns

None

Inherited Members
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy
ExtendedResults = {'slpf': <class 'openc2lib.profiles.slpf.response.Results'>}

List of Extended Results

List of registered extensions to Results. It is only used internally the openc2lib to correctly parse incoming Rensponses.

class Results(openc2lib.types.basetypes.Map):
 66class Results(Map):
 67	""" OpenC2 Response Results
 68
 69		This class implements the definition in Sec. 3.3.2.2 of the Language Specification. The `Results` carry
 70		the output of an OpenC2 Command. This definition only includes basic fields and it is expected to
 71		be extended for each `Profile`.
 72
 73		Extensions must be derived class that define the following member:
 74			- `fieldtypes`
 75			- `extend`
 76			- `nsid`
 77		`nsid` must be set to the profile name.
 78	"""
 79	fieldtypes = dict(versions= ArrayOf(Version), profiles= ArrayOf(Nsid), pairs= ActionTargets, rate_limit= int)
 80	""" Field types
 81	
 82		This is the definition of the fields beard by the `Results`. This definition is for internal use only,
 83		to parse OpenC2 messages. Extensions must include these fields and add additional definitions.
 84	"""
 85	extend = None
 86	""" Extension
 87
 88		This field must be set to None in the base class, and to `Results` in the derived class that defines an extension.
 89	"""
 90	regext = ExtendedResults
 91	""" Extended NameSpace
 92
 93		This field is for internal use only and must not be set by any derived class.
 94	"""
 95
 96	def set(self, version=None, profiles=None, pairs=None, rate_limit=None):
 97		""" Set values
 98
 99			This function may be used to set specific values of the `Results`, with a key=value syntax.
100			:param version: List of OpenC2 Versions supported by the Actuator.
101			:param profiles: List of OpenC2 Profiles supported by the Actuator.
102			:param pairs: List of `Targets` applicable to each supported `Action`.
103			:param rate_limit: Maximum number of requests per minute supported by design or policy.
104			:return: None
105		"""
106		self['version']=version
107		self['profiles']=profiles
108		self['pairs']=pairs
109		self['rate_limit']=rate_limit

OpenC2 Response Results

This class implements the definition in Sec. 3.3.2.2 of the Language Specification. The Results carry the output of an OpenC2 Command. This definition only includes basic fields and it is expected to be extended for each Profile.

Extensions must be derived class that define the following member: - fieldtypes - extend - nsid nsid must be set to the profile name.

fieldtypes = {'versions': <class 'openc2lib.types.basetypes.ArrayOf.__new__.<locals>.ArrayOf'>, 'profiles': <class 'openc2lib.types.basetypes.ArrayOf.__new__.<locals>.ArrayOf'>, 'pairs': <class 'openc2lib.types.datatypes.ActionTargets'>, 'rate_limit': <class 'int'>}

Field types

This is the definition of the fields beard by the Results. This definition is for internal use only, to parse OpenC2 messages. Extensions must include these fields and add additional definitions.

extend = None

Extension

This field must be set to None in the base class, and to Results in the derived class that defines an extension.

regext = {'slpf': <class 'openc2lib.profiles.slpf.response.Results'>}

Extended NameSpace

This field is for internal use only and must not be set by any derived class.

def set(self, version=None, profiles=None, pairs=None, rate_limit=None):
 96	def set(self, version=None, profiles=None, pairs=None, rate_limit=None):
 97		""" Set values
 98
 99			This function may be used to set specific values of the `Results`, with a key=value syntax.
100			:param version: List of OpenC2 Versions supported by the Actuator.
101			:param profiles: List of OpenC2 Profiles supported by the Actuator.
102			:param pairs: List of `Targets` applicable to each supported `Action`.
103			:param rate_limit: Maximum number of requests per minute supported by design or policy.
104			:return: None
105		"""
106		self['version']=version
107		self['profiles']=profiles
108		self['pairs']=pairs
109		self['rate_limit']=rate_limit

Set values

This function may be used to set specific values of the Results, with a key=value syntax.

Parameters
  • version: List of OpenC2 Versions supported by the Actuator.
  • profiles: List of OpenC2 Profiles supported by the Actuator.
  • pairs: List of Targets applicable to each supported Action.
  • rate_limit: Maximum number of requests per minute supported by design or policy.
Returns

None

Inherited Members
openc2lib.types.basetypes.Map
todict
fromdict
builtins.dict
get
setdefault
pop
popitem
keys
items
values
update
fromkeys
clear
copy