forked from rocky-linux/oval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoval.py
111 lines (80 loc) · 3.08 KB
/
oval.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
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
import oval_xml as xml
import oval_control as ctrl
def output( definitions, tests, objects, states ) :
"""
output to OVAL XML content based on transformed content
with definitions section followed by tests, objects, states
"""
# header content
print( xml.header( xml.version ) )
# definitions section
print( xml.section( "definitions") )
for definition in definitions :
metadata_output = xml.metadata(
definition[ 'title' ], definition[ 'family' ], definition[ 'platform' ],
definition[ 'ref_id' ], definition[ 'source' ], definition[ 'references' ],
definition[ 'description' ], definition[ 'severity' ], definition[ 'issued' ],
definition[ 'updated' ], definition[ 'cpes']
)
criteria_output = xml.criteria(
xml.version[ "Scope" ], definition[ 'criteria' ]
)
# definition content
print( xml.definition( xml.version[ "Scope" ],
definition[ 'id' ], definition[ 'version' ], definition[ 'class' ],
metadata_output, criteria_output)
)
print( xml.section( "definitions", True ) )
# tests section
print( xml.section( "tests" ) )
for test in tests :
print( xml.test( xml.version[ 'Tag' ], xml.version[ "Scope" ],
test[ 'type' ], test[ 'id' ], test[ 'version' ], test[ 'comment' ],
test[ 'check' ], test[ 'oid' ], test[ 'sids' ] )
)
print( xml.section( "tests", True ) )
# objects section
print( xml.section( "objects" ) )
for object in objects :
print( xml.object( xml.version[ 'Tag' ], xml.version[ 'Scope' ],
object[ 'type' ], object[ 'id' ], object[ 'version' ],
object[ 'contents' ] )
)
print( xml.section( "objects", True ) )
# states section
print( xml.section( "states" ) )
for state in states :
print( xml.state( xml.version[ 'Tag' ], xml.version[ 'Scope' ],
state[ 'type' ], state[ 'id' ], state[ 'version' ],
state[ 'contents' ] )
)
print( xml.section( "states", True ) )
# footer content
print( xml.footer( ) )
def pipeline( test_local = False ) :
"""
pipeline for gathering advisories, normalizing and filtering followed
by transforming and XML output
"""
# ingest advisory information from API as list of JSON strings
alist = ctrl.ingest( )
# normalize JSON strings to dataframes
advisories = ctrl.normalize( alist )
# filter all advisories other than security type
advisories = ctrl.filter( advisories )
# transform to OVAL types
definitions, tests, objects, states = ctrl.transform( advisories )
# output to OVAL XML content
output( definitions, tests, objects, states )
"""
TODO - remove dependency on pandas and use dictionary
TODO - add error handling to stderr
"""
def main( ):
"""
run the pipeline to generate OVAL XML output based on current advisories
"""
# pipeline conversion from JSON ingest to OVAL XML output
pipeline( )
if __name__ == "__main__":
main( )