From b2835f462d9c072a10afa2c1edc3436855f1231a Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Thu, 12 Aug 2021 18:40:17 -0700 Subject: [PATCH] Fix: Move text/html mimetype check to after None 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 --- lftools/deploy.py | 8 ++++---- releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml diff --git a/lftools/deploy.py b/lftools/deploy.py index fbf8ea6b..183ccddb 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -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 index 00000000..6c015af3 --- /dev/null +++ b/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml @@ -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. -- 2.16.6