Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IaC Scan Runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIACERE
public
The Platform
IaC Scan Runner
Commits
b7667882
Commit
b7667882
authored
2 years ago
by
penenadpi
Committed by
Anze Luzar
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed output handling in case of HTML response output
parent
d890ca9c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/iac_scan_runner/compatibility.py
+0
-1
0 additions, 1 deletion
src/iac_scan_runner/compatibility.py
src/iac_scan_runner/scan_runner.py
+14
-19
14 additions, 19 deletions
src/iac_scan_runner/scan_runner.py
src/iac_scan_runner/utils.py
+15
-0
15 additions, 0 deletions
src/iac_scan_runner/utils.py
with
29 additions
and
20 deletions
src/iac_scan_runner/compatibility.py
+
0
−
1
View file @
b7667882
...
...
@@ -54,7 +54,6 @@ class Compatibility:
try
:
for
root
,
folders
,
names
in
os
.
walk
(
iac_directory
):
for
f
in
names
:
print
(
f
)
if
(
f
.
find
(
"
.tf
"
)
or
f
.
find
(
"
.tftpl
"
))
>
-
1
:
types
.
append
(
"
terraform
"
)
scanned_terraform
.
append
(
f
)
...
...
This diff is collapsed.
Click to expand it.
src/iac_scan_runner/scan_runner.py
+
14
−
19
View file @
b7667882
...
...
@@ -37,10 +37,12 @@ from iac_scan_runner.utils import (
generate_random_pathname
,
unpack_archive_to_dir
,
write_string_to_file
,
file_to_string
)
from
pydantic
import
SecretStr
import
uuid
import
os
import
json
class
ScanRunner
:
def
__init__
(
self
):
...
...
@@ -142,22 +144,15 @@ class ScanRunner:
compatible_checks
=
self
.
compatibility_matrix
.
get_all_compatible_checks
(
self
.
iac_dir
)
non_compatible_checks
=
[]
if
scan_response_type
==
ScanResponseType
.
json
:
scan_output
=
{}
else
:
scan_output
=
""
if
selected_checks
:
for
selected_check
in
selected_checks
:
check
=
self
.
iac_checks
[
selected_check
]
if
check
.
enabled
:
if
selected_check
in
compatible_checks
:
check_output
=
check
.
run
(
self
.
iac_dir
)
if
scan_response_type
==
ScanResponseType
.
json
:
scan_output
[
selected_check
]
=
check_output
.
to_dict
()
else
:
# TODO: Discuss the format of this output
scan_output
+=
f
"
###
{
selected_check
}
###
\n
{
check_output
.
to_string
()
}
\n\n
"
write_string_to_file
(
check
.
name
,
dir_name
,
scan_output
[
check
.
name
][
"
output
"
])
self
.
results_summary
.
summarize_outcome
(
selected_check
,
scan_output
[
check
.
name
][
"
output
"
],
self
.
compatibility_matrix
.
scanned_files
,
Compatibility
.
compatibility_matrix
)
...
...
@@ -173,18 +168,18 @@ class ScanRunner:
for
iac_check
in
self
.
iac_checks
.
values
():
if
iac_check
.
enabled
:
check_output
=
iac_check
.
run
(
self
.
iac_dir
)
if
scan_response_type
==
ScanResponseType
.
json
:
scan_output
[
iac_check
.
name
]
=
check_output
.
to_dict
()
else
:
# TODO: Discuss the format of this output
scan_output
+=
(
f
"
###
{
iac_check
.
name
}
###
\n
{
check_output
.
to_string
()
}
\n\n
"
)
# TODO: Discuss the format of this output
write_string_to_file
(
iac_check
.
name
,
dir_name
,
scan_output
[
iac_check
.
name
][
"
output
"
]
)
if
scan_response_type
==
ScanResponseType
.
json
:
scan_output
=
json
.
loads
(
file_to_string
(
f
"
../outputs/json_dumps/
{
random_uuid
}
.json
"
))
else
:
scan_output
=
file_to_string
(
f
"
../outputs/generated_html/
{
random_uuid
}
.html
"
)
return
scan_output
def
enable_check
(
self
,
check_name
:
str
)
->
str
:
...
...
This diff is collapsed.
Click to expand it.
src/iac_scan_runner/utils.py
+
15
−
0
View file @
b7667882
...
...
@@ -97,3 +97,18 @@ def write_html_to_file(file_name: str, output_value: str):
text_file
.
write
(
output_value
)
except
Exception
as
e
:
raise
Exception
(
f
"
Error storing HTML to file:
{
str
(
e
)
}
.
"
)
def
file_to_string
(
file_path
:
str
):
"""
Reads the file given by path and returns its contents as string output
:param file_path: Path of the file
:return output: Content read from file in form of a string
"""
output
=
""
try
:
with
open
(
file_path
,
"
r
"
)
as
text_file
:
output
=
str
(
text_file
.
read
())
except
Exception
as
e
:
raise
Exception
(
f
"
Error while reading file:
{
str
(
e
)
}
.
"
)
return
output
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