Skip to content
Snippets Groups Projects
Unverified Commit 19be800c authored by Roman Karwacik's avatar Roman Karwacik
Browse files

Feature: Use S3 presigned urls instead of direct links

parent 2a200632
Branches
No related tags found
1 merge request!47Draft: Support for S3
......@@ -40,3 +40,8 @@ MAIL_DEFAULT = 'Video AG <videoag@fsmpi.rwth-aachen.de>'
MAIL_ADMINS = 'videoag-it@lists.fsmpi.rwth-aachen.de'
STREAMING_SERVER = 'rtmp://video-web-0.fsmpi.rwth-aachen.de/src/'
BACKUP_STREAMING_SERVER = 'rtmp://video-web-1.fsmpi.rwth-aachen.de/src/'
S3_ACCESS_KEY = None
S3_SECRET_KEY = None
S3_ENDPOINT = "http://rgw.fsmpi.rwth-aachen.de:7480"
S3_BUCKET_NAME = "VIDEO.rgw.fsmpi.rwth-aachen.de"
# required
flask
requests
boto3
# optional
lxml
......
......@@ -7,6 +7,7 @@ import traceback
import string
import locale
import urllib
import boto3
from flask import Flask, request, url_for, redirect, session, render_template, flash, Response, make_response
from werkzeug.routing import Rule
......@@ -39,6 +40,10 @@ if config['DEBUG']:
if not config.get('SECRET_KEY', None):
config['SECRET_KEY'] = os.urandom(24)
if config.get("S3_ACCESS_KEY") and config.get("S3_SECRET_KEY"):
b3_session = boto3.Session(aws_access_key_id=config["S3_ACCESS_KEY"],
aws_secret_access_key=config["S3_SECRET_KEY"])
mod_endpoints = [] #pylint: disable=invalid-name
def mod_required(func):
mod_endpoints.append(func.__name__)
......@@ -539,6 +544,18 @@ def auth(): #pylint: disable=too-many-branches
@app.route('/files/<filename>')
def files(filename):
if config.get("S3_ACCESS_KEY") and config.get("S3_SECRET_KEY"):
s3_client = b3_session.client('s3', endpoint_url=config["S3_ENDPOINT"])
# creates a presigned url, doesn't check wether the object exists though
try:
generated_url = s3_client.generate_presigned_url('get_object',
Params={"Bucket":config["S3_BUCKET_NAME"], "Key": filename},
ExpiresIn=3600)
except:
notify_admins('s3 error', traceback="creating presigned url failed!")
return None
return redirect(generated_url)
else:
return redirect(config['VIDEOPREFIX']+'/'+filename)
@app.route('/sitemap.xml')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment