2013-09-20 15:55:44 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2013-10-29 20:11:54 +00:00
|
|
|
import urlparse
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-01-24 22:00:42 +00:00
|
|
|
from flask import request, make_response, jsonify, session, Blueprint
|
2013-09-20 15:55:44 +00:00
|
|
|
from functools import wraps
|
2014-02-21 03:26:10 +00:00
|
|
|
from collections import OrderedDict
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-03-18 23:21:27 +00:00
|
|
|
from data import model
|
2014-03-20 16:09:25 +00:00
|
|
|
from data.model import oauth
|
2014-10-29 19:42:44 +00:00
|
|
|
from app import app, authentication, userevents, storage
|
2014-02-25 20:07:24 +00:00
|
|
|
from auth.auth import process_auth
|
2014-03-26 20:19:04 +00:00
|
|
|
from auth.auth_context import get_authenticated_user, get_validated_token, get_validated_oauth_token
|
2013-11-11 21:28:05 +00:00
|
|
|
from util.names import parse_repository_name
|
2014-05-28 22:22:48 +00:00
|
|
|
from util.useremails import send_confirmation_email
|
2014-03-18 23:21:27 +00:00
|
|
|
from auth.permissions import (ModifyRepositoryPermission, UserAdminPermission,
|
|
|
|
ReadRepositoryPermission, CreateRepositoryPermission)
|
2014-01-28 23:29:45 +00:00
|
|
|
|
2014-01-24 20:01:40 +00:00
|
|
|
from util.http import abort
|
2014-10-30 16:49:51 +00:00
|
|
|
from endpoints.trackhelper import track_and_log
|
2014-07-18 20:34:52 +00:00
|
|
|
from endpoints.notificationhelper import spawn_notification
|
2014-01-24 20:01:40 +00:00
|
|
|
|
2014-10-02 18:49:18 +00:00
|
|
|
import features
|
2014-01-24 22:00:42 +00:00
|
|
|
|
2013-09-20 15:55:44 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2014-05-02 01:19:52 +00:00
|
|
|
profile = logging.getLogger('application.profiler')
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
index = Blueprint('index', __name__)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-10-16 18:24:10 +00:00
|
|
|
def generate_headers(role='read'):
|
|
|
|
def decorator_method(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapper(namespace, repository, *args, **kwargs):
|
|
|
|
response = f(namespace, repository, *args, **kwargs)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-12-09 04:24:29 +00:00
|
|
|
# Setting session namespace and repository
|
|
|
|
session['namespace'] = namespace
|
|
|
|
session['repository'] = repository
|
|
|
|
|
2014-02-16 22:38:47 +00:00
|
|
|
if get_authenticated_user():
|
|
|
|
session['username'] = get_authenticated_user().username
|
|
|
|
else:
|
|
|
|
session.pop('username', None)
|
|
|
|
|
2013-10-29 20:11:54 +00:00
|
|
|
# We run our index and registry on the same hosts for now
|
|
|
|
registry_server = urlparse.urlparse(request.url).netloc
|
|
|
|
response.headers['X-Docker-Endpoints'] = registry_server
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-10-16 18:24:10 +00:00
|
|
|
has_token_request = request.headers.get('X-Docker-Token', '')
|
2013-09-20 22:38:17 +00:00
|
|
|
|
2013-10-16 18:24:10 +00:00
|
|
|
if has_token_request:
|
|
|
|
repo = model.get_repository(namespace, repository)
|
2013-11-11 22:01:21 +00:00
|
|
|
if repo:
|
|
|
|
token = model.create_access_token(repo, role)
|
|
|
|
token_str = 'signature=%s' % token.code
|
|
|
|
response.headers['WWW-Authenticate'] = token_str
|
|
|
|
response.headers['X-Docker-Token'] = token_str
|
|
|
|
else:
|
|
|
|
logger.info('Token request in non-existing repo: %s/%s' %
|
|
|
|
(namespace, repository))
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-10-16 18:24:10 +00:00
|
|
|
return response
|
|
|
|
return wrapper
|
|
|
|
return decorator_method
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/users', methods=['POST'])
|
|
|
|
@index.route('/users/', methods=['POST'])
|
2013-09-20 15:55:44 +00:00
|
|
|
def create_user():
|
2014-10-02 18:49:18 +00:00
|
|
|
if not features.USER_CREATION:
|
|
|
|
abort(400, 'User creation is disabled. Please speak to your administrator.')
|
|
|
|
|
2013-09-20 15:55:44 +00:00
|
|
|
user_data = request.get_json()
|
2014-10-14 19:46:35 +00:00
|
|
|
if not user_data or not 'username' in user_data:
|
2014-09-15 15:27:33 +00:00
|
|
|
abort(400, 'Missing username')
|
|
|
|
|
2013-10-01 16:25:06 +00:00
|
|
|
username = user_data['username']
|
2014-07-15 01:24:38 +00:00
|
|
|
password = user_data.get('password', '')
|
2013-10-01 16:25:06 +00:00
|
|
|
|
2014-02-20 19:49:34 +00:00
|
|
|
# UGH! we have to use this response when the login actually worked, in order
|
|
|
|
# to get the CLI to try again with a get, and then tell us login succeeded.
|
|
|
|
success = make_response('"Username or email already exists"', 400)
|
|
|
|
|
2013-10-16 18:24:10 +00:00
|
|
|
if username == '$token':
|
|
|
|
try:
|
2013-11-11 21:28:05 +00:00
|
|
|
model.load_token_data(password)
|
2014-02-20 19:49:34 +00:00
|
|
|
return success
|
2013-10-16 18:24:10 +00:00
|
|
|
except model.InvalidTokenException:
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(400, 'Invalid access token.', issue='invalid-access-token')
|
2013-10-16 18:24:10 +00:00
|
|
|
|
2014-03-20 16:09:25 +00:00
|
|
|
elif username == '$oauthtoken':
|
|
|
|
validated = oauth.validate_access_token(password)
|
|
|
|
if validated is not None:
|
|
|
|
return success
|
|
|
|
else:
|
|
|
|
abort(400, 'Invalid oauth access token.', issue='invalid-oauth-access-token')
|
|
|
|
|
2013-11-21 00:43:19 +00:00
|
|
|
elif '+' in username:
|
|
|
|
try:
|
|
|
|
model.verify_robot(username, password)
|
2014-02-20 19:49:34 +00:00
|
|
|
return success
|
2013-11-21 00:43:19 +00:00
|
|
|
except model.InvalidRobotException:
|
2014-02-20 19:49:34 +00:00
|
|
|
abort(400, 'Invalid robot account or password.',
|
|
|
|
issue='robot-login-failure')
|
2013-11-21 00:43:19 +00:00
|
|
|
|
2014-05-13 19:22:31 +00:00
|
|
|
if authentication.user_exists(username):
|
2014-05-13 16:17:26 +00:00
|
|
|
verified = authentication.verify_user(username, password)
|
2013-10-01 16:25:06 +00:00
|
|
|
if verified:
|
2014-02-07 01:58:26 +00:00
|
|
|
# Mark that the user was logged in.
|
2014-05-30 18:25:29 +00:00
|
|
|
event = userevents.get_event(username)
|
2014-02-07 01:58:26 +00:00
|
|
|
event.publish_event_data('docker-cli', {'action': 'login'})
|
|
|
|
|
2014-02-20 19:49:34 +00:00
|
|
|
return success
|
2013-10-01 16:25:06 +00:00
|
|
|
else:
|
2014-02-07 01:58:26 +00:00
|
|
|
# Mark that the login failed.
|
2014-05-30 18:25:29 +00:00
|
|
|
event = userevents.get_event(username)
|
2014-02-07 01:58:26 +00:00
|
|
|
event.publish_event_data('docker-cli', {'action': 'loginfailure'})
|
|
|
|
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(400, 'Invalid password.', issue='login-failure')
|
|
|
|
|
2013-10-01 16:25:06 +00:00
|
|
|
else:
|
|
|
|
# New user case
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Creating user')
|
2014-05-28 19:22:36 +00:00
|
|
|
new_user = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
new_user = model.create_user(username, password, user_data['email'])
|
|
|
|
except model.TooManyUsersException as ex:
|
|
|
|
abort(402, 'Seat limit has been reached for this license', issue='seat-limit')
|
2014-05-02 01:19:52 +00:00
|
|
|
|
|
|
|
profile.debug('Creating email code for user')
|
2013-10-01 16:25:06 +00:00
|
|
|
code = model.create_confirm_email_code(new_user)
|
2014-05-02 01:19:52 +00:00
|
|
|
|
|
|
|
profile.debug('Sending email code to user')
|
2013-10-01 16:25:06 +00:00
|
|
|
send_confirmation_email(new_user.username, new_user.email, code.code)
|
2014-05-02 01:19:52 +00:00
|
|
|
|
2013-10-01 16:25:06 +00:00
|
|
|
return make_response('Created', 201)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/users', methods=['GET'])
|
|
|
|
@index.route('/users/', methods=['GET'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
def get_user():
|
2014-03-26 20:19:04 +00:00
|
|
|
if get_validated_oauth_token():
|
|
|
|
return jsonify({
|
|
|
|
'username': '$oauthtoken',
|
|
|
|
'email': None,
|
|
|
|
})
|
2014-11-24 21:07:38 +00:00
|
|
|
elif get_authenticated_user():
|
2013-11-07 22:09:47 +00:00
|
|
|
return jsonify({
|
|
|
|
'username': get_authenticated_user().username,
|
|
|
|
'email': get_authenticated_user().email,
|
|
|
|
})
|
2014-02-21 21:07:08 +00:00
|
|
|
elif get_validated_token():
|
|
|
|
return jsonify({
|
|
|
|
'username': '$token',
|
|
|
|
'email': None,
|
|
|
|
})
|
2013-11-07 22:09:47 +00:00
|
|
|
abort(404)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/users/<username>/', methods=['PUT'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
def update_user(username):
|
2014-03-18 23:21:27 +00:00
|
|
|
permission = UserAdminPermission(username)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
if permission.can():
|
|
|
|
update_request = request.get_json()
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
if 'password' in update_request:
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Updating user password')
|
2013-09-20 22:38:17 +00:00
|
|
|
model.change_password(get_authenticated_user(),
|
|
|
|
update_request['password'])
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
if 'email' in update_request:
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Updating user email')
|
2013-09-20 22:38:17 +00:00
|
|
|
model.update_email(get_authenticated_user(), update_request['email'])
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
return jsonify({
|
|
|
|
'username': get_authenticated_user().username,
|
|
|
|
'email': get_authenticated_user().email,
|
|
|
|
})
|
|
|
|
|
|
|
|
abort(403)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/repositories/<path:repository>', methods=['PUT'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
@parse_repository_name
|
2013-10-16 18:24:10 +00:00
|
|
|
@generate_headers(role='write')
|
2013-09-20 15:55:44 +00:00
|
|
|
def create_repository(namespace, repository):
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Parsing image descriptions')
|
2014-06-11 19:37:45 +00:00
|
|
|
image_descriptions = json.loads(request.data.decode('utf8'))
|
2014-05-02 01:19:52 +00:00
|
|
|
|
|
|
|
profile.debug('Looking up repository')
|
2013-09-20 22:38:17 +00:00
|
|
|
repo = model.get_repository(namespace, repository)
|
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Repository looked up')
|
2013-10-16 18:24:10 +00:00
|
|
|
if not repo and get_authenticated_user() is None:
|
2013-12-20 21:21:07 +00:00
|
|
|
logger.debug('Attempt to create new repository without user auth.')
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(401,
|
|
|
|
message='Cannot create a repository as a guest. Please login via "docker login" first.',
|
|
|
|
issue='no-login')
|
2013-10-16 18:24:10 +00:00
|
|
|
|
|
|
|
elif repo:
|
2013-09-20 22:38:17 +00:00
|
|
|
permission = ModifyRepositoryPermission(namespace, repository)
|
|
|
|
if not permission.can():
|
2014-11-24 21:07:38 +00:00
|
|
|
abort(403,
|
2014-01-28 23:29:45 +00:00
|
|
|
message='You do not have permission to modify repository %(namespace)s/%(repository)s',
|
|
|
|
issue='no-repo-write-permission',
|
|
|
|
namespace=namespace, repository=repository)
|
2013-09-20 22:47:47 +00:00
|
|
|
|
2013-09-26 19:58:11 +00:00
|
|
|
else:
|
2013-11-11 21:31:29 +00:00
|
|
|
permission = CreateRepositoryPermission(namespace)
|
2013-11-04 20:42:08 +00:00
|
|
|
if not permission.can():
|
|
|
|
logger.info('Attempt to create a new repo with insufficient perms.')
|
2014-11-24 21:07:38 +00:00
|
|
|
abort(403,
|
2014-01-28 23:29:45 +00:00
|
|
|
message='You do not have permission to create repositories in namespace "%(namespace)s"',
|
|
|
|
issue='no-create-permission',
|
|
|
|
namespace=namespace)
|
2013-09-20 22:38:17 +00:00
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Creaing repository with owner: %s', get_authenticated_user().username)
|
2013-09-20 22:38:17 +00:00
|
|
|
repo = model.create_repository(namespace, repository,
|
|
|
|
get_authenticated_user())
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-11-06 19:48:16 +00:00
|
|
|
profile.debug('Determining already added images')
|
|
|
|
added_images = OrderedDict([(desc['id'], desc) for desc in image_descriptions])
|
2014-02-21 03:26:10 +00:00
|
|
|
new_repo_images = dict(added_images)
|
2014-02-21 13:00:47 +00:00
|
|
|
|
2014-11-06 19:48:16 +00:00
|
|
|
# Optimization: Lookup any existing images in the repository with matching docker IDs and
|
|
|
|
# remove them from the added dict, so we don't need to look them up one-by-one.
|
|
|
|
def chunks(l, n):
|
|
|
|
for i in xrange(0, len(l), n):
|
|
|
|
yield l[i:i+n]
|
|
|
|
|
|
|
|
# Note: We do this in chunks in an effort to not hit the SQL query size limit.
|
|
|
|
for chunk in chunks(new_repo_images.keys(), 50):
|
|
|
|
existing_images = model.lookup_repository_images(namespace, repository, chunk)
|
|
|
|
for existing in existing_images:
|
2013-10-01 18:14:39 +00:00
|
|
|
added_images.pop(existing.docker_image_id)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Creating/Linking necessary images')
|
2014-02-16 22:38:47 +00:00
|
|
|
username = get_authenticated_user() and get_authenticated_user().username
|
2014-02-21 03:26:10 +00:00
|
|
|
translations = {}
|
2013-09-20 15:55:44 +00:00
|
|
|
for image_description in added_images.values():
|
2014-02-25 21:31:52 +00:00
|
|
|
model.find_create_or_link_image(image_description['id'], repo, username,
|
2014-06-17 20:03:43 +00:00
|
|
|
translations, storage.preferred_locations[0])
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
|
|
|
|
profile.debug('Created images')
|
2014-10-29 19:42:44 +00:00
|
|
|
track_and_log('push_repo', repo)
|
2014-11-06 19:48:16 +00:00
|
|
|
return make_response('Created', 201)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/repositories/<path:repository>/images', methods=['PUT'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
@parse_repository_name
|
2013-10-16 18:24:10 +00:00
|
|
|
@generate_headers(role='write')
|
2013-09-20 15:55:44 +00:00
|
|
|
def update_images(namespace, repository):
|
2013-09-20 22:38:17 +00:00
|
|
|
permission = ModifyRepositoryPermission(namespace, repository)
|
|
|
|
|
|
|
|
if permission.can():
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Looking up repository')
|
2013-11-16 20:05:26 +00:00
|
|
|
repo = model.get_repository(namespace, repository)
|
|
|
|
if not repo:
|
2013-11-11 23:05:21 +00:00
|
|
|
# Make sure the repo actually exists.
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(404, message='Unknown repository', issue='unknown-repo')
|
2013-11-11 23:05:21 +00:00
|
|
|
|
2014-02-07 01:58:26 +00:00
|
|
|
if get_authenticated_user():
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Publishing push event')
|
2014-02-07 01:58:26 +00:00
|
|
|
username = get_authenticated_user().username
|
|
|
|
|
|
|
|
# Mark that the user has pushed the repo.
|
|
|
|
user_data = {
|
|
|
|
'action': 'pushed_repo',
|
|
|
|
'repository': repository,
|
|
|
|
'namespace': namespace
|
2014-07-18 19:58:18 +00:00
|
|
|
}
|
2014-02-07 01:58:26 +00:00
|
|
|
|
2014-05-30 18:25:29 +00:00
|
|
|
event = userevents.get_event(username)
|
2014-02-07 01:58:26 +00:00
|
|
|
event.publish_event_data('docker-cli', user_data)
|
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('GCing repository')
|
2014-02-06 19:13:35 +00:00
|
|
|
num_removed = model.garbage_collect_repository(namespace, repository)
|
|
|
|
|
2014-07-18 02:51:58 +00:00
|
|
|
# Generate a job for each notification that has been added to this repo
|
|
|
|
profile.debug('Adding notifications for repository')
|
|
|
|
|
2014-10-22 18:14:56 +00:00
|
|
|
updated_tags = session.get('pushed_tags', {})
|
2014-07-18 02:51:58 +00:00
|
|
|
event_data = {
|
|
|
|
'updated_tags': updated_tags,
|
|
|
|
'pruned_image_count': num_removed
|
|
|
|
}
|
2014-07-18 19:58:18 +00:00
|
|
|
spawn_notification(repo, 'repo_push', event_data)
|
2013-09-20 22:38:17 +00:00
|
|
|
return make_response('Updated', 204)
|
|
|
|
|
|
|
|
abort(403)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/repositories/<path:repository>/images', methods=['GET'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
@parse_repository_name
|
2013-10-16 18:24:10 +00:00
|
|
|
@generate_headers(role='read')
|
2013-09-20 15:55:44 +00:00
|
|
|
def get_repository_images(namespace, repository):
|
2013-09-20 22:38:17 +00:00
|
|
|
permission = ReadRepositoryPermission(namespace, repository)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
# TODO invalidate token?
|
2014-12-18 16:08:50 +00:00
|
|
|
if permission.can() or model.repository_is_public(namespace, repository):
|
2013-11-11 23:05:21 +00:00
|
|
|
# We can't rely on permissions to tell us if a repo exists anymore
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Looking up repository')
|
2013-11-11 23:05:21 +00:00
|
|
|
repo = model.get_repository(namespace, repository)
|
|
|
|
if not repo:
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(404, message='Unknown repository', issue='unknown-repo')
|
2013-11-11 23:05:21 +00:00
|
|
|
|
2013-09-20 22:38:17 +00:00
|
|
|
all_images = []
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Retrieving repository images')
|
2013-09-20 22:38:17 +00:00
|
|
|
for image in model.get_repository_images(namespace, repository):
|
|
|
|
new_image_view = {
|
2013-10-01 18:14:39 +00:00
|
|
|
'id': image.docker_image_id,
|
2014-06-11 19:37:45 +00:00
|
|
|
'checksum': image.storage.checksum,
|
2013-09-20 22:38:17 +00:00
|
|
|
}
|
|
|
|
all_images.append(new_image_view)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-05-02 01:19:52 +00:00
|
|
|
profile.debug('Building repository image response')
|
2013-09-20 22:38:17 +00:00
|
|
|
resp = make_response(json.dumps(all_images), 200)
|
|
|
|
resp.mimetype = 'application/json'
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2014-10-29 19:42:44 +00:00
|
|
|
track_and_log('pull_repo', repo)
|
2013-09-20 22:38:17 +00:00
|
|
|
return resp
|
2013-09-20 15:55:44 +00:00
|
|
|
|
2013-11-11 23:05:21 +00:00
|
|
|
abort(403)
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/repositories/<path:repository>/images', methods=['DELETE'])
|
2013-09-20 22:38:17 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
@parse_repository_name
|
2013-10-16 18:24:10 +00:00
|
|
|
@generate_headers(role='write')
|
2013-09-20 15:55:44 +00:00
|
|
|
def delete_repository_images(namespace, repository):
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(501, 'Not Implemented', issue='not-implemented')
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/repositories/<path:repository>/auth', methods=['PUT'])
|
2013-09-20 15:55:44 +00:00
|
|
|
@parse_repository_name
|
|
|
|
def put_repository_auth(namespace, repository):
|
2014-01-28 23:29:45 +00:00
|
|
|
abort(501, 'Not Implemented', issue='not-implemented')
|
2013-09-20 15:55:44 +00:00
|
|
|
|
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/search', methods=['GET'])
|
2014-08-22 23:41:22 +00:00
|
|
|
@process_auth
|
2013-09-20 15:55:44 +00:00
|
|
|
def get_search():
|
2014-08-22 23:41:22 +00:00
|
|
|
def result_view(repo):
|
|
|
|
return {
|
2014-09-24 22:01:35 +00:00
|
|
|
"name": repo.namespace_user.username + '/' + repo.name,
|
2014-08-22 23:41:22 +00:00
|
|
|
"description": repo.description
|
|
|
|
}
|
|
|
|
|
|
|
|
query = request.args.get('q')
|
|
|
|
|
|
|
|
username = None
|
|
|
|
user = get_authenticated_user()
|
|
|
|
if user is not None:
|
|
|
|
username = user.username
|
|
|
|
|
2014-08-25 18:23:21 +00:00
|
|
|
if query:
|
|
|
|
matching = model.get_matching_repositories(query, username)
|
|
|
|
else:
|
|
|
|
matching = []
|
|
|
|
|
2014-08-22 23:41:22 +00:00
|
|
|
results = [result_view(repo) for repo in matching
|
2014-11-24 21:07:38 +00:00
|
|
|
if (repo.visibility.name == 'public' or
|
2014-09-24 22:01:35 +00:00
|
|
|
ReadRepositoryPermission(repo.namespace_user.username, repo.name).can())]
|
2014-08-22 23:41:22 +00:00
|
|
|
|
|
|
|
data = {
|
|
|
|
"query": query,
|
|
|
|
"num_results": len(results),
|
|
|
|
"results" : results
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = make_response(json.dumps(data), 200)
|
|
|
|
resp.mimetype = 'application/json'
|
|
|
|
return resp
|
2013-09-25 16:45:12 +00:00
|
|
|
|
2015-01-15 04:39:58 +00:00
|
|
|
# Note: This is *not* part of the Docker index spec. This is here for our own health check,
|
|
|
|
# since we have nginx handle the _ping below.
|
|
|
|
@index.route('/_internal_ping')
|
|
|
|
def internal_ping():
|
|
|
|
return make_response('true', 200)
|
2013-09-25 16:45:12 +00:00
|
|
|
|
2013-12-30 22:05:27 +00:00
|
|
|
@index.route('/_ping')
|
|
|
|
@index.route('/_ping')
|
2013-09-25 16:45:12 +00:00
|
|
|
def ping():
|
2014-10-06 14:24:40 +00:00
|
|
|
# NOTE: any changes made here must also be reflected in the nginx config
|
2013-09-25 16:45:12 +00:00
|
|
|
response = make_response('true', 200)
|
|
|
|
response.headers['X-Docker-Registry-Version'] = '0.6.0'
|
2014-05-02 18:52:03 +00:00
|
|
|
response.headers['X-Docker-Registry-Standalone'] = '0'
|
2013-09-25 16:45:12 +00:00
|
|
|
return response
|