FIX: Improve ContentEncoding handling 37/33737/1
authorpmikus <pmikus@cisco.com>
Thu, 16 Sep 2021 12:28:34 +0000 (12:28 +0000)
committerpmikus <pmikus@cisco.com>
Thu, 16 Sep 2021 12:28:34 +0000 (12:28 +0000)
+ Each bucket has different settings that is accepted.
  This patch helps to make all buckets and jobs works
  as expected for their settings.

+ Tested on sandbox on all kind of jobs (tox,docs,trending)

Signed-off-by: pmikus <pmikus@cisco.com>
Change-Id: Ibf7e81f06c9bd9b3f17194231cbd4f7e83596305

jjb/scripts/publish_library_py.sh

index f9b6a37..a6e2edf 100644 (file)
@@ -126,25 +126,22 @@ def upload(s3_resource, s3_bucket, src_fpath, s3_path):
     :type src_fpath: str
     :type s3_path: str
     """
+    mime = MimeTypes().guess_type(src_fpath)[0]
+    encoding = MimeTypes().guess_type(src_fpath)[1]
+
     extra_args = {
         u"ContentType": u"text/plain"
     }
     text_html_extra_args = {
-        u"ContentType": u"text/html",
-        u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
+        u"ContentType": u"text/html"
     }
     text_plain_extra_args = {
-        u"ContentType": u"text/plain",
-        u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
+        u"ContentType": u"text/plain"
     }
     app_xml_extra_args = {
-        u"ContentType": u"application/xml",
-        u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
+        u"ContentType": u"application/xml"
     }
 
-    mime = MimeTypes().guess_type(src_fpath)[0]
-    encoding = MimeTypes().guess_type(src_fpath)[1]
-
     if mime is None and encoding is None:
         extra_args = extra_args
     elif mime is None or mime in u"text/plain":
@@ -156,6 +153,9 @@ def upload(s3_resource, s3_bucket, src_fpath, s3_path):
     else:
         extra_args = extra_args
 
+    if encoding:
+        extra_args[u"ContentEncoding"] = encoding
+
     try:
         s3_resource.Bucket(s3_bucket).upload_file(
             src_fpath, s3_path, ExtraArgs=extra_args
@@ -250,7 +250,7 @@ def deploy_s3(s3_bucket, s3_path, build_url, workspace):
     except KeyError:
         s3_resource = boto3.resource(
             u"s3"
-        )  
+        )
 
     previous_dir = os.getcwd()
     work_dir = tempfile.mkdtemp(prefix="backup-s3.")