diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9abb766 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e1ef8b9..f0c7f55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ FROM python:3.7.12-alpine3.14 WORKDIR /code -ENV FLASK_APP app.py -ENV FLASK_RUN_HOST 0.0.0.0 +ENV FLASK_APP=app.py +ENV FLASK_RUN_HOST=0.0.0.0 RUN apk add --no-cache gcc musl-dev linux-headers tzdata libffi-dev libc-dev +COPY app.py app.py COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt RUN pip3 install -U flask-cors diff --git a/app.py b/app.py index 44be0a1..8f6a948 100644 --- a/app.py +++ b/app.py @@ -33,7 +33,7 @@ class MYSQLConnection: def __init__(self): - logger.debug( + logger.info( "Start: MYSQLConnection().__init__(), trying to load environment variables in docker" ) self.host = None @@ -99,11 +99,8 @@ def get_file_info_by_file_name(file_name): "SELECT * FROM repo_file_v WHERE file_name = %s", (file_name,), ) -# /api/v1/file/download/46669edb-0e3e-4470-8834-e9ca30a50bc3/ -# 4a45bcae-3203-4319-b455-b28965b1587a_20240604_OpenAccessClinicalData.csv' - -@app.route('/v1/file/download//', methods=['GET']) +@app.route('/v1/file/download//', methods=['POST', 'GET']) def downloadFile(packageId, objectName): result = get_file_info_by_file_name(objectName) if result[0]["access"] == "open": @@ -113,15 +110,14 @@ def downloadFile(packageId, objectName): payload = { "client_id": "XXXXXXXXXX.YYYYYYYYYY", "events": [ - { - "name": "file_download", - "params": { - "file_name": objectName[59:] - } + { + "name": "file_download", + "params": { + "file_name": objectName } - ] + }] } - requests.post(url, json=payload, headers={'content-type': 'application/json'}, verify=True) + requests.post(url, json=payload, headers={"Content-Type": "application/json"}) return send_file(object, as_attachment=True, download_name=objectName) except S3Error as err: logger.error(err) @@ -138,7 +134,7 @@ def downloadDerivedFileS3PS(packageId, objectName): Params={'Bucket': s3Bucket, 'Key': objectNameFull}, ExpiresIn=3600) except botocore.exceptions.ClientError as error: - logger.error(err) + logger.error(error) except botocore.exceptions.ParamValidationError as error: - logger.error(err) + logger.error(error) diff --git a/requirements.txt b/requirements.txt index 9950f47..c4796ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ minio boto3 flask-cors mysql-connector-python +requests \ No newline at end of file