PEP8 fixes.
This commit is contained in:
parent
427b745f2f
commit
6a038bb24e
7 changed files with 56 additions and 45 deletions
|
@ -41,7 +41,7 @@ def create_confirm_email_code(user):
|
||||||
|
|
||||||
def confirm_user_email(code):
|
def confirm_user_email(code):
|
||||||
code = EmailConfirmation.get(EmailConfirmation.code == code,
|
code = EmailConfirmation.get(EmailConfirmation.code == code,
|
||||||
EmailConfirmation.email_confirm == True)
|
EmailConfirmation.email_confirm is True)
|
||||||
|
|
||||||
user = code.user
|
user = code.user
|
||||||
user.verified = True
|
user.verified = True
|
||||||
|
@ -96,14 +96,15 @@ def get_token(code):
|
||||||
return AccessToken.get(AccessToken.code == code)
|
return AccessToken.get(AccessToken.code == code)
|
||||||
|
|
||||||
|
|
||||||
def get_visible_repositories(username=None, include_public=True, limit=None, sort=False):
|
def get_visible_repositories(username=None, include_public=True, limit=None,
|
||||||
|
sort=False):
|
||||||
if not username and not include_public:
|
if not username and not include_public:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
query = Repository.select().distinct().join(Visibility)
|
query = Repository.select().distinct().join(Visibility)
|
||||||
or_clauses = []
|
or_clauses = []
|
||||||
if include_public:
|
if include_public:
|
||||||
or_clauses.append((Visibility.name == 'public'));
|
or_clauses.append((Visibility.name == 'public'))
|
||||||
|
|
||||||
if username:
|
if username:
|
||||||
with_perms = query.switch(Repository).join(RepositoryPermission,
|
with_perms = query.switch(Repository).join(RepositoryPermission,
|
||||||
|
@ -123,6 +124,7 @@ def get_visible_repositories(username=None, include_public=True, limit=None, sor
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
def get_matching_repositories(repo_term, username=None):
|
def get_matching_repositories(repo_term, username=None):
|
||||||
namespace_term = repo_term
|
namespace_term = repo_term
|
||||||
name_term = repo_term
|
name_term = repo_term
|
||||||
|
@ -197,7 +199,7 @@ def set_repository_visibility(repo, visibility):
|
||||||
|
|
||||||
repo.visibility = visibility_obj
|
repo.visibility = visibility_obj
|
||||||
repo.save()
|
repo.save()
|
||||||
|
|
||||||
|
|
||||||
def create_repository(namespace, name, owner):
|
def create_repository(namespace, name, owner):
|
||||||
private = Visibility.get(name='private')
|
private = Visibility.get(name='private')
|
||||||
|
|
|
@ -102,6 +102,7 @@ def create_repo_api():
|
||||||
@app.route('/api/find/repository', methods=['GET'])
|
@app.route('/api/find/repository', methods=['GET'])
|
||||||
def match_repos_api():
|
def match_repos_api():
|
||||||
prefix = request.args.get('query', '')
|
prefix = request.args.get('query', '')
|
||||||
|
|
||||||
def repo_view(repo):
|
def repo_view(repo):
|
||||||
return {
|
return {
|
||||||
'namespace': repo.namespace,
|
'namespace': repo.namespace,
|
||||||
|
@ -109,7 +110,10 @@ def match_repos_api():
|
||||||
'description': repo.description
|
'description': repo.description
|
||||||
}
|
}
|
||||||
|
|
||||||
username = current_user.db_user.username if current_user.is_authenticated() else None
|
username = None
|
||||||
|
if current_user.is_authenticated():
|
||||||
|
username = current_user.db_user.username
|
||||||
|
|
||||||
matching = model.get_matching_repositories(prefix, username)
|
matching = model.get_matching_repositories(prefix, username)
|
||||||
response = {
|
response = {
|
||||||
'repositories': [repo_view(repo) for repo in matching]
|
'repositories': [repo_view(repo) for repo in matching]
|
||||||
|
@ -126,7 +130,7 @@ def list_repos_api():
|
||||||
'name': repo_obj.name,
|
'name': repo_obj.name,
|
||||||
'description': repo_obj.description,
|
'description': repo_obj.description,
|
||||||
}
|
}
|
||||||
|
|
||||||
limit = request.args.get('limit', None)
|
limit = request.args.get('limit', None)
|
||||||
include_public = request.args.get('public', 'true')
|
include_public = request.args.get('public', 'true')
|
||||||
include_private = request.args.get('private', 'true')
|
include_private = request.args.get('private', 'true')
|
||||||
|
@ -141,10 +145,14 @@ def list_repos_api():
|
||||||
include_private = include_private == 'true'
|
include_private = include_private == 'true'
|
||||||
sort = sort == 'true'
|
sort = sort == 'true'
|
||||||
|
|
||||||
username = current_user.db_user.username if current_user.is_authenticated() and include_private else None
|
username = None
|
||||||
repos = [repo_view(repo)
|
if current_user.is_authenticated() and include_private:
|
||||||
for repo in model.get_visible_repositories(
|
username = current_user.db_user.username
|
||||||
username, limit = limit, include_public = include_public, sort = sort)]
|
|
||||||
|
repo_query = model.get_visible_repositories(username, limit=limit,
|
||||||
|
include_public=include_public,
|
||||||
|
sort=sort)
|
||||||
|
repos = [repo_view(repo) for repo in repo_query]
|
||||||
response = {
|
response = {
|
||||||
'repositories': repos
|
'repositories': repos
|
||||||
}
|
}
|
||||||
|
@ -170,7 +178,8 @@ def update_repo_api(namespace, repository):
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/repository/<path:repository>/changevisibility', methods=['POST'])
|
@app.route('/api/repository/<path:repository>/changevisibility',
|
||||||
|
methods=['POST'])
|
||||||
@api_login_required
|
@api_login_required
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def change_repo_visibility_api(namespace, repository):
|
def change_repo_visibility_api(namespace, repository):
|
||||||
|
@ -348,7 +357,7 @@ def delete_permissions(namespace, repository, username):
|
||||||
abort(403) # Permission denied
|
abort(403) # Permission denied
|
||||||
|
|
||||||
|
|
||||||
def subscription_view(stripe_subscription, used_repos):
|
def subscription_view(stripe_subscription, used_repos):
|
||||||
return {
|
return {
|
||||||
'currentPeriodStart': stripe_subscription.current_period_start,
|
'currentPeriodStart': stripe_subscription.current_period_start,
|
||||||
'currentPeriodEnd': stripe_subscription.current_period_end,
|
'currentPeriodEnd': stripe_subscription.current_period_end,
|
||||||
|
@ -375,7 +384,7 @@ def subscribe():
|
||||||
cus = stripe.Customer.create(email=user.email, plan=plan, card=card)
|
cus = stripe.Customer.create(email=user.email, plan=plan, card=card)
|
||||||
user.stripe_id = cus.id
|
user.stripe_id = cus.id
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
resp = jsonify(subscription_view(cus.subscription, private_repos))
|
resp = jsonify(subscription_view(cus.subscription, private_repos))
|
||||||
resp.status_code = 201
|
resp.status_code = 201
|
||||||
return resp
|
return resp
|
||||||
|
@ -422,4 +431,4 @@ def get_subscription():
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'plan': 'free',
|
'plan': 'free',
|
||||||
'usedPrivateRepos': private_repos,
|
'usedPrivateRepos': private_repos,
|
||||||
});
|
})
|
||||||
|
|
|
@ -151,7 +151,7 @@ def update_images(namespace, repository):
|
||||||
|
|
||||||
for image in image_with_checksums:
|
for image in image_with_checksums:
|
||||||
logger.debug('Setting checksum for image id: %s to %s' %
|
logger.debug('Setting checksum for image id: %s to %s' %
|
||||||
(image['id'], image['checksum']))
|
(image['id'], image['checksum']))
|
||||||
model.set_image_checksum(image['id'], repository, image['checksum'])
|
model.set_image_checksum(image['id'], repository, image['checksum'])
|
||||||
|
|
||||||
return make_response('Updated', 204)
|
return make_response('Updated', 204)
|
||||||
|
|
|
@ -44,7 +44,7 @@ def require_completion(f):
|
||||||
def wrapper(namespace, repository, *args, **kwargs):
|
def wrapper(namespace, repository, *args, **kwargs):
|
||||||
if store.exists(store.image_mark_path(namespace, repository,
|
if store.exists(store.image_mark_path(namespace, repository,
|
||||||
kwargs['image_id'])):
|
kwargs['image_id'])):
|
||||||
abort(400) #'Image is being uploaded, retry later')
|
abort(400) # 'Image is being uploaded, retry later')
|
||||||
return f(namespace, repository, *args, **kwargs)
|
return f(namespace, repository, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ def get_image_layer(namespace, repository, image_id, headers):
|
||||||
return Response(store.stream_read(store.image_layer_path(
|
return Response(store.stream_read(store.image_layer_path(
|
||||||
namespace, repository, image_id)), headers=headers)
|
namespace, repository, image_id)), headers=headers)
|
||||||
except IOError:
|
except IOError:
|
||||||
abort(404) #'Image not found', 404)
|
abort(404) # 'Image not found', 404)
|
||||||
|
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
@ -102,11 +102,11 @@ def put_image_layer(namespace, repository, image_id):
|
||||||
json_data = store.get_content(store.image_json_path(namespace, repository,
|
json_data = store.get_content(store.image_json_path(namespace, repository,
|
||||||
image_id))
|
image_id))
|
||||||
except IOError:
|
except IOError:
|
||||||
abort(404) #'Image not found', 404)
|
abort(404) # 'Image not found', 404)
|
||||||
layer_path = store.image_layer_path(namespace, repository, image_id)
|
layer_path = store.image_layer_path(namespace, repository, image_id)
|
||||||
mark_path = store.image_mark_path(namespace, repository, image_id)
|
mark_path = store.image_mark_path(namespace, repository, image_id)
|
||||||
if store.exists(layer_path) and not store.exists(mark_path):
|
if store.exists(layer_path) and not store.exists(mark_path):
|
||||||
abort(409) #'Image already exists', 409)
|
abort(409) # 'Image already exists', 409)
|
||||||
input_stream = request.stream
|
input_stream = request.stream
|
||||||
if request.headers.get('transfer-encoding') == 'chunked':
|
if request.headers.get('transfer-encoding') == 'chunked':
|
||||||
# Careful, might work only with WSGI servers supporting chunked
|
# Careful, might work only with WSGI servers supporting chunked
|
||||||
|
@ -127,7 +127,7 @@ def put_image_layer(namespace, repository, image_id):
|
||||||
tmp.close()
|
tmp.close()
|
||||||
except (IOError, checksums.TarError) as e:
|
except (IOError, checksums.TarError) as e:
|
||||||
logger.debug('put_image_layer: Error when computing tarsum '
|
logger.debug('put_image_layer: Error when computing tarsum '
|
||||||
'{0}'.format(e))
|
'{0}'.format(e))
|
||||||
try:
|
try:
|
||||||
checksum = store.get_content(store.image_checksum_path(namespace,
|
checksum = store.get_content(store.image_checksum_path(namespace,
|
||||||
repository,
|
repository,
|
||||||
|
@ -140,7 +140,7 @@ def put_image_layer(namespace, repository, image_id):
|
||||||
# We check if the checksums provided matches one the one we computed
|
# We check if the checksums provided matches one the one we computed
|
||||||
if checksum not in csums:
|
if checksum not in csums:
|
||||||
logger.debug('put_image_layer: Wrong checksum')
|
logger.debug('put_image_layer: Wrong checksum')
|
||||||
abort(400) #'Checksum mismatch, ignoring the layer')
|
abort(400) # 'Checksum mismatch, ignoring the layer')
|
||||||
# Checksum is ok, we remove the marker
|
# Checksum is ok, we remove the marker
|
||||||
store.remove(mark_path)
|
store.remove(mark_path)
|
||||||
return make_response('true', 200)
|
return make_response('true', 200)
|
||||||
|
@ -156,14 +156,14 @@ def put_image_checksum(namespace, repository, image_id):
|
||||||
|
|
||||||
checksum = request.headers.get('X-Docker-Checksum')
|
checksum = request.headers.get('X-Docker-Checksum')
|
||||||
if not checksum:
|
if not checksum:
|
||||||
abort(400) #'Missing Image\'s checksum')
|
abort(400) # 'Missing Image\'s checksum')
|
||||||
if not session.get('checksum'):
|
if not session.get('checksum'):
|
||||||
abort(400) #'Checksum not found in Cookie')
|
abort(400) # 'Checksum not found in Cookie')
|
||||||
if not store.exists(store.image_json_path(namespace, repository, image_id)):
|
if not store.exists(store.image_json_path(namespace, repository, image_id)):
|
||||||
abort(404) #'Image not found', 404)
|
abort(404) # 'Image not found', 404)
|
||||||
mark_path = store.image_mark_path(namespace, repository, image_id)
|
mark_path = store.image_mark_path(namespace, repository, image_id)
|
||||||
if not store.exists(mark_path):
|
if not store.exists(mark_path):
|
||||||
abort(409) #'Cannot set this image checksum', 409)
|
abort(409) # 'Cannot set this image checksum', 409)
|
||||||
err = store_checksum(namespace, repository, image_id, checksum)
|
err = store_checksum(namespace, repository, image_id, checksum)
|
||||||
if err:
|
if err:
|
||||||
abort(err)
|
abort(err)
|
||||||
|
@ -171,7 +171,7 @@ def put_image_checksum(namespace, repository, image_id):
|
||||||
logger.debug('session checksums: %s' % session.get('checksum', []))
|
logger.debug('session checksums: %s' % session.get('checksum', []))
|
||||||
logger.debug('client supplied checksum: %s' % checksum)
|
logger.debug('client supplied checksum: %s' % checksum)
|
||||||
logger.debug('put_image_layer: Wrong checksum')
|
logger.debug('put_image_layer: Wrong checksum')
|
||||||
abort(400) #'Checksum mismatch')
|
abort(400) # 'Checksum mismatch')
|
||||||
# Checksum is ok, we remove the marker
|
# Checksum is ok, we remove the marker
|
||||||
store.remove(mark_path)
|
store.remove(mark_path)
|
||||||
return make_response('true', 200)
|
return make_response('true', 200)
|
||||||
|
@ -184,15 +184,15 @@ def put_image_checksum(namespace, repository, image_id):
|
||||||
@set_cache_headers
|
@set_cache_headers
|
||||||
def get_image_json(namespace, repository, image_id, headers):
|
def get_image_json(namespace, repository, image_id, headers):
|
||||||
permission = ReadRepositoryPermission(namespace, repository)
|
permission = ReadRepositoryPermission(namespace, repository)
|
||||||
if (not permission.can() and not
|
if not permission.can() and not model.repository_is_public(namespace,
|
||||||
model.repository_is_public(namespace, repository)):
|
repository):
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = store.get_content(store.image_json_path(namespace, repository,
|
data = store.get_content(store.image_json_path(namespace, repository,
|
||||||
image_id))
|
image_id))
|
||||||
except IOError:
|
except IOError:
|
||||||
abort(404) #'Image not found', 404)
|
abort(404) # 'Image not found', 404)
|
||||||
try:
|
try:
|
||||||
size = store.get_size(store.image_layer_path(namespace, repository,
|
size = store.get_size(store.image_layer_path(namespace, repository,
|
||||||
image_id))
|
image_id))
|
||||||
|
@ -214,15 +214,15 @@ def get_image_json(namespace, repository, image_id, headers):
|
||||||
@set_cache_headers
|
@set_cache_headers
|
||||||
def get_image_ancestry(namespace, repository, image_id, headers):
|
def get_image_ancestry(namespace, repository, image_id, headers):
|
||||||
permission = ReadRepositoryPermission(namespace, repository)
|
permission = ReadRepositoryPermission(namespace, repository)
|
||||||
if (not permission.can() and not
|
if not permission.can() and not model.repository_is_public(namespace,
|
||||||
model.repository_is_public(namespace, repository)):
|
repository):
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = store.get_content(store.image_ancestry_path(namespace, repository,
|
data = store.get_content(store.image_ancestry_path(namespace, repository,
|
||||||
image_id))
|
image_id))
|
||||||
except IOError:
|
except IOError:
|
||||||
abort(404) #'Image not found', 404)
|
abort(404) # 'Image not found', 404)
|
||||||
response = make_response(json.dumps(json.loads(data)), 200)
|
response = make_response(json.dumps(json.loads(data)), 200)
|
||||||
response.headers.extend(headers)
|
response.headers.extend(headers)
|
||||||
return response
|
return response
|
||||||
|
@ -265,9 +265,9 @@ def put_image_json(namespace, repository, image_id):
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
if not data or not isinstance(data, dict):
|
if not data or not isinstance(data, dict):
|
||||||
abort(400) #'Invalid JSON')
|
abort(400) # 'Invalid JSON')
|
||||||
if 'id' not in data:
|
if 'id' not in data:
|
||||||
abort(400) #'Missing key `id\' in JSON')
|
abort(400) # 'Missing key `id\' in JSON')
|
||||||
# Read the checksum
|
# Read the checksum
|
||||||
checksum = request.headers.get('X-Docker-Checksum')
|
checksum = request.headers.get('X-Docker-Checksum')
|
||||||
if checksum:
|
if checksum:
|
||||||
|
@ -279,16 +279,16 @@ def put_image_json(namespace, repository, image_id):
|
||||||
# We cleanup any old checksum in case it's a retry after a fail
|
# We cleanup any old checksum in case it's a retry after a fail
|
||||||
store.remove(store.image_checksum_path(namespace, repository, image_id))
|
store.remove(store.image_checksum_path(namespace, repository, image_id))
|
||||||
if image_id != data['id']:
|
if image_id != data['id']:
|
||||||
abort(400) #'JSON data contains invalid id')
|
abort(400) # 'JSON data contains invalid id')
|
||||||
parent_id = data.get('parent')
|
parent_id = data.get('parent')
|
||||||
if parent_id and not store.exists(store.image_json_path(namespace,
|
if parent_id and not store.exists(store.image_json_path(namespace,
|
||||||
repository,
|
repository,
|
||||||
data['parent'])):
|
data['parent'])):
|
||||||
abort(400) #'Image depends on a non existing parent')
|
abort(400) # 'Image depends on a non existing parent')
|
||||||
json_path = store.image_json_path(namespace, repository, image_id)
|
json_path = store.image_json_path(namespace, repository, image_id)
|
||||||
mark_path = store.image_mark_path(namespace, repository, image_id)
|
mark_path = store.image_mark_path(namespace, repository, image_id)
|
||||||
if store.exists(json_path) and not store.exists(mark_path):
|
if store.exists(json_path) and not store.exists(mark_path):
|
||||||
abort(409) #'Image already exists', 409)
|
abort(409) # 'Image already exists', 409)
|
||||||
# If we reach that point, it means that this is a new image or a retry
|
# If we reach that point, it means that this is a new image or a retry
|
||||||
# on a failed push
|
# on a failed push
|
||||||
# save the metadata
|
# save the metadata
|
||||||
|
@ -311,4 +311,4 @@ def delete_repository_storage(namespace, repository):
|
||||||
repository_path = store.repository_namespace_path(namespace, repository)
|
repository_path = store.repository_namespace_path(namespace, repository)
|
||||||
|
|
||||||
logger.debug('Recursively deleting path: %s' % repository_path)
|
logger.debug('Recursively deleting path: %s' % repository_path)
|
||||||
store.remove(repository_path)
|
store.remove(repository_path)
|
||||||
|
|
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/v1/repositories/<path:repository>/tags',
|
@app.route('/v1/repositories/<path:repository>/tags',
|
||||||
methods=['GET'])
|
methods=['GET'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def get_tags(namespace, repository):
|
def get_tags(namespace, repository):
|
||||||
|
@ -34,7 +34,7 @@ def get_tags(namespace, repository):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
||||||
methods=['GET'])
|
methods=['GET'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def get_tag(namespace, repository, tag):
|
def get_tag(namespace, repository, tag):
|
||||||
|
@ -48,7 +48,7 @@ def get_tag(namespace, repository, tag):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
||||||
methods=['PUT'])
|
methods=['PUT'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def put_tag(namespace, repository, tag):
|
def put_tag(namespace, repository, tag):
|
||||||
|
@ -64,7 +64,7 @@ def put_tag(namespace, repository, tag):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
|
||||||
methods=['DELETE'])
|
methods=['DELETE'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def delete_tag(namespace, repository, tag):
|
def delete_tag(namespace, repository, tag):
|
||||||
|
@ -79,7 +79,7 @@ def delete_tag(namespace, repository, tag):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/v1/repositories/<path:repository>/tags',
|
@app.route('/v1/repositories/<path:repository>/tags',
|
||||||
methods=['DELETE'])
|
methods=['DELETE'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def delete_repository_tags(namespace, repository):
|
def delete_repository_tags(namespace, repository):
|
||||||
|
|
|
@ -60,7 +60,7 @@ def common_login(db_user):
|
||||||
identity=Identity(db_user.username, 'username'))
|
identity=Identity(db_user.username, 'username'))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.debug('User could not be logged in, inactive?.');
|
logger.debug('User could not be logged in, inactive?.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from data.database import initialize_db
|
from data.database import initialize_db
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
initialize_db()
|
initialize_db()
|
||||||
|
|
Reference in a new issue