-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from KPMP/develop
Merge develop into master for release 1.2
- Loading branch information
Showing
4 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
flask | ||
redis | ||
minio | ||
minio | ||
boto3 | ||
flask-cors |