Move each flask module into a Blueprint and have CSRF protection only on the API blueprint
This commit is contained in:
parent
b598c7ec85
commit
310c98df50
8 changed files with 174 additions and 162 deletions
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from flask import make_response, request, session, Response, abort, redirect
|
||||
from flask import (make_response, request, session, Response, abort,
|
||||
redirect, Blueprint)
|
||||
from functools import wraps
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
|
@ -15,6 +16,7 @@ from auth.permissions import (ReadRepositoryPermission,
|
|||
ModifyRepositoryPermission)
|
||||
from data import model
|
||||
|
||||
registry = Blueprint('registry', __name__)
|
||||
|
||||
store = app.config['STORAGE']
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -72,7 +74,7 @@ def set_cache_headers(f):
|
|||
return wrapper
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/layer', methods=['GET'])
|
||||
@registry.route('/images/<image_id>/layer', methods=['GET'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
@require_completion
|
||||
|
@ -92,7 +94,7 @@ def get_image_layer(namespace, repository, image_id, headers):
|
|||
abort(403)
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/layer', methods=['PUT'])
|
||||
@registry.route('/images/<image_id>/layer', methods=['PUT'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
def put_image_layer(namespace, repository, image_id):
|
||||
|
@ -158,7 +160,7 @@ def put_image_layer(namespace, repository, image_id):
|
|||
return make_response('true', 200)
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/checksum', methods=['PUT'])
|
||||
@registry.route('/images/<image_id>/checksum', methods=['PUT'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
def put_image_checksum(namespace, repository, image_id):
|
||||
|
@ -199,7 +201,7 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
return make_response('true', 200)
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/json', methods=['GET'])
|
||||
@registry.route('/images/<image_id>/json', methods=['GET'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
@require_completion
|
||||
|
@ -229,7 +231,7 @@ def get_image_json(namespace, repository, image_id, headers):
|
|||
return response
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/ancestry', methods=['GET'])
|
||||
@registry.route('/images/<image_id>/ancestry', methods=['GET'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
@require_completion
|
||||
|
@ -274,7 +276,7 @@ def store_checksum(namespace, repository, image_id, checksum):
|
|||
store.put_content(checksum_path, checksum)
|
||||
|
||||
|
||||
@app.route('/v1/images/<image_id>/json', methods=['PUT'])
|
||||
@registry.route('/images/<image_id>/json', methods=['PUT'])
|
||||
@process_auth
|
||||
@extract_namespace_repo_from_session
|
||||
def put_image_json(namespace, repository, image_id):
|
||||
|
|
Reference in a new issue