mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-17 17:41:50 +00:00
fix(s3): add ContentType in upload_file (#7643)
Co-authored-by: Pedro Martín <pedromarting3@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
|
||||
- Improve compliance and dashboard [(#7596)](https://github.com/prowler-cloud/prowler/pull/7596)
|
||||
- Remove invalid parameter `create_file_descriptor` [(#7600)](https://github.com/prowler-cloud/prowler/pull/7600)
|
||||
- Remove first empty line in HTML output [(#7606)](https://github.com/prowler-cloud/prowler/pull/7606)
|
||||
- Ensure that ContentType in upload_file matches the uploaded file’s format [(#7635)](https://github.com/prowler-cloud/prowler/pull/7635)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -105,6 +105,12 @@ class S3:
|
||||
"""
|
||||
try:
|
||||
uploaded_objects = {"success": {}, "failure": {}}
|
||||
extension_to_content_type = {
|
||||
".html": "text/html",
|
||||
".csv": "text/csv",
|
||||
".ocsf.json": "application/json",
|
||||
".asff.json": "application/json",
|
||||
}
|
||||
# Keys are regular and/or compliance
|
||||
for key, output_list in outputs.items():
|
||||
for output in output_list:
|
||||
@@ -115,6 +121,7 @@ class S3:
|
||||
|
||||
bucket_directory = self.get_object_path(self._output_directory)
|
||||
basename = path.basename(output.file_descriptor.name)
|
||||
file_extension = output.file_extension
|
||||
|
||||
if key == "compliance":
|
||||
object_name = f"{bucket_directory}/{key}/{basename}"
|
||||
@@ -128,7 +135,12 @@ class S3:
|
||||
# into the local filesystem because S3 upload file is the recommended way.
|
||||
# https://aws.amazon.com/blogs/developer/uploading-files-to-amazon-s3/
|
||||
self._session.upload_file(
|
||||
output.file_descriptor.name, self._bucket_name, object_name
|
||||
Filename=output.file_descriptor.name,
|
||||
Bucket=self._bucket_name,
|
||||
Key=object_name,
|
||||
ExtraArgs={
|
||||
"ContentType": extension_to_content_type[file_extension]
|
||||
},
|
||||
)
|
||||
|
||||
if output.file_extension in uploaded_objects["success"]:
|
||||
|
||||
@@ -93,7 +93,7 @@ class TestS3:
|
||||
Bucket=S3_BUCKET_NAME,
|
||||
Key=uploaded_object_name,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
== "text/csv"
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
@@ -132,7 +132,7 @@ class TestS3:
|
||||
Bucket=S3_BUCKET_NAME,
|
||||
Key=uploaded_object_name,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
== "text/csv"
|
||||
)
|
||||
|
||||
remove(f"{CURRENT_DIRECTORY}/{csv_file}")
|
||||
@@ -171,7 +171,7 @@ class TestS3:
|
||||
Bucket=S3_BUCKET_NAME,
|
||||
Key=uploaded_object_name,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
== "application/json"
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
@@ -209,7 +209,7 @@ class TestS3:
|
||||
Bucket=S3_BUCKET_NAME,
|
||||
Key=uploaded_object_name,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
== "text/html"
|
||||
)
|
||||
|
||||
@mock_aws
|
||||
@@ -290,7 +290,7 @@ class TestS3:
|
||||
Bucket=S3_BUCKET_NAME,
|
||||
Key=uploaded_object_name,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
== "text/csv"
|
||||
)
|
||||
|
||||
def test_get_get_object_path_with_prowler(self):
|
||||
|
||||
Reference in New Issue
Block a user