regscale-cli 6.16.0.0__py3-none-any.whl → 6.16.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of regscale-cli might be problematic. Click here for more details.
- regscale/__init__.py +1 -1
- regscale/core/app/application.py +1 -0
- regscale/core/app/internal/login.py +1 -1
- regscale/core/app/internal/poam_editor.py +1 -1
- regscale/core/app/utils/app_utils.py +1 -1
- regscale/core/app/utils/parser_utils.py +2 -2
- regscale/integrations/commercial/__init__.py +2 -2
- regscale/integrations/commercial/ad.py +1 -1
- regscale/integrations/commercial/azure/intune.py +1 -0
- regscale/integrations/commercial/grype/__init__.py +3 -0
- regscale/integrations/commercial/grype/commands.py +72 -0
- regscale/integrations/commercial/grype/scanner.py +390 -0
- regscale/integrations/commercial/import_all/import_all_cmd.py +2 -2
- regscale/integrations/commercial/nessus/scanner.py +3 -0
- regscale/integrations/commercial/opentext/__init__.py +6 -0
- regscale/integrations/commercial/opentext/commands.py +77 -0
- regscale/integrations/commercial/opentext/scanner.py +449 -85
- regscale/integrations/commercial/sap/sysdig/sysdig_scanner.py +4 -0
- regscale/integrations/commercial/sap/tenable/click.py +1 -1
- regscale/integrations/commercial/sap/tenable/scanner.py +8 -2
- regscale/integrations/commercial/tenablev2/click.py +39 -16
- regscale/integrations/commercial/trivy/__init__.py +5 -0
- regscale/integrations/commercial/trivy/commands.py +74 -0
- regscale/integrations/commercial/trivy/scanner.py +276 -0
- regscale/integrations/commercial/wizv2/click.py +9 -21
- regscale/integrations/commercial/wizv2/scanner.py +2 -1
- regscale/integrations/commercial/wizv2/utils.py +146 -70
- regscale/integrations/jsonl_scanner_integration.py +869 -0
- regscale/integrations/public/fedramp/fedramp_common.py +4 -4
- regscale/integrations/public/fedramp/import_workbook.py +1 -1
- regscale/integrations/public/fedramp/inventory_items.py +3 -3
- regscale/integrations/public/fedramp/poam/scanner.py +51 -44
- regscale/integrations/public/fedramp/ssp_logger.py +6 -6
- regscale/integrations/scanner_integration.py +268 -64
- regscale/models/app_models/mapping.py +3 -3
- regscale/models/integration_models/amazon_models/inspector.py +15 -17
- regscale/models/integration_models/aqua.py +1 -5
- regscale/models/integration_models/cisa_kev_data.json +100 -10
- regscale/models/integration_models/ecr_models/ecr.py +2 -6
- regscale/models/integration_models/{flat_file_importer.py → flat_file_importer/__init__.py} +7 -4
- regscale/models/integration_models/grype_import.py +3 -3
- regscale/models/integration_models/prisma.py +3 -3
- regscale/models/integration_models/synqly_models/capabilities.json +1 -1
- regscale/models/integration_models/synqly_models/connectors/assets.py +1 -0
- regscale/models/integration_models/synqly_models/connectors/vulnerabilities.py +2 -0
- regscale/models/integration_models/tenable_models/integration.py +46 -10
- regscale/models/integration_models/trivy_import.py +1 -1
- regscale/models/integration_models/xray.py +1 -1
- regscale/models/regscale_models/__init__.py +2 -0
- regscale/models/regscale_models/control_implementation.py +18 -44
- regscale/models/regscale_models/inherited_control.py +61 -0
- regscale/models/regscale_models/issue.py +3 -2
- regscale/models/regscale_models/mixins/parent_cache.py +1 -1
- regscale/models/regscale_models/regscale_model.py +73 -7
- regscale/models/regscale_models/vulnerability.py +61 -8
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/METADATA +3 -3
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/RECORD +62 -56
- tests/regscale/core/test_logz.py +8 -0
- regscale/integrations/commercial/grype.py +0 -165
- regscale/integrations/commercial/opentext/click.py +0 -99
- regscale/integrations/commercial/trivy.py +0 -162
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/LICENSE +0 -0
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/WHEEL +0 -0
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/entry_points.txt +0 -0
- {regscale_cli-6.16.0.0.dist-info → regscale_cli-6.16.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module for processing Grype scan results and loading them into RegScale.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import logging
|
|
6
|
-
import traceback
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
from typing import List, Optional, Union
|
|
9
|
-
|
|
10
|
-
import click
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
|
|
13
|
-
from regscale.core.app.utils.file_utils import (
|
|
14
|
-
download_from_s3,
|
|
15
|
-
find_files,
|
|
16
|
-
iterate_files,
|
|
17
|
-
move_file,
|
|
18
|
-
)
|
|
19
|
-
from regscale.models.integration_models.flat_file_importer import FlatFileImporter
|
|
20
|
-
from regscale.models.integration_models.grype_import import GrypeImport
|
|
21
|
-
|
|
22
|
-
logger = logging.getLogger(__name__)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class GrypeProcessingError(Exception):
|
|
26
|
-
"""Custom exception for Grype processing errors."""
|
|
27
|
-
|
|
28
|
-
pass
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@click.group()
|
|
32
|
-
def grype():
|
|
33
|
-
"""Performs actions from the Grype scanner integration."""
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@grype.command("import_scans")
|
|
38
|
-
@FlatFileImporter.common_scanner_options(
|
|
39
|
-
message="File path to the folder containing Grype .json files to process to RegScale.",
|
|
40
|
-
prompt="File path for Grype files",
|
|
41
|
-
import_name="grype",
|
|
42
|
-
)
|
|
43
|
-
@click.option("--destination", "-d", type=click.Path(exists=True, dir_okay=True), required=False)
|
|
44
|
-
@click.option("--file_pattern", "-p", type=str, required=False, default="grype*.json")
|
|
45
|
-
def import_scans(
|
|
46
|
-
destination: Optional[Path],
|
|
47
|
-
file_pattern: str,
|
|
48
|
-
folder_path: Path,
|
|
49
|
-
regscale_ssp_id: int,
|
|
50
|
-
scan_date: datetime,
|
|
51
|
-
mappings_path: Path,
|
|
52
|
-
disable_mapping: bool,
|
|
53
|
-
s3_bucket: str,
|
|
54
|
-
s3_prefix: str,
|
|
55
|
-
aws_profile: str,
|
|
56
|
-
upload_file: bool,
|
|
57
|
-
) -> None:
|
|
58
|
-
"""
|
|
59
|
-
Process Grype scan results from a folder containing Grype scan files and load into RegScale.
|
|
60
|
-
"""
|
|
61
|
-
import_grype_scans(
|
|
62
|
-
destination=destination,
|
|
63
|
-
file_pattern=file_pattern,
|
|
64
|
-
folder_path=folder_path,
|
|
65
|
-
regscale_ssp_id=regscale_ssp_id,
|
|
66
|
-
scan_date=scan_date,
|
|
67
|
-
mappings_path=mappings_path,
|
|
68
|
-
disable_mapping=disable_mapping,
|
|
69
|
-
s3_bucket=s3_bucket,
|
|
70
|
-
s3_prefix=s3_prefix,
|
|
71
|
-
aws_profile=aws_profile,
|
|
72
|
-
upload_file=upload_file,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def import_grype_scans(
|
|
77
|
-
folder_path: Path,
|
|
78
|
-
regscale_ssp_id: int,
|
|
79
|
-
scan_date: datetime,
|
|
80
|
-
mappings_path: Optional[Path] = None,
|
|
81
|
-
disable_mapping: Optional[bool] = False,
|
|
82
|
-
s3_bucket: Optional[str] = None,
|
|
83
|
-
s3_prefix: Optional[str] = None,
|
|
84
|
-
aws_profile: Optional[str] = None,
|
|
85
|
-
destination: Optional[Path] = None,
|
|
86
|
-
file_pattern: Optional[str] = "grype*.json",
|
|
87
|
-
upload_file: Optional[bool] = True,
|
|
88
|
-
) -> None:
|
|
89
|
-
"""
|
|
90
|
-
Process Grype scan results from a folder container grype scan files and load into RegScale.
|
|
91
|
-
|
|
92
|
-
:param Path folder_path: Path to the Grype scan results JSON file
|
|
93
|
-
:param int regscale_ssp_id: RegScale SSP ID
|
|
94
|
-
:param datetime scan_date: The date of the scan
|
|
95
|
-
:param Optional[Path] mappings_path: Path to the header mapping file, default: None
|
|
96
|
-
:param Optional[bool] disable_mapping: Disable the header mapping, default: False
|
|
97
|
-
:param Optional[str] s3_bucket: S3 bucket to download scan files from, default: None
|
|
98
|
-
:param Optional[str] s3_prefix: Prefix (folder path) within the S3 bucket, default: None
|
|
99
|
-
:param Optional[str] aws_profile: AWS profile to use for S3 access, default: None
|
|
100
|
-
:param Optional[Path] destination: Destination folder for processed files, default: None
|
|
101
|
-
:param Optional[str] file_pattern: File pattern to search for in the directory, default: grype*.json
|
|
102
|
-
:param Optional[bool] upload_file: Whether to upload the file to RegScale after processing, default: True
|
|
103
|
-
:raises GrypeProcessingError: If there is an error processing the Grype results
|
|
104
|
-
:rtype: None
|
|
105
|
-
"""
|
|
106
|
-
from regscale.exceptions import ValidationException
|
|
107
|
-
from regscale.core.app.application import Application
|
|
108
|
-
|
|
109
|
-
try:
|
|
110
|
-
if s3_bucket and s3_prefix and aws_profile:
|
|
111
|
-
download_from_s3(bucket=s3_bucket, prefix=s3_prefix, local_path=destination, aws_profile=aws_profile)
|
|
112
|
-
files = find_files(path=destination, pattern=file_pattern)
|
|
113
|
-
logger.info("Downloaded all Grype scan files from S3. Processing...")
|
|
114
|
-
elif destination and not s3_bucket:
|
|
115
|
-
logger.info("Moving Grype scan files to %s", destination)
|
|
116
|
-
stored_file_collection = find_files(path=folder_path, pattern=file_pattern)
|
|
117
|
-
move_all_files(stored_file_collection, destination)
|
|
118
|
-
files = find_files(path=destination, pattern=file_pattern)
|
|
119
|
-
logger.info("Done moving files")
|
|
120
|
-
else:
|
|
121
|
-
stored_file_collection = find_files(path=folder_path, pattern=file_pattern)
|
|
122
|
-
files = stored_file_collection
|
|
123
|
-
if not files:
|
|
124
|
-
logger.error("No Grype scan results found in the specified directory")
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
except Exception as e:
|
|
128
|
-
logger.error(f"Error processing Grype results: {str(e)}")
|
|
129
|
-
logger.error(traceback.format_exc())
|
|
130
|
-
raise GrypeProcessingError(f"Failed to process Grype results: {str(e)}")
|
|
131
|
-
|
|
132
|
-
for file in files:
|
|
133
|
-
try:
|
|
134
|
-
GrypeImport(
|
|
135
|
-
name="Grype",
|
|
136
|
-
app=Application(),
|
|
137
|
-
file_path=str(file),
|
|
138
|
-
file_type=file.suffix,
|
|
139
|
-
parent_id=regscale_ssp_id,
|
|
140
|
-
parent_module="securityplans",
|
|
141
|
-
scan_date=scan_date,
|
|
142
|
-
mappings_path=mappings_path,
|
|
143
|
-
disable_mapping=disable_mapping,
|
|
144
|
-
upload_file=upload_file,
|
|
145
|
-
file_name=file.name,
|
|
146
|
-
)
|
|
147
|
-
except ValidationException as e:
|
|
148
|
-
logger.error(f"Validation error on {file}: {e}")
|
|
149
|
-
continue
|
|
150
|
-
logger.info("Completed Grype processing.")
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def move_all_files(file_collection: List[Union[Path, str]], destination: Union[Path, str]) -> None:
|
|
154
|
-
"""
|
|
155
|
-
Move all Grype files in the current directory to a folder called 'processed'.
|
|
156
|
-
|
|
157
|
-
:param List[Union[Path, str]] file_collection: A list of file paths or S3 URIs
|
|
158
|
-
:param Union[Path, str] destination: The destination folder
|
|
159
|
-
:rtype: None
|
|
160
|
-
"""
|
|
161
|
-
for file in iterate_files(file_collection):
|
|
162
|
-
file_path = Path(file)
|
|
163
|
-
new_filename = f"{file_path.stem}{file_path.suffix}"
|
|
164
|
-
new_file_path = Path(destination) / new_filename
|
|
165
|
-
move_file(file, new_file_path)
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module contains the Click commands for the opentext integration.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
# pylint: disable=W0621
|
|
6
|
-
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
from os import PathLike
|
|
9
|
-
from typing import Optional
|
|
10
|
-
|
|
11
|
-
import click
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
from regscale.integrations.commercial.opentext.scanner import WebInspect
|
|
15
|
-
from regscale.models.integration_models.flat_file_importer import FlatFileImporter
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@click.group()
|
|
19
|
-
def fortify():
|
|
20
|
-
"""Performs actions on the OpenText Fortify"""
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@fortify.group(name="web_inspect")
|
|
24
|
-
def web_inspect():
|
|
25
|
-
"""Performs actions on the OpenText Web Inspect files."""
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@web_inspect.command(name="import_file")
|
|
29
|
-
@FlatFileImporter.common_scanner_options(
|
|
30
|
-
message="File path to the folder containing Fortify WebInspect .xml files to process to RegScale.",
|
|
31
|
-
prompt="File path for Web Inspect files",
|
|
32
|
-
import_name="web_inspect",
|
|
33
|
-
)
|
|
34
|
-
def import_file(
|
|
35
|
-
folder_path: PathLike[str],
|
|
36
|
-
regscale_ssp_id: int,
|
|
37
|
-
scan_date: datetime,
|
|
38
|
-
mappings_path: Path,
|
|
39
|
-
disable_mapping: bool,
|
|
40
|
-
s3_bucket: str,
|
|
41
|
-
s3_prefix: str,
|
|
42
|
-
aws_profile: str,
|
|
43
|
-
upload_file: bool,
|
|
44
|
-
):
|
|
45
|
-
"""
|
|
46
|
-
Import and process a folder of Fortify WebInspect XML file(s).
|
|
47
|
-
"""
|
|
48
|
-
import_opentext_file(
|
|
49
|
-
folder_path=folder_path,
|
|
50
|
-
regscale_ssp_id=regscale_ssp_id,
|
|
51
|
-
scan_date=scan_date,
|
|
52
|
-
mappings_path=mappings_path,
|
|
53
|
-
disable_mapping=disable_mapping,
|
|
54
|
-
s3_bucket=s3_bucket,
|
|
55
|
-
s3_prefix=s3_prefix,
|
|
56
|
-
aws_profile=aws_profile,
|
|
57
|
-
upload_file=upload_file,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def import_opentext_file(
|
|
62
|
-
folder_path: PathLike[str],
|
|
63
|
-
regscale_ssp_id: int,
|
|
64
|
-
scan_date: datetime,
|
|
65
|
-
mappings_path: Optional[Path] = None,
|
|
66
|
-
disable_mapping: Optional[bool] = False,
|
|
67
|
-
s3_bucket: Optional[str] = None,
|
|
68
|
-
s3_prefix: Optional[str] = None,
|
|
69
|
-
aws_profile: Optional[str] = None,
|
|
70
|
-
upload_file: Optional[bool] = True,
|
|
71
|
-
) -> None:
|
|
72
|
-
"""
|
|
73
|
-
Import and process a folder of Fortify WebInspect XML file(s).
|
|
74
|
-
|
|
75
|
-
:param click.Path folder_path: The Path to a folder of XML file(s) to import
|
|
76
|
-
:param int regscale_ssp_id: RegScale SSP ID
|
|
77
|
-
:param datetime scan_date: The date of the scan
|
|
78
|
-
:param Optional[Path] mappings_path: Path to the header mapping file, default: None
|
|
79
|
-
:param Optional[bool] disable_mapping: Disable the header mapping, default: False
|
|
80
|
-
:param Optional[str] s3_bucket: S3 bucket to download scan files from, default: None
|
|
81
|
-
:param Optional[str] s3_prefix: Prefix (folder path) within the S3 bucket, default: None
|
|
82
|
-
:param Optional[str] aws_profile: AWS profile to use for S3 access, default: None
|
|
83
|
-
:param Optional[bool] upload_file: Whether to upload the file to RegScale after processing, default: True
|
|
84
|
-
:return: None
|
|
85
|
-
"""
|
|
86
|
-
FlatFileImporter.import_files(
|
|
87
|
-
import_type=WebInspect,
|
|
88
|
-
import_name="Web Inspect",
|
|
89
|
-
file_types=".xml",
|
|
90
|
-
folder_path=folder_path,
|
|
91
|
-
regscale_ssp_id=regscale_ssp_id,
|
|
92
|
-
scan_date=scan_date,
|
|
93
|
-
mappings_path=mappings_path,
|
|
94
|
-
disable_mapping=disable_mapping,
|
|
95
|
-
s3_bucket=s3_bucket,
|
|
96
|
-
s3_prefix=s3_prefix,
|
|
97
|
-
aws_profile=aws_profile,
|
|
98
|
-
upload_file=upload_file,
|
|
99
|
-
)
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module for processing Trivy scan results and loading them into RegScale.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import logging
|
|
6
|
-
import traceback
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
from typing import List, Optional, Union
|
|
9
|
-
|
|
10
|
-
import click
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
|
|
13
|
-
from regscale.core.app.utils.file_utils import (
|
|
14
|
-
download_from_s3,
|
|
15
|
-
find_files,
|
|
16
|
-
iterate_files,
|
|
17
|
-
move_file,
|
|
18
|
-
)
|
|
19
|
-
from regscale.models.integration_models.flat_file_importer import FlatFileImporter
|
|
20
|
-
from regscale.models.integration_models.trivy_import import TrivyImport
|
|
21
|
-
|
|
22
|
-
logger = logging.getLogger(__name__)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class TrivyProcessingError(Exception):
|
|
26
|
-
"""Custom exception for Trivy processing errors."""
|
|
27
|
-
|
|
28
|
-
pass
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@click.group()
|
|
32
|
-
def trivy():
|
|
33
|
-
"""Performs actions from the Trivy scanner integration."""
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@trivy.command("import_scans")
|
|
38
|
-
@FlatFileImporter.common_scanner_options(
|
|
39
|
-
message="File path to the folder containing Trivy .json files to process to RegScale.",
|
|
40
|
-
prompt="File path for Trivy files",
|
|
41
|
-
import_name="trivy",
|
|
42
|
-
)
|
|
43
|
-
@click.option("--destination", "-d", type=click.Path(exists=True, dir_okay=True), required=False)
|
|
44
|
-
@click.option("--file_pattern", "-p", type=str, required=False, default="trivy*.json")
|
|
45
|
-
def import_scans(
|
|
46
|
-
destination: Optional[Path],
|
|
47
|
-
file_pattern: str,
|
|
48
|
-
folder_path: Path,
|
|
49
|
-
regscale_ssp_id: int,
|
|
50
|
-
scan_date: datetime,
|
|
51
|
-
mappings_path: Path,
|
|
52
|
-
disable_mapping: bool,
|
|
53
|
-
s3_bucket: str,
|
|
54
|
-
s3_prefix: str,
|
|
55
|
-
aws_profile: str,
|
|
56
|
-
upload_file: bool,
|
|
57
|
-
) -> None:
|
|
58
|
-
"""
|
|
59
|
-
Process Trivy scan results from a folder containing trivy scan files and load into RegScale.
|
|
60
|
-
"""
|
|
61
|
-
import_trivy_scans(
|
|
62
|
-
destination=destination,
|
|
63
|
-
file_pattern=file_pattern,
|
|
64
|
-
folder_path=folder_path,
|
|
65
|
-
regscale_ssp_id=regscale_ssp_id,
|
|
66
|
-
scan_date=scan_date,
|
|
67
|
-
mappings_path=mappings_path,
|
|
68
|
-
disable_mapping=disable_mapping,
|
|
69
|
-
s3_bucket=s3_bucket,
|
|
70
|
-
s3_prefix=s3_prefix,
|
|
71
|
-
aws_profile=aws_profile,
|
|
72
|
-
upload_file=upload_file,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def import_trivy_scans(
|
|
77
|
-
folder_path: Path,
|
|
78
|
-
regscale_ssp_id: int,
|
|
79
|
-
scan_date: datetime,
|
|
80
|
-
mappings_path: Optional[Path] = None,
|
|
81
|
-
disable_mapping: Optional[bool] = False,
|
|
82
|
-
s3_bucket: Optional[str] = None,
|
|
83
|
-
s3_prefix: Optional[str] = None,
|
|
84
|
-
aws_profile: Optional[str] = None,
|
|
85
|
-
destination: Optional[Path] = None,
|
|
86
|
-
file_pattern: Optional[str] = "trivy*.json",
|
|
87
|
-
upload_file: Optional[bool] = True,
|
|
88
|
-
) -> None:
|
|
89
|
-
"""
|
|
90
|
-
Process Trivy scan results from a folder container trivy scan files and load into RegScale.
|
|
91
|
-
|
|
92
|
-
:param Path folder_path: Path to the Trivy scan results JSON file
|
|
93
|
-
:param int regscale_ssp_id: RegScale SSP ID
|
|
94
|
-
:param datetime scan_date: The date of the scan
|
|
95
|
-
:param Optional[Path] mappings_path: Path to the header mapping file, default: None
|
|
96
|
-
:param Optional[bool] disable_mapping: Disable the header mapping, default: False
|
|
97
|
-
:param Optional[str] s3_bucket: S3 bucket to download scan files from, default: None
|
|
98
|
-
:param Optional[str] s3_prefix: Prefix (folder path) within the S3 bucket, default: None
|
|
99
|
-
:param Optional[str] aws_profile: AWS profile to use for S3 access, default: None
|
|
100
|
-
:param Optional[Path] destination: The destination folder for the processed files, default: None
|
|
101
|
-
:param Optional[str] file_pattern: The file pattern to search for in the file path Default: trivy*.json
|
|
102
|
-
:param Optional[bool] upload_file: Whether to upload the file to RegScale after processing, default: True
|
|
103
|
-
"""
|
|
104
|
-
from regscale.exceptions import ValidationException
|
|
105
|
-
from regscale.core.app.application import Application
|
|
106
|
-
|
|
107
|
-
try:
|
|
108
|
-
if s3_bucket and s3_prefix and aws_profile:
|
|
109
|
-
download_from_s3(bucket=s3_bucket, prefix=s3_prefix, local_path=destination, aws_profile=aws_profile)
|
|
110
|
-
files = find_files(path=destination, pattern=file_pattern)
|
|
111
|
-
logger.info("Downloaded all Trivy scan files from S3. Processing...")
|
|
112
|
-
elif destination and not s3_bucket:
|
|
113
|
-
logger.info("Moving Trivy scan files to %s", destination)
|
|
114
|
-
stored_file_collection = find_files(path=folder_path, pattern=file_pattern)
|
|
115
|
-
move_all_files(stored_file_collection, destination)
|
|
116
|
-
files = find_files(path=destination, pattern=file_pattern)
|
|
117
|
-
logger.info("Done moving files")
|
|
118
|
-
else:
|
|
119
|
-
stored_file_collection = find_files(path=folder_path, pattern=file_pattern)
|
|
120
|
-
files = stored_file_collection
|
|
121
|
-
if not files:
|
|
122
|
-
logger.error("No Trivy scan results found in the specified directory")
|
|
123
|
-
return
|
|
124
|
-
except Exception as e:
|
|
125
|
-
logger.error(f"Error processing Trivy results: {str(e)}")
|
|
126
|
-
logger.error(traceback.format_exc())
|
|
127
|
-
raise TrivyProcessingError(f"Failed to process Trivy results: {str(e)}")
|
|
128
|
-
|
|
129
|
-
for file in files:
|
|
130
|
-
try:
|
|
131
|
-
TrivyImport(
|
|
132
|
-
name="Trivy",
|
|
133
|
-
app=Application(),
|
|
134
|
-
file_path=str(file),
|
|
135
|
-
file_type=file.suffix,
|
|
136
|
-
parent_id=regscale_ssp_id,
|
|
137
|
-
parent_module="securityplans",
|
|
138
|
-
scan_date=scan_date,
|
|
139
|
-
mappings_path=mappings_path,
|
|
140
|
-
disable_mapping=disable_mapping,
|
|
141
|
-
upload_file=upload_file,
|
|
142
|
-
file_name=file.name,
|
|
143
|
-
)
|
|
144
|
-
except ValidationException as e:
|
|
145
|
-
logger.error(f"Validation error on {file}: {e}")
|
|
146
|
-
continue
|
|
147
|
-
logger.info("Completed Trivy processing.")
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
def move_all_files(file_collection: List[Union[Path, str]], destination: Union[Path, str]) -> None:
|
|
151
|
-
"""
|
|
152
|
-
Move all Trivy files in the current directory to a folder called 'processed'.
|
|
153
|
-
|
|
154
|
-
:param List[Union[Path, str]] file_collection: A list of file paths or S3 URIs
|
|
155
|
-
:param Union[Path, str] destination: The destination folder
|
|
156
|
-
:rtype: None
|
|
157
|
-
"""
|
|
158
|
-
for file in iterate_files(file_collection):
|
|
159
|
-
file_path = Path(file)
|
|
160
|
-
new_filename = f"{file_path.stem}{file_path.suffix}"
|
|
161
|
-
new_file_path = Path(destination) / new_filename
|
|
162
|
-
move_file(file, new_file_path)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|