Extract app from torrent handling code

Fixes https://jira.coreos.com/browse/QUAY-969
This commit is contained in:
Joseph Schorr 2018-06-14 17:29:39 -04:00
parent c92c0ca5e1
commit 0fdefd78e9
7 changed files with 63 additions and 53 deletions

View file

@ -5,7 +5,7 @@ from flask import redirect, Blueprint, abort, send_file, make_response, request
import features
from app import app, signer, storage, metric_queue, config_provider, ip_resolver
from app import app, signer, storage, metric_queue, config_provider, ip_resolver, instance_keys
from auth.auth_context import get_authenticated_user
from auth.decorators import process_auth
from auth.permissions import ReadRepositoryPermission
@ -22,8 +22,8 @@ from util.registry.filelike import wrap_with_handler
from util.registry.queuefile import QueueFile
from util.registry.queueprocess import QueueProcess
from util.registry.tarlayerformat import TarLayerFormatterReporter
from util.registry.torrent import (
make_torrent, per_user_torrent_filename, public_torrent_filename, PieceHasher)
from util.registry.torrent import (make_torrent, per_user_torrent_filename, public_torrent_filename,
PieceHasher, TorrentConfiguration)
logger = logging.getLogger(__name__)
@ -137,6 +137,9 @@ def _torrent_for_blob(blob, is_public):
# We cannot support webseeds for storages that cannot provide direct downloads.
exact_abort(501, 'Storage engine does not support seeding.')
# Load the config for building torrents.
torrent_config = TorrentConfiguration.from_app_config(instance_keys, app.config)
# Build the filename for the torrent.
if is_public:
name = public_torrent_filename(blob.uuid)
@ -145,10 +148,10 @@ def _torrent_for_blob(blob, is_public):
if not user:
abort(403)
name = per_user_torrent_filename(user.uuid, blob.uuid)
name = per_user_torrent_filename(torrent_config, user.uuid, blob.uuid)
# Return the torrent file.
torrent_file = make_torrent(name, webseed, blob.size, torrent_info.piece_length,
torrent_file = make_torrent(torrent_config, name, webseed, blob.size, torrent_info.piece_length,
torrent_info.pieces)
headers = {