Fix: Move text/html mimetype check to after None 29/68529/2 v0.35.7
authorEric Ball <eball@linuxfoundation.org>
Fri, 13 Aug 2021 01:40:17 +0000 (18:40 -0700)
committerEric Ball <eball@linuxfoundation.org>
Fri, 13 Aug 2021 01:46:53 +0000 (18:46 -0700)
When checking mimetype during _upload_to_s3, the newly-added
text/html type was checking before it is checked for None, which is a
potential TypeError.

By moving it after the variable is checked for None, the feature is
safe without requiring any further modifications.

Change-Id: Ia945893adb8973608cb9527b4ea811a5610d6aba
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
lftools/deploy.py
releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml [new file with mode: 0644]

index fbf8ea6..183ccdd 100755 (executable)
@@ -447,16 +447,16 @@ 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
+        elif mimetypes.guess_type(file)[0] is None or mimetypes.guess_type(file)[0] in "text/plain":
+            extra_args = text_plain_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
+        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:
diff --git a/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml b/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml
new file mode 100644 (file)
index 0000000..6c015af
--- /dev/null
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    When checking mimetype during _upload_to_s3, the newly-added text/html type
+    was checking before it is checked for None, which is a potential TypeError.
+    By moving it after the variable is checked for None, the feature is safe
+    without requiring any further modifications.