Skip to content

Commit

Permalink
Fix: Move text/html mimetype check to after None
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eb-oss committed Aug 13, 2021
1 parent 0ef6527 commit b2835f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lftools/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,16 @@ def _upload_to_s3(file):
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:
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit b2835f4

Please sign in to comment.