Bases: TaskBase
flowchart TD
trestle.tasks.oscal_profile_to_osco_profile.ProfileToOsco[ProfileToOsco]
trestle.tasks.base_task.TaskBase[TaskBase]
trestle.tasks.base_task.TaskBase --> trestle.tasks.oscal_profile_to_osco_profile.ProfileToOsco
click trestle.tasks.oscal_profile_to_osco_profile.ProfileToOsco href "" "trestle.tasks.oscal_profile_to_osco_profile.ProfileToOsco"
click trestle.tasks.base_task.TaskBase href "" "trestle.tasks.base_task.TaskBase"
Task to convert Profile to OSC yaml.
Attributes:
| Name | Type | Description |
name | | |
Source code in trestle/tasks/oscal_profile_to_osco_profile.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 | class ProfileToOsco(TaskBase):
"""
Task to convert Profile to OSC yaml.
Attributes:
name: Name of the task.
"""
name = 'oscal-profile-to-osco-profile'
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""
Initialize trestle task oscal-profile-to-osco-profile.
Args:
config_object: Config section associated with the task.
"""
super().__init__(config_object)
def print_info(self) -> None:
"""Print the help string."""
logger.info(f'Help information for {self.name} task.')
logger.info('')
logger.info(
'Purpose: Transform Open Security Controls Assessment Language (OSCAL) Profile '
+ 'into Open Shift Compliance Operator (OSCO) .yaml file.'
)
logger.info('')
logger.info('Configuration flags sit under [task.oscal-profile-to-osco-profile]:')
logger.info(' input-file = (required) path of the input file comprising OSCAL profile.')
logger.info(' output-dir = (required) path of the output directory comprising synthesized .yaml file.')
logger.info(
' output-name = (optional) name of created file in output directory, default is osco-profile.yaml.'
)
logger.info(' output-overwrite = (optional) true [default] or false; replace existing output when true.')
logger.info(
' quiet = (optional) true or false [default]; display file creations and rules analysis when false.'
)
logger.info('')
logger.info('Operation: The specified input profile is transformed into OSCO .yaml.')
logger.info('')
logger.info('Notes:')
note11 = '[1] The input-file OSCAL profile should specify a metadata property with'
note12 = 'name "osco_version" and value of the form "0.1.46".'
note13 = 'The value corresponds with the OpenShift Compliance Operator (OSCO) version'
note14 = 'and affects the format of the emitted yaml.'
note15 = 'If not specified, the default is "0.1.46".'
logger.info(f'{note11} {note12} {note13} {note14} {note15}')
note21 = '[2] For OSCO version "0.1.39" and prior no "description" is emitted for "spec".'
logger.info(f'{note21}')
def simulate(self) -> TaskOutcome:
"""Provide a simulated outcome."""
return TaskOutcome('simulated-success')
def execute(self) -> TaskOutcome:
"""Provide an actual outcome."""
try:
return self._execute()
except Exception:
logger.warning(traceback.format_exc())
return TaskOutcome('failure')
def _execute(self) -> TaskOutcome:
"""Perform transformation."""
# check config
if not self._config:
logger.warning('config missing')
return TaskOutcome('failure')
# input-file
input_file = self._config.get('input-file')
if input_file is None:
logger.warning('config missing "input-file"')
return TaskOutcome('failure')
logger.info(f'input-file: {input_file}')
input_path = pathlib.Path(input_file)
# output-dir
output_dir = self._config.get('output-dir')
if output_dir is None:
logger.warning('config missing "output-dir"')
return TaskOutcome('failure')
output_path = pathlib.Path(output_dir)
# insure output dir exists
output_path.mkdir(exist_ok=True, parents=True)
# output file path
output_name = self._config.get('output-name', 'osco-profile.yaml')
output_filepath = pathlib.Path(output_dir, output_name)
logger.info(f'output-file: {output_filepath}')
# overwrite
overwrite = self._config.getboolean('output-overwrite', True)
if not overwrite and pathlib.Path(output_filepath).exists():
logger.warning(f'output-file: {output_filepath} already exists')
return TaskOutcome('failure')
# read input
profile = Profile.oscal_read(input_path)
# transform
transformer = OscalProfileToOscoProfileTransformer()
ydata = json.loads(transformer.transform(profile))
# write output
yaml = YAML(typ='safe')
yaml.default_flow_style = False
with open(output_filepath, 'w') as outfile:
yaml.dump(ydata, outfile)
# success
return TaskOutcome('success')
|
Attributes
name = 'oscal-profile-to-osco-profile' class-attribute instance-attribute
Functions
__init__(config_object)
Initialize trestle task oscal-profile-to-osco-profile.
Parameters:
| Name | Type | Description | Default |
config_object | Optional[SectionProxy] | Config section associated with the task. | required |
Source code in trestle/tasks/oscal_profile_to_osco_profile.py
| def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
"""
Initialize trestle task oscal-profile-to-osco-profile.
Args:
config_object: Config section associated with the task.
"""
super().__init__(config_object)
|
execute()
Provide an actual outcome.
Source code in trestle/tasks/oscal_profile_to_osco_profile.py
| def execute(self) -> TaskOutcome:
"""Provide an actual outcome."""
try:
return self._execute()
except Exception:
logger.warning(traceback.format_exc())
return TaskOutcome('failure')
|
print_info()
Print the help string.
Source code in trestle/tasks/oscal_profile_to_osco_profile.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 | def print_info(self) -> None:
"""Print the help string."""
logger.info(f'Help information for {self.name} task.')
logger.info('')
logger.info(
'Purpose: Transform Open Security Controls Assessment Language (OSCAL) Profile '
+ 'into Open Shift Compliance Operator (OSCO) .yaml file.'
)
logger.info('')
logger.info('Configuration flags sit under [task.oscal-profile-to-osco-profile]:')
logger.info(' input-file = (required) path of the input file comprising OSCAL profile.')
logger.info(' output-dir = (required) path of the output directory comprising synthesized .yaml file.')
logger.info(
' output-name = (optional) name of created file in output directory, default is osco-profile.yaml.'
)
logger.info(' output-overwrite = (optional) true [default] or false; replace existing output when true.')
logger.info(
' quiet = (optional) true or false [default]; display file creations and rules analysis when false.'
)
logger.info('')
logger.info('Operation: The specified input profile is transformed into OSCO .yaml.')
logger.info('')
logger.info('Notes:')
note11 = '[1] The input-file OSCAL profile should specify a metadata property with'
note12 = 'name "osco_version" and value of the form "0.1.46".'
note13 = 'The value corresponds with the OpenShift Compliance Operator (OSCO) version'
note14 = 'and affects the format of the emitted yaml.'
note15 = 'If not specified, the default is "0.1.46".'
logger.info(f'{note11} {note12} {note13} {note14} {note15}')
note21 = '[2] For OSCO version "0.1.39" and prior no "description" is emitted for "spec".'
logger.info(f'{note21}')
|
simulate()
Provide a simulated outcome.
Source code in trestle/tasks/oscal_profile_to_osco_profile.py
| def simulate(self) -> TaskOutcome:
"""Provide a simulated outcome."""
return TaskOutcome('simulated-success')
|