Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
flan
Commits
b9bf3512
Commit
b9bf3512
authored
1 year ago
by
Lukas Koenen
Browse files
Options
Downloads
Patches
Plain Diff
refactor: report info
parent
6eed154b
No related branches found
No related tags found
No related merge requests found
Pipeline
#201338
passed
1 year ago
Stage: test
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contrib/report_builders/html_report_builder.py
+23
-17
23 additions, 17 deletions
contrib/report_builders/html_report_builder.py
run.sh
+3
-3
3 additions, 3 deletions
run.sh
with
26 additions
and
20 deletions
contrib/report_builders/html_report_builder.py
+
23
−
17
View file @
b9bf3512
...
@@ -8,26 +8,28 @@ from contrib.descriptions import VulnDescriptionProvider
...
@@ -8,26 +8,28 @@ from contrib.descriptions import VulnDescriptionProvider
from
contrib.report_builders
import
JsonReportBuilder
from
contrib.report_builders
import
JsonReportBuilder
class
Severity
:
class
ReportInfo
:
def
__init__
(
self
,
severity
):
def
__init__
(
self
,
severity
=
'
SeverityNone
'
,
is_empty
=
False
):
self
.
l
eve
l
=
severity
self
.
s
eve
rity
=
severity
self
.
num_
l
eve
l
=
0
self
.
num_
s
eve
rity
=
0
if
severity
==
'
Low
'
:
self
.
empty
=
is_empty
self
.
num_level
=
1
if
severity
==
'
Medium
'
:
if
severity
==
'
SeverityLow
'
:
self
.
num_
l
eve
l
=
2
self
.
num_
s
eve
rity
=
1
if
severity
==
'
High
'
:
if
severity
==
'
SeverityMedium
'
:
self
.
num_level
=
3
self
.
num_severity
=
2
if
severity
==
'
SeverityHigh
'
:
self
.
num_severity
=
3
def
toJSON
(
self
):
def
toJSON
(
self
):
return
json
.
dumps
(
self
,
default
=
lambda
o
:
o
.
__dict__
,
return
json
.
dumps
(
self
,
default
=
lambda
o
:
o
.
__dict__
,
sort_keys
=
True
,
indent
=
4
)
sort_keys
=
True
,
indent
=
4
)
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
return
self
.
num_
l
eve
l
<
other
.
num_
l
eve
l
return
self
.
num_
s
eve
rity
<
other
.
num_
s
eve
rity
class
JinjaHtmlReportBuilder
(
JsonReportBuilder
):
class
JinjaHtmlReportBuilder
(
JsonReportBuilder
):
...
@@ -40,16 +42,20 @@ class JinjaHtmlReportBuilder(JsonReportBuilder):
...
@@ -40,16 +42,20 @@ class JinjaHtmlReportBuilder(JsonReportBuilder):
def
build
(
self
)
->
Any
:
def
build
(
self
)
->
Any
:
json_data
=
self
.
_buffer
json_data
=
self
.
_buffer
max_severity
=
Severity
(
'
Empty
'
)
report_info
=
ReportInfo
()
if
len
(
json_data
[
'
ips
'
])
==
0
:
report_info
.
empty
=
True
for
vv
in
json_data
[
'
vulnerable
'
].
values
():
for
vv
in
json_data
[
'
vulnerable
'
].
values
():
for
v
in
vv
[
'
vulnerabilities
'
]:
for
v
in
vv
[
'
vulnerabilities
'
]:
s
=
Severity
(
v
[
'
severity_str
'
]
)
r
=
ReportInfo
(
f
'
Severity
{
v
[
"
severity_str
"
]
}
'
)
if
s
>
max_severity
:
if
r
>
report_info
:
max_severity
=
s
report_info
=
r
with
open
(
f
'
{
json_data
[
"
output_path
"
]
}
.
severity
'
,
'
w+
'
)
as
severity
:
with
open
(
f
'
{
json_data
[
"
output_path
"
]
}
.
info
'
,
'
w+
'
)
as
info
:
severity
.
write
(
max_severity
.
toJSON
())
info
.
write
(
report_info
.
toJSON
())
return
self
.
_template
.
render
(
data
=
json_data
)
return
self
.
_template
.
render
(
data
=
json_data
)
...
...
This diff is collapsed.
Click to expand it.
run.sh
+
3
−
3
View file @
b9bf3512
...
@@ -20,7 +20,7 @@ xml_subdir=$xml_dir/$current_time
...
@@ -20,7 +20,7 @@ xml_subdir=$xml_dir/$current_time
report_subdir
=
$report_dir
/
$current_time
report_subdir
=
$report_dir
/
$current_time
report_file
=
report_
$current_time
.
$report_extension
report_file
=
report_
$current_time
.
$report_extension
severity
_file
=
report_
$current_time
.
severity
info
_file
=
report_
$current_time
.
info
if
[[
!
-z
$project
]]
if
[[
!
-z
$project
]]
then
then
...
@@ -28,7 +28,7 @@ then
...
@@ -28,7 +28,7 @@ then
report_subdir
=
$report_dir
/
$project
/
$current_time
report_subdir
=
$report_dir
/
$project
/
$current_time
report_file
=
report_
$project
\_
$current_time
.
$report_extension
report_file
=
report_
$project
\_
$current_time
.
$report_extension
severity
_file
=
report_
$project
\_
$current_time
.
severity
info
_file
=
report_
$project
\_
$current_time
.
info
fi
fi
function
upload
{
function
upload
{
...
@@ -87,4 +87,4 @@ then
...
@@ -87,4 +87,4 @@ then
sed
-i
's/%/\\%/g'
$root_dir
/
$report_dir
/
$report_file
sed
-i
's/%/\\%/g'
$root_dir
/
$report_dir
/
$report_file
fi
fi
upload
$report_subdir
/
$report_file
upload
$report_subdir
/
$report_file
upload
$report_subdir
/
$
severity
_file
upload
$report_subdir
/
$
info
_file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment