From f5b8bbf9746a75b1913c296acf970513fd037dd9 Mon Sep 17 00:00:00 2001 From: Mingfei Shao Date: Tue, 13 Aug 2024 15:47:14 -0500 Subject: [PATCH 1/2] json type --- manifestservice/manifests/__init__.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/manifestservice/manifests/__init__.py b/manifestservice/manifests/__init__.py index d95ea91..59ba14f 100644 --- a/manifestservice/manifests/__init__.py +++ b/manifestservice/manifests/__init__.py @@ -1,13 +1,12 @@ +import json import flask import html import boto3 from flask import current_app as app import re -import requests import ntpath -from datetime import date, datetime +from datetime import datetime from authutils.token.validate import current_token, validate_request, set_current_token -from authutils import user as authutils_user from cdislogging import get_logger logger = get_logger("manifestservice_logger", log_level="info") @@ -323,13 +322,12 @@ def _add_metadata_to_bucket(current_token, metadata_body): result["metadata"], file_type="metadata" ) - metadata_as_bytes = str.encode(str(metadata_body)) filepath_in_bucket = folder_name + "/exported-metadata/" + filename try: obj = s3.Object( flask.current_app.config.get("MANIFEST_BUCKET_NAME"), filepath_in_bucket ) - obj.put(Body=metadata_as_bytes) + obj.put(Body=bytes(json.dumps(metadata_body).encode('UTF-8'))) except Exception as e: return str(e), False @@ -357,14 +355,13 @@ def _add_manifest_to_bucket(current_token, manifest_json): filename = _generate_unique_filename( result["manifests"], ) - manifest_as_bytes = str.encode(str(flask.request.json)) filepath_in_bucket = folder_name + "/" + filename try: obj = s3.Object( flask.current_app.config.get("MANIFEST_BUCKET_NAME"), filepath_in_bucket ) - obj.put(Body=manifest_as_bytes) + obj.put(Body=bytes(json.dumps(manifest_json).encode('UTF-8'))) except Exception as e: logger.error(f"Failed to add manifest to bucket: {e}") return str(e), False From d28654577ac0c67d3a564b7d096ace634795409f Mon Sep 17 00:00:00 2001 From: Mingfei Shao Date: Tue, 13 Aug 2024 21:38:47 -0500 Subject: [PATCH 2/2] update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 53ff2f3..7e90f07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "manifestservice" -version = "0.5.0" +version = "0.5.2" description = "Handles reading from and writing to a user's s3 folder containing their manifests" authors = ["CTDS UChicago "] license = "Apache-2.0"