2014-09-16 04:18:57 +00:00
|
|
|
import logging
|
2014-09-19 16:22:54 +00:00
|
|
|
import hashlib
|
2014-09-16 04:18:57 +00:00
|
|
|
|
2016-01-20 21:33:10 +00:00
|
|
|
from flask import redirect, Blueprint, abort, send_file, make_response, request
|
2014-09-16 04:18:57 +00:00
|
|
|
|
2016-01-15 16:32:29 +00:00
|
|
|
import features
|
|
|
|
|
2016-10-10 20:23:42 +00:00
|
|
|
from app import app, signer, storage, metric_queue, license_validator
|
2015-12-31 19:10:36 +00:00
|
|
|
from auth.auth_context import get_authenticated_user
|
2014-09-16 04:18:57 +00:00
|
|
|
from auth.permissions import ReadRepositoryPermission
|
2016-09-29 19:24:57 +00:00
|
|
|
from auth.process import process_auth
|
2016-09-01 23:00:11 +00:00
|
|
|
from data import database
|
2016-09-23 21:50:09 +00:00
|
|
|
from data.interfaces.verbs import pre_oci_model as model
|
2016-08-02 22:45:30 +00:00
|
|
|
from endpoints.common import route_show_if, parse_repository_name
|
2015-05-19 21:52:44 +00:00
|
|
|
from endpoints.decorators import anon_protect
|
2016-08-02 22:45:30 +00:00
|
|
|
from endpoints.trackhelper import track_and_log
|
|
|
|
from endpoints.v2.blob import BLOB_DIGEST_ROUTE
|
|
|
|
from image.appc import AppCImageFormatter
|
|
|
|
from image.docker.squashed import SquashedDockerImageFormatter
|
|
|
|
from storage import Storage
|
|
|
|
from util.registry.filelike import wrap_with_handler
|
2015-08-03 19:49:10 +00:00
|
|
|
from util.registry.queuefile import QueueFile
|
|
|
|
from util.registry.queueprocess import QueueProcess
|
2016-01-06 17:01:15 +00:00
|
|
|
from util.registry.torrent import (make_torrent, per_user_torrent_filename, public_torrent_filename,
|
|
|
|
PieceHasher)
|
2016-01-08 00:07:23 +00:00
|
|
|
|
2014-09-16 04:18:57 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-10-10 20:23:42 +00:00
|
|
|
verbs = Blueprint('verbs', __name__)
|
2016-10-17 19:20:09 +00:00
|
|
|
license_validator.enforce_license_before_request(verbs)
|
2016-10-10 20:23:42 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
def _open_stream(formatter, namespace, repository, tag, derived_image_id, repo_image, handlers):
|
2016-08-31 19:18:01 +00:00
|
|
|
"""
|
|
|
|
This method generates a stream of data which will be replicated and read from the queue files.
|
|
|
|
This method runs in a separate process.
|
2016-01-15 16:32:29 +00:00
|
|
|
"""
|
2014-11-06 22:50:48 +00:00
|
|
|
# For performance reasons, we load the full image list here, cache it, then disconnect from
|
|
|
|
# the database.
|
|
|
|
with database.UseThenDisconnect(app.config):
|
2016-09-01 23:00:11 +00:00
|
|
|
image_list = list(model.get_manifest_layers_with_blobs(repo_image))
|
2015-11-17 23:25:43 +00:00
|
|
|
|
2014-09-19 16:22:54 +00:00
|
|
|
def get_next_image():
|
2014-11-06 22:50:48 +00:00
|
|
|
for current_image in image_list:
|
|
|
|
yield current_image
|
2014-09-19 16:22:54 +00:00
|
|
|
|
2014-09-17 02:43:19 +00:00
|
|
|
def get_next_layer():
|
2016-01-15 16:32:29 +00:00
|
|
|
# Re-Initialize the storage engine because some may not respond well to forking (e.g. S3)
|
|
|
|
store = Storage(app, metric_queue)
|
2016-09-01 23:00:11 +00:00
|
|
|
for current_image in image_list:
|
|
|
|
current_image_path = model.get_blob_path(current_image.blob)
|
|
|
|
current_image_stream = store.stream_read_file(current_image.blob.locations,
|
2014-09-17 02:43:19 +00:00
|
|
|
current_image_path)
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.debug('Returning image layer %s: %s', current_image.image_id, current_image_path)
|
2014-09-17 02:43:19 +00:00
|
|
|
yield current_image_stream
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
stream = formatter.build_stream(namespace, repository, tag, repo_image, derived_image_id,
|
|
|
|
get_next_image, get_next_layer)
|
2014-09-19 16:22:54 +00:00
|
|
|
|
2016-01-06 17:01:15 +00:00
|
|
|
for handler_fn in handlers:
|
|
|
|
stream = wrap_with_handler(stream, handler_fn)
|
|
|
|
|
2014-09-17 02:43:19 +00:00
|
|
|
return stream.read
|
|
|
|
|
2014-09-18 21:26:40 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
def _sign_derived_image(verb, derived_image, queue_file):
|
2016-01-15 16:32:29 +00:00
|
|
|
""" Read from the queue file and sign the contents which are generated. This method runs in a
|
|
|
|
separate process. """
|
2015-02-04 20:29:24 +00:00
|
|
|
signature = None
|
|
|
|
try:
|
|
|
|
signature = signer.detached_sign(queue_file)
|
|
|
|
except:
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.exception('Exception when signing %s deriving image %s', verb, derived_image.ref)
|
2015-02-04 20:29:24 +00:00
|
|
|
return
|
|
|
|
|
2015-02-05 20:00:19 +00:00
|
|
|
# Setup the database (since this is a new process) and then disconnect immediately
|
|
|
|
# once the operation completes.
|
|
|
|
if not queue_file.raised_exception:
|
|
|
|
with database.UseThenDisconnect(app.config):
|
2016-09-01 23:00:11 +00:00
|
|
|
model.set_derived_image_signature(derived_image, signer.name, signature)
|
2015-02-04 20:29:24 +00:00
|
|
|
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
def _write_derived_image_to_storage(verb, derived_image, queue_file):
|
2016-01-15 16:32:29 +00:00
|
|
|
""" Read from the generated stream and write it back to the storage engine. This method runs in a
|
|
|
|
separate process.
|
|
|
|
"""
|
2014-10-08 17:43:12 +00:00
|
|
|
def handle_exception(ex):
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.debug('Exception when building %s derived image %s: %s', verb, derived_image.ref, ex)
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2014-11-06 22:50:48 +00:00
|
|
|
with database.UseThenDisconnect(app.config):
|
2016-09-01 23:00:11 +00:00
|
|
|
model.delete_derived_image(derived_image)
|
2014-10-08 17:43:12 +00:00
|
|
|
|
|
|
|
queue_file.add_exception_handler(handle_exception)
|
|
|
|
|
2016-01-15 16:32:29 +00:00
|
|
|
# Re-Initialize the storage engine because some may not respond well to forking (e.g. S3)
|
|
|
|
store = Storage(app, metric_queue)
|
2016-09-01 23:00:11 +00:00
|
|
|
image_path = model.get_blob_path(derived_image.blob)
|
|
|
|
store.stream_write(derived_image.blob.locations, image_path, queue_file)
|
2014-09-17 02:43:19 +00:00
|
|
|
queue_file.close()
|
2014-09-16 04:18:57 +00:00
|
|
|
|
2014-09-18 21:26:40 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
def _torrent_for_blob(blob, is_public):
|
|
|
|
""" Returns a response containing the torrent file contents for the given blob. May abort
|
2016-01-20 21:33:10 +00:00
|
|
|
with an error if the state is not valid (e.g. non-public, non-user request).
|
|
|
|
"""
|
|
|
|
# Make sure the storage has a size.
|
2016-09-01 23:00:11 +00:00
|
|
|
if not blob.size:
|
2016-01-20 21:33:10 +00:00
|
|
|
abort(404)
|
|
|
|
|
|
|
|
# Lookup the torrent information for the storage.
|
2016-09-01 23:00:11 +00:00
|
|
|
torrent_info = model.get_torrent_info(blob)
|
|
|
|
if torrent_info is None:
|
2016-01-20 21:33:10 +00:00
|
|
|
abort(404)
|
|
|
|
|
|
|
|
# Lookup the webseed path for the storage.
|
2016-09-01 23:00:11 +00:00
|
|
|
path = model.get_blob_path(blob)
|
|
|
|
webseed = storage.get_direct_download_url(blob.locations, path,
|
2016-02-08 21:51:38 +00:00
|
|
|
expires_in=app.config['BITTORRENT_WEBSEED_LIFETIME'])
|
2016-01-20 21:33:10 +00:00
|
|
|
if webseed is None:
|
|
|
|
# We cannot support webseeds for storages that cannot provide direct downloads.
|
|
|
|
abort(make_response('Storage engine does not support seeding.', 501))
|
|
|
|
|
|
|
|
# Build the filename for the torrent.
|
|
|
|
if is_public:
|
2016-09-01 23:00:11 +00:00
|
|
|
name = public_torrent_filename(blob.uuid)
|
2016-01-20 21:33:10 +00:00
|
|
|
else:
|
|
|
|
user = get_authenticated_user()
|
|
|
|
if not user:
|
|
|
|
abort(403)
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
name = per_user_torrent_filename(user.uuid, blob.uuid)
|
2016-01-20 21:33:10 +00:00
|
|
|
|
|
|
|
# Return the torrent file.
|
2016-09-01 23:00:11 +00:00
|
|
|
torrent_file = make_torrent(name, webseed, blob.size, torrent_info.piece_length,
|
|
|
|
torrent_info.pieces)
|
2016-01-20 21:33:10 +00:00
|
|
|
|
|
|
|
headers = {'Content-Type': 'application/x-bittorrent',
|
|
|
|
'Content-Disposition': 'attachment; filename={0}.torrent'.format(name)}
|
|
|
|
|
|
|
|
return make_response(torrent_file, 200, headers)
|
|
|
|
|
|
|
|
|
|
|
|
def _torrent_repo_verb(repo_image, tag, verb, **kwargs):
|
|
|
|
""" Handles returning a torrent for the given verb on the given image and tag. """
|
|
|
|
if not features.BITTORRENT:
|
|
|
|
# Torrent feature is not enabled.
|
|
|
|
abort(406)
|
|
|
|
|
|
|
|
# Lookup an *existing* derived storage for the verb. If the verb's image storage doesn't exist,
|
2016-05-05 17:55:24 +00:00
|
|
|
# we cannot create it here, so we 406.
|
2016-09-01 23:00:11 +00:00
|
|
|
derived_image = model.lookup_derived_image(repo_image, verb, varying_metadata={'tag': tag})
|
|
|
|
if derived_image is None:
|
2016-01-20 21:33:10 +00:00
|
|
|
abort(406)
|
|
|
|
|
|
|
|
# Return the torrent.
|
2016-09-01 23:00:11 +00:00
|
|
|
public_repo = model.repository_is_public(repo_image.repository.namespace_name,
|
|
|
|
repo_image.repository.name)
|
|
|
|
torrent = _torrent_for_blob(derived_image.blob, public_repo)
|
2016-01-20 21:33:10 +00:00
|
|
|
|
|
|
|
# Log the action.
|
|
|
|
track_and_log('repo_verb', repo_image.repository, tag=tag, verb=verb, torrent=True, **kwargs)
|
|
|
|
return torrent
|
|
|
|
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
def _verify_repo_verb(_, namespace, repository, tag, verb, checker=None):
|
2014-09-16 04:18:57 +00:00
|
|
|
permission = ReadRepositoryPermission(namespace, repository)
|
2016-09-01 23:00:11 +00:00
|
|
|
if not permission.can() and not model.repository_is_public(namespace, repository):
|
2015-02-04 20:29:24 +00:00
|
|
|
abort(403)
|
|
|
|
|
|
|
|
# Lookup the requested tag.
|
2016-09-01 23:00:11 +00:00
|
|
|
tag_image = model.get_tag_image(namespace, repository, tag)
|
|
|
|
if tag_image is None:
|
2015-02-04 20:29:24 +00:00
|
|
|
abort(404)
|
|
|
|
|
|
|
|
# If there is a data checker, call it first.
|
|
|
|
if checker is not None:
|
2016-09-01 23:00:11 +00:00
|
|
|
if not checker(tag_image):
|
2015-02-04 20:29:24 +00:00
|
|
|
logger.debug('Check mismatch on %s/%s:%s, verb %s', namespace, repository, tag, verb)
|
2014-09-16 04:18:57 +00:00
|
|
|
abort(404)
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
return tag_image
|
2014-09-18 21:26:40 +00:00
|
|
|
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
def _repo_verb_signature(namespace, repository, tag, verb, checker=None, **kwargs):
|
|
|
|
# Verify that the image exists and that we have access to it.
|
2016-09-01 23:00:11 +00:00
|
|
|
repo_image = _verify_repo_verb(storage, namespace, repository, tag, verb, checker)
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
# derived_image the derived image storage for the verb.
|
|
|
|
derived_image = model.lookup_derived_image(repo_image, verb, varying_metadata={'tag': tag})
|
|
|
|
if derived_image is None or derived_image.blob.uploading:
|
2015-04-29 19:33:20 +00:00
|
|
|
return make_response('', 202)
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Check if we have a valid signer configured.
|
|
|
|
if not signer.name:
|
|
|
|
abort(404)
|
2014-10-29 19:42:44 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Lookup the signature for the verb.
|
2016-09-01 23:00:11 +00:00
|
|
|
signature_value = model.get_derived_image_signature(derived_image, signer.name)
|
|
|
|
if signature_value is None:
|
2015-02-04 20:29:24 +00:00
|
|
|
abort(404)
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Return the signature.
|
2016-09-01 23:00:11 +00:00
|
|
|
return make_response(signature_value)
|
2014-09-17 02:43:19 +00:00
|
|
|
|
2014-11-06 23:00:52 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
def _repo_verb(namespace, repository, tag, verb, formatter, sign=False, checker=None, **kwargs):
|
|
|
|
# Verify that the image exists and that we have access to it.
|
2016-09-01 23:00:11 +00:00
|
|
|
repo_image = _verify_repo_verb(storage, namespace, repository, tag, verb, checker)
|
2014-09-17 02:43:19 +00:00
|
|
|
|
2016-01-20 21:33:10 +00:00
|
|
|
# Check for torrent. If found, we return a torrent for the repo verb image (if the derived
|
|
|
|
# image already exists).
|
|
|
|
if request.accept_mimetypes.best == 'application/x-bittorrent':
|
2016-11-03 19:28:40 +00:00
|
|
|
metric_queue.repository_pull.Inc(labelvalues=[namespace, repository, verb + '+torrent', True])
|
2016-01-20 21:33:10 +00:00
|
|
|
return _torrent_repo_verb(repo_image, tag, verb, **kwargs)
|
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Log the action.
|
|
|
|
track_and_log('repo_verb', repo_image.repository, tag=tag, verb=verb, **kwargs)
|
2016-11-03 19:28:40 +00:00
|
|
|
metric_queue.repository_pull.Inc(labelvalues=[namespace, repository, verb, True])
|
2014-09-18 21:26:40 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
# Lookup/create the derived image for the verb and repo image.
|
|
|
|
derived_image = model.lookup_or_create_derived_image(repo_image, verb,
|
2016-06-06 19:38:29 +00:00
|
|
|
storage.preferred_locations[0],
|
|
|
|
varying_metadata={'tag': tag})
|
2016-09-01 23:00:11 +00:00
|
|
|
if not derived_image.blob.uploading:
|
|
|
|
logger.debug('Derived %s image %s exists in storage', verb, derived_image.ref)
|
|
|
|
derived_layer_path = model.get_blob_path(derived_image.blob)
|
2016-02-11 22:00:38 +00:00
|
|
|
is_head_request = request.method == 'HEAD'
|
2016-09-01 23:00:11 +00:00
|
|
|
download_url = storage.get_direct_download_url(derived_image.blob.locations, derived_layer_path,
|
2016-02-11 22:00:38 +00:00
|
|
|
head=is_head_request)
|
2015-11-24 17:44:07 +00:00
|
|
|
if download_url:
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.debug('Redirecting to download URL for derived %s image %s', verb, derived_image.ref)
|
2015-11-24 17:44:07 +00:00
|
|
|
return redirect(download_url)
|
2015-11-24 04:49:46 +00:00
|
|
|
|
2015-11-24 17:44:07 +00:00
|
|
|
# Close the database handle here for this process before we send the long download.
|
|
|
|
database.close_db_filter(None)
|
2014-10-21 21:40:57 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.debug('Sending cached derived %s image %s', verb, derived_image.ref)
|
|
|
|
return send_file(storage.stream_read_file(derived_image.blob.locations, derived_layer_path))
|
2014-09-17 02:43:19 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
logger.debug('Building and returning derived %s image %s', verb, derived_image.ref)
|
2014-09-16 04:18:57 +00:00
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
# Calculate a derived image ID.
|
|
|
|
derived_image_id = hashlib.sha256(repo_image.image_id + ':' + verb).hexdigest()
|
2015-02-04 20:29:24 +00:00
|
|
|
|
|
|
|
def _cleanup():
|
|
|
|
# Close any existing DB connection once the process has exited.
|
2014-11-06 22:50:48 +00:00
|
|
|
database.close_db_filter(None)
|
2014-11-05 17:27:38 +00:00
|
|
|
|
2016-01-22 20:52:28 +00:00
|
|
|
hasher = PieceHasher(app.config['BITTORRENT_PIECE_SIZE'])
|
2016-01-20 21:33:10 +00:00
|
|
|
|
2016-01-06 17:01:15 +00:00
|
|
|
def _store_metadata_and_cleanup():
|
|
|
|
with database.UseThenDisconnect(app.config):
|
2016-09-01 23:00:11 +00:00
|
|
|
model.set_torrent_info(derived_image.blob, app.config['BITTORRENT_PIECE_SIZE'],
|
|
|
|
hasher.final_piece_hashes())
|
|
|
|
model.set_blob_size(derived_image.blob, hasher.hashed_bytes)
|
2016-01-06 17:01:15 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Create a queue process to generate the data. The queue files will read from the process
|
|
|
|
# and send the results to the client and storage.
|
2016-01-06 17:01:15 +00:00
|
|
|
handlers = [hasher.update]
|
2016-09-01 23:00:11 +00:00
|
|
|
args = (formatter, namespace, repository, tag, derived_image_id, repo_image, handlers)
|
2015-02-04 20:29:24 +00:00
|
|
|
queue_process = QueueProcess(_open_stream,
|
2015-07-15 21:25:41 +00:00
|
|
|
8 * 1024, 10 * 1024 * 1024, # 8K/10M chunk/max
|
2016-01-06 17:01:15 +00:00
|
|
|
args, finished=_store_metadata_and_cleanup)
|
2014-09-16 04:18:57 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
client_queue_file = QueueFile(queue_process.create_queue(), 'client')
|
2015-11-24 17:44:07 +00:00
|
|
|
storage_queue_file = QueueFile(queue_process.create_queue(), 'storage')
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# If signing is required, add a QueueFile for signing the image as we stream it out.
|
2015-11-24 17:44:07 +00:00
|
|
|
signing_queue_file = None
|
|
|
|
if sign and signer.name:
|
|
|
|
signing_queue_file = QueueFile(queue_process.create_queue(), 'signing')
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
# Start building.
|
|
|
|
queue_process.run()
|
|
|
|
|
|
|
|
# Start the storage saving.
|
2016-09-01 23:00:11 +00:00
|
|
|
storage_args = (verb, derived_image, storage_queue_file)
|
|
|
|
QueueProcess.run_process(_write_derived_image_to_storage, storage_args, finished=_cleanup)
|
2015-02-04 20:29:24 +00:00
|
|
|
|
2015-11-24 17:44:07 +00:00
|
|
|
if sign and signer.name:
|
2016-09-01 23:00:11 +00:00
|
|
|
signing_args = (verb, derived_image, signing_queue_file)
|
|
|
|
QueueProcess.run_process(_sign_derived_image, signing_args, finished=_cleanup)
|
2015-02-04 20:29:24 +00:00
|
|
|
|
|
|
|
# Close the database handle here for this process before we send the long download.
|
|
|
|
database.close_db_filter(None)
|
|
|
|
|
|
|
|
# Return the client's data.
|
|
|
|
return send_file(client_queue_file)
|
|
|
|
|
|
|
|
|
|
|
|
def os_arch_checker(os, arch):
|
2016-09-01 23:00:11 +00:00
|
|
|
def checker(repo_image):
|
|
|
|
image_json = repo_image.compat_metadata
|
|
|
|
|
2015-01-13 22:46:11 +00:00
|
|
|
# Verify the architecture and os.
|
|
|
|
operating_system = image_json.get('os', 'linux')
|
|
|
|
if operating_system != os:
|
|
|
|
return False
|
|
|
|
|
|
|
|
architecture = image_json.get('architecture', 'amd64')
|
2015-02-06 17:22:27 +00:00
|
|
|
|
|
|
|
# Note: Some older Docker images have 'x86_64' rather than 'amd64'.
|
|
|
|
# We allow the conversion here.
|
|
|
|
if architecture == 'x86_64' and operating_system == 'linux':
|
|
|
|
architecture = 'amd64'
|
|
|
|
|
2015-01-13 22:46:11 +00:00
|
|
|
if architecture != arch:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
return checker
|
|
|
|
|
|
|
|
|
2016-02-16 20:31:23 +00:00
|
|
|
@route_show_if(features.ACI_CONVERSION)
|
2015-05-19 21:52:44 +00:00
|
|
|
@anon_protect
|
2015-02-04 20:29:24 +00:00
|
|
|
@verbs.route('/aci/<server>/<namespace>/<repository>/<tag>/sig/<os>/<arch>/', methods=['GET'])
|
2015-03-11 00:26:00 +00:00
|
|
|
@verbs.route('/aci/<server>/<namespace>/<repository>/<tag>/aci.asc/<os>/<arch>/', methods=['GET'])
|
2015-02-04 20:29:24 +00:00
|
|
|
@process_auth
|
|
|
|
def get_aci_signature(server, namespace, repository, tag, os, arch):
|
|
|
|
return _repo_verb_signature(namespace, repository, tag, 'aci', checker=os_arch_checker(os, arch),
|
|
|
|
os=os, arch=arch)
|
|
|
|
|
|
|
|
|
2016-02-16 20:31:23 +00:00
|
|
|
@route_show_if(features.ACI_CONVERSION)
|
2015-05-19 21:52:44 +00:00
|
|
|
@anon_protect
|
2016-02-11 22:00:38 +00:00
|
|
|
@verbs.route('/aci/<server>/<namespace>/<repository>/<tag>/aci/<os>/<arch>/', methods=['GET', 'HEAD'])
|
2015-02-04 20:29:24 +00:00
|
|
|
@process_auth
|
|
|
|
def get_aci_image(server, namespace, repository, tag, os, arch):
|
2016-08-02 22:45:30 +00:00
|
|
|
return _repo_verb(namespace, repository, tag, 'aci', AppCImageFormatter(),
|
2015-02-04 20:29:24 +00:00
|
|
|
sign=True, checker=os_arch_checker(os, arch), os=os, arch=arch)
|
2015-01-13 22:46:11 +00:00
|
|
|
|
|
|
|
|
2015-05-19 21:52:44 +00:00
|
|
|
@anon_protect
|
2015-01-13 22:46:11 +00:00
|
|
|
@verbs.route('/squash/<namespace>/<repository>/<tag>', methods=['GET'])
|
|
|
|
@process_auth
|
|
|
|
def get_squashed_tag(namespace, repository, tag):
|
2016-08-02 22:45:30 +00:00
|
|
|
return _repo_verb(namespace, repository, tag, 'squash', SquashedDockerImageFormatter())
|
2015-01-13 22:46:11 +00:00
|
|
|
|
2015-12-30 21:16:23 +00:00
|
|
|
|
2016-01-08 00:07:23 +00:00
|
|
|
@route_show_if(features.BITTORRENT)
|
2015-12-30 21:16:23 +00:00
|
|
|
@anon_protect
|
2015-12-31 19:10:36 +00:00
|
|
|
@verbs.route('/torrent{0}'.format(BLOB_DIGEST_ROUTE), methods=['GET'])
|
2015-12-30 21:16:23 +00:00
|
|
|
@process_auth
|
2016-03-09 21:20:28 +00:00
|
|
|
@parse_repository_name()
|
|
|
|
def get_tag_torrent(namespace_name, repo_name, digest):
|
|
|
|
permission = ReadRepositoryPermission(namespace_name, repo_name)
|
2016-09-01 23:00:11 +00:00
|
|
|
public_repo = model.repository_is_public(namespace_name, repo_name)
|
2015-12-31 19:27:38 +00:00
|
|
|
if not permission.can() and not public_repo:
|
2015-12-30 21:16:23 +00:00
|
|
|
abort(403)
|
|
|
|
|
2015-12-31 19:10:36 +00:00
|
|
|
user = get_authenticated_user()
|
2016-01-07 19:15:04 +00:00
|
|
|
if user is None and not public_repo:
|
2016-01-08 21:38:02 +00:00
|
|
|
# We can not generate a private torrent cluster without a user uuid (e.g. token auth)
|
2015-12-31 19:10:36 +00:00
|
|
|
abort(403)
|
|
|
|
|
2016-09-01 23:00:11 +00:00
|
|
|
blob = model.get_repo_blob_by_digest(namespace_name, repo_name, digest)
|
|
|
|
if blob is None:
|
2015-12-30 21:16:23 +00:00
|
|
|
abort(404)
|
|
|
|
|
2016-11-03 19:28:40 +00:00
|
|
|
metric_queue.repository_pull.Inc(labelvalues=[namespace_name, repo_name, 'torrent', True])
|
2016-09-01 23:00:11 +00:00
|
|
|
return _torrent_for_blob(blob, public_repo)
|