Skip to content

Commit

Permalink
Merge pull request #5 from KPMP/develop
Browse files Browse the repository at this point in the history
Merge develop into master for release 1.2
  • Loading branch information
rlreamy authored Nov 2, 2021
2 parents 8451adb + d7c5769 commit c335e79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea/
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
RUN apk add --no-cache gcc musl-dev linux-headers tzdata
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
RUN pip3 install -U flask-cors
CMD ["flask", "run"]
31 changes: 26 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
from datetime import timedelta
import os, sys, redis
from minio import Minio
from minio.error import (ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists)
from flask import Flask, redirect, send_file
import boto3
import botocore.exceptions
from minio.error import S3Error
from flask import Flask, redirect, send_file, Response
from flask_cors import CORS

app = Flask(__name__)
CORS(app)
cache = redis.Redis(host='redis', port=6379)
minioAccessKey = os.environ.get('MINIO_ACCESS_KEY')
minioSecretKey = os.environ.get('MINIO_SECRET_KEY')
s3Bucket = os.environ.get('BUCKET_NAME')
minioUrl = os.environ.get('MINIO_URL')
minioClient = Minio(minioUrl, access_key=minioAccessKey, secret_key=minioSecretKey, secure=False)
s3_client = boto3.client(
's3',
'us-east-1',
aws_access_key_id=minioAccessKey,
aws_secret_access_key=minioSecretKey
)

@app.route('/v1/file/download/<packageId>/<objectName>', methods=['GET'])
def downloadFile(packageId, objectName):
try:
objectNameFull = packageId + '/' + objectName
object = minioClient.get_object(s3Bucket, objectNameFull, request_headers=None)
return send_file(object, as_attachment=True, attachment_filename=objectName)
except ResponseError as err:
except S3Error as err:
print(err)
return err
return err

@app.route('/v1/derived/download/<packageId>/<objectName>', methods=['GET'])
def downloadDerivedFileS3PS(packageId, objectName):
try:
objectNameFull = packageId + '/derived/' + objectName
return s3_client.generate_presigned_url('get_object',
Params={'Bucket': s3Bucket, 'Key': objectNameFull},
ExpiresIn=3600)
except botocore.exceptions.ClientError as error:
print(error)
except botocore.exceptions.ParamValidationError as error:
print(error)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
flask
redis
minio
minio
boto3
flask-cors

0 comments on commit c335e79

Please sign in to comment.