-
Notifications
You must be signed in to change notification settings - Fork 4
/
generateYAMLFramework.py
59 lines (40 loc) · 1.74 KB
/
generateYAMLFramework.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
# Core python packages
import yaml
# 3rd party packages
import boto3
def create_yaml_controls(
name_report: str,
filename: str,
region_name = None
):
auditmanager_client = boto3.client('auditmanager', region_name=region_name)
## create a zero byte yaml file
open(filename, 'w', encoding="utf-8" ).close()
framework_list_response = auditmanager_client.list_assessment_frameworks(frameworkType='Standard')
for framework_list in framework_list_response['frameworkMetadataList']:
if framework_list['name'] == name_report:
id_report = framework_list['id']
framework_controls_response = auditmanager_client.get_assessment_framework(
frameworkId=id_report
)
yaml_dict = {}
for control_sets in framework_controls_response['framework']['controlSets']:
control_sets_dict = {}
for controls in control_sets['controls']:
controls_dict = {}
controls_dict['name'] = controls['name'].strip()[0:300]
if 'description' in controls.keys():
controls_dict['description'] = controls['description'].strip()[0:1000]
else:
controls_dict['description'] = "Not Available"
controls_dict['testingInformation'] = "-"
controls_dict['actionPlanTitle'] = "-"
controls_dict['actionPlanInstructions'] = "-"
for control_map in controls['controlMappingSources']:
control_map['sourceName'] = control_map['sourceId']
control_map.pop('sourceId')
controls_dict['controlMappingSources'] = controls['controlMappingSources']
control_sets_dict[controls['name'].strip()] = controls_dict
yaml_dict[control_sets['name']] = control_sets_dict
with open(filename, 'a', encoding="utf-8") as file:
documents = yaml.dump(yaml_dict, file, sort_keys=False)