Fix: Add text/html mimetype to handle s3 logs 08/68508/1 v0.35.6
authorpmikus <peter.mikus@protonmail.ch>
Tue, 10 Aug 2021 11:31:16 +0000 (11:31 +0000)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 11 Aug 2021 12:55:27 +0000 (22:55 +1000)
Currently html files in S3 bucket are not rendered properly
via Cloudfront as they are sent with text/plain content-type.
This patch is setting up content-tyepe for html for text/html.

Signed-off-by: pmikus <peter.mikus@protonmail.ch>
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
Change-Id: Id8a26f77446890320b212522236b68552d73c425

lftools/deploy.py
releasenotes/notes/s3-html-60b86a77657a7bb4.yaml [new file with mode: 0644]

index cfbfe81..fbf8ea6 100755 (executable)
@@ -429,6 +429,7 @@ def deploy_s3(s3_bucket, s3_path, build_url, workspace, pattern=None):
 
     def _upload_to_s3(file):
         extra_args = {"ContentType": "text/plain"}
+        text_html_extra_args = {"ContentType": "text/html", "ContentEncoding": mimetypes.guess_type(file)[1]}
         text_plain_extra_args = {"ContentType": "text/plain", "ContentEncoding": mimetypes.guess_type(file)[1]}
         app_xml_extra_args = {"ContentType": "application/xml'", "ContentEncoding": mimetypes.guess_type(file)[1]}
         if file == "_tmpfile":
@@ -446,6 +447,14 @@ def deploy_s3(s3_bucket, s3_path, build_url, workspace, pattern=None):
                 log.error(e)
                 return False
             return True
+        elif mimetypes.guess_type(file)[0] in "text/html":
+            extra_args = text_html_extra_args
+            try:
+                s3.Bucket(s3_bucket).upload_file(file, "{}{}".format(s3_path, file), ExtraArgs=extra_args)
+            except ClientError as e:
+                log.error(e)
+                return False
+            return True
         elif mimetypes.guess_type(file)[0] is None or mimetypes.guess_type(file)[0] in "text/plain":
             extra_args = text_plain_extra_args
             try:
diff --git a/releasenotes/notes/s3-html-60b86a77657a7bb4.yaml b/releasenotes/notes/s3-html-60b86a77657a7bb4.yaml
new file mode 100644 (file)
index 0000000..b2039bd
--- /dev/null
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    Handle content-type for html uploaded files to S3 storage correctly.
+    This fixes the issue with detecting and setting ExtraArgs for html
+    to text/html instead of text/plain.