From: pmikus Date: Tue, 10 Aug 2021 11:31:16 +0000 (+0000) Subject: Fix: Add text/html mimetype to handle s3 logs X-Git-Tag: v0.35.6^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F68508%2F1;p=releng%2Flftools.git Fix: Add text/html mimetype to handle s3 logs 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 Signed-off-by: Anil Belur Change-Id: Id8a26f77446890320b212522236b68552d73c425 --- diff --git a/lftools/deploy.py b/lftools/deploy.py index cfbfe819..fbf8ea6b 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -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 index 00000000..b2039bdc --- /dev/null +++ b/releasenotes/notes/s3-html-60b86a77657a7bb4.yaml @@ -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.