Move route_show_if into decorators
Also removes unused route_hide_if
This commit is contained in:
parent
ed3ba07830
commit
17f3de811e
9 changed files with 24 additions and 46 deletions
|
@ -8,7 +8,7 @@ from auth.decorators import require_session_login
|
||||||
from buildtrigger.basehandler import BuildTriggerHandler
|
from buildtrigger.basehandler import BuildTriggerHandler
|
||||||
from buildtrigger.bitbuckethandler import BitbucketBuildTrigger
|
from buildtrigger.bitbuckethandler import BitbucketBuildTrigger
|
||||||
from data import model
|
from data import model
|
||||||
from endpoints.common import route_show_if
|
from endpoints.decorators import route_show_if
|
||||||
from util.http import abort
|
from util.http import abort
|
||||||
|
|
||||||
import features
|
import features
|
||||||
|
|
|
@ -54,29 +54,6 @@ def parse_repository_name(include_tag=False,
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
def route_show_if(value):
|
|
||||||
def decorator(f):
|
|
||||||
@wraps(f)
|
|
||||||
def decorated_function(*args, **kwargs):
|
|
||||||
if not value:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
return decorated_function
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def route_hide_if(value):
|
|
||||||
def decorator(f):
|
|
||||||
@wraps(f)
|
|
||||||
def decorated_function(*args, **kwargs):
|
|
||||||
if value:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
return decorated_function
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
def truthy_param(param):
|
def truthy_param(param):
|
||||||
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
|
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
|
||||||
|
|
|
@ -38,3 +38,17 @@ def check_anon_protection(func):
|
||||||
|
|
||||||
abort(401)
|
abort(401)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def route_show_if(value):
|
||||||
|
""" Adds/shows the decorated route if the given value is True. """
|
||||||
|
def decorator(f):
|
||||||
|
@wraps(f)
|
||||||
|
def decorated_function(*args, **kwargs):
|
||||||
|
if not value:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return decorated_function
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ from app import app, github_trigger
|
||||||
from auth.decorators import require_session_login
|
from auth.decorators import require_session_login
|
||||||
from auth.permissions import AdministerRepositoryPermission
|
from auth.permissions import AdministerRepositoryPermission
|
||||||
from data import model
|
from data import model
|
||||||
from endpoints.common import route_show_if, parse_repository_name
|
from endpoints.common import parse_repository_name
|
||||||
|
from endpoints.decorators import route_show_if
|
||||||
from util.http import abort
|
from util.http import abort
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from app import app, gitlab_trigger
|
||||||
from auth.decorators import require_session_login
|
from auth.decorators import require_session_login
|
||||||
from auth.permissions import AdministerRepositoryPermission
|
from auth.permissions import AdministerRepositoryPermission
|
||||||
from data import model
|
from data import model
|
||||||
from endpoints.common import route_show_if
|
from endpoints.decorators import route_show_if
|
||||||
from util.http import abort
|
from util.http import abort
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import features
|
||||||
|
|
||||||
from app import secscan_notification_queue
|
from app import secscan_notification_queue
|
||||||
from flask import request, make_response, Blueprint, abort
|
from flask import request, make_response, Blueprint, abort
|
||||||
from endpoints.common import route_show_if
|
from endpoints.decorators import route_show_if
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
secscan = Blueprint('secscan', __name__)
|
secscan = Blueprint('secscan', __name__)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from auth.auth_context import get_grant_context
|
||||||
from auth.permissions import (
|
from auth.permissions import (
|
||||||
ReadRepositoryPermission, ModifyRepositoryPermission, AdministerRepositoryPermission)
|
ReadRepositoryPermission, ModifyRepositoryPermission, AdministerRepositoryPermission)
|
||||||
from auth.registry_jwt_auth import process_registry_jwt_auth, get_auth_headers
|
from auth.registry_jwt_auth import process_registry_jwt_auth, get_auth_headers
|
||||||
from endpoints.decorators import anon_protect, anon_allowed
|
from endpoints.decorators import anon_protect, anon_allowed, route_show_if
|
||||||
from endpoints.v2.errors import V2RegistryException, Unauthorized, Unsupported, NameUnknown
|
from endpoints.v2.errors import V2RegistryException, Unauthorized, Unsupported, NameUnknown
|
||||||
from endpoints.v2.models_pre_oci import data_model as model
|
from endpoints.v2.models_pre_oci import data_model as model
|
||||||
from util.http import abort
|
from util.http import abort
|
||||||
|
@ -126,20 +126,6 @@ def get_input_stream(flask_request):
|
||||||
return flask_request.stream
|
return flask_request.stream
|
||||||
|
|
||||||
|
|
||||||
def route_show_if(value):
|
|
||||||
def decorator(f):
|
|
||||||
@wraps(f)
|
|
||||||
def decorated_function(*args, **kwargs):
|
|
||||||
if not value:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
|
|
||||||
return decorated_function
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
@v2_bp.route('/')
|
@v2_bp.route('/')
|
||||||
@route_show_if(features.ADVERTISE_V2)
|
@route_show_if(features.ADVERTISE_V2)
|
||||||
@process_registry_jwt_auth()
|
@process_registry_jwt_auth()
|
||||||
|
|
|
@ -10,8 +10,8 @@ from auth.auth_context import get_authenticated_user
|
||||||
from auth.decorators import process_auth
|
from auth.decorators import process_auth
|
||||||
from auth.permissions import ReadRepositoryPermission
|
from auth.permissions import ReadRepositoryPermission
|
||||||
from data import database
|
from data import database
|
||||||
from endpoints.common import route_show_if, parse_repository_name
|
from endpoints.common import parse_repository_name
|
||||||
from endpoints.decorators import anon_protect
|
from endpoints.decorators import anon_protect, route_show_if
|
||||||
from endpoints.verbs.models_pre_oci import pre_oci_model as model
|
from endpoints.verbs.models_pre_oci import pre_oci_model as model
|
||||||
from endpoints.v2.blob import BLOB_DIGEST_ROUTE
|
from endpoints.v2.blob import BLOB_DIGEST_ROUTE
|
||||||
from image.appc import AppCImageFormatter
|
from image.appc import AppCImageFormatter
|
||||||
|
|
|
@ -27,10 +27,10 @@ from buildtrigger.triggerutil import TriggerProviderException
|
||||||
from data import model
|
from data import model
|
||||||
from data.database import db
|
from data.database import db
|
||||||
from endpoints.api.discovery import swagger_route_data
|
from endpoints.api.discovery import swagger_route_data
|
||||||
from endpoints.common import (common_login, render_page_template, route_show_if, param_required,
|
from endpoints.common import (common_login, render_page_template, param_required,
|
||||||
parse_repository_name)
|
parse_repository_name)
|
||||||
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
||||||
from endpoints.decorators import anon_protect, anon_allowed
|
from endpoints.decorators import anon_protect, anon_allowed, route_show_if
|
||||||
from health.healthcheck import get_healthchecker
|
from health.healthcheck import get_healthchecker
|
||||||
from util.cache import no_cache
|
from util.cache import no_cache
|
||||||
from util.headers import parse_basic_auth
|
from util.headers import parse_basic_auth
|
||||||
|
|
Reference in a new issue