mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-30 23:34:27 +00:00
chore: change output folder (#8447)
This commit is contained in:
1 parent
92bc992e7f
commit
a9d16bbbce
5 files changed
+57
-31
No files matched your search
@@ -83,13 +83,6 @@ def upload_s3_integration(
|
||||
for integration in integrations:
|
||||
try:
|
||||
connected, s3 = get_s3_client_from_integration(integration)
|
||||
# Since many scans will be send to the same S3 bucket, we need to
|
||||
# add the output directory to the S3 output directory to avoid
|
||||
# overwriting the files and known the scan origin.
|
||||
folder = os.getenv("OUTPUT_DIRECTORY", "/tmp/prowler_api_output")
|
||||
s3._output_directory = (
|
||||
f"{s3._output_directory}{output_directory.split(folder)[-1]}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"S3 connection failed for integration {integration.id}: {e}"
|
||||
|
||||
@@ -331,6 +331,35 @@ class TestS3IntegrationUploads:
|
||||
# Verify complex path normalization
|
||||
assert configuration["output_directory"] == "test/folder/subfolder"
|
||||
|
||||
@patch("tasks.jobs.integrations.S3")
|
||||
def test_s3_client_uses_output_directory_in_object_paths(self, mock_s3_class):
|
||||
"""Test that S3 client uses output_directory correctly when generating object paths."""
|
||||
mock_integration = MagicMock()
|
||||
mock_integration.credentials = {
|
||||
"aws_access_key_id": "AKIA...",
|
||||
"aws_secret_access_key": "SECRET",
|
||||
}
|
||||
mock_integration.configuration = {
|
||||
"bucket_name": "test-bucket",
|
||||
"output_directory": "my-custom-prefix/scan-results",
|
||||
}
|
||||
|
||||
mock_s3_instance = MagicMock()
|
||||
mock_connection = MagicMock()
|
||||
mock_connection.is_connected = True
|
||||
mock_s3_instance.test_connection.return_value = mock_connection
|
||||
mock_s3_class.return_value = mock_s3_instance
|
||||
|
||||
connected, s3 = get_s3_client_from_integration(mock_integration)
|
||||
|
||||
assert connected is True
|
||||
# Verify S3 was initialized with the correct output_directory
|
||||
mock_s3_class.assert_called_once_with(
|
||||
**mock_integration.credentials,
|
||||
bucket_name="test-bucket",
|
||||
output_directory="my-custom-prefix/scan-results",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestProwlerIntegrationConnectionTest:
|
||||
|
||||
Reference in new issue
Block a user