diff --git a/endpoints/bitbuckettrigger.py b/endpoints/bitbuckettrigger.py index e58f04db2..7e521c10d 100644 --- a/endpoints/bitbuckettrigger.py +++ b/endpoints/bitbuckettrigger.py @@ -8,7 +8,7 @@ from auth.decorators import require_session_login from buildtrigger.basehandler import BuildTriggerHandler from buildtrigger.bitbuckethandler import BitbucketBuildTrigger from data import model -from endpoints.common import route_show_if +from endpoints.decorators import route_show_if from util.http import abort import features diff --git a/endpoints/common.py b/endpoints/common.py index a43ecbd74..50eccc0f4 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -54,29 +54,6 @@ def parse_repository_name(include_tag=False, 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): return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'} diff --git a/endpoints/decorators.py b/endpoints/decorators.py index 3cc374db3..89093806a 100644 --- a/endpoints/decorators.py +++ b/endpoints/decorators.py @@ -38,3 +38,17 @@ def check_anon_protection(func): abort(401) 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 + diff --git a/endpoints/githubtrigger.py b/endpoints/githubtrigger.py index 416df8842..3b373bdf0 100644 --- a/endpoints/githubtrigger.py +++ b/endpoints/githubtrigger.py @@ -9,7 +9,8 @@ from app import app, github_trigger from auth.decorators import require_session_login from auth.permissions import AdministerRepositoryPermission 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 diff --git a/endpoints/gitlabtrigger.py b/endpoints/gitlabtrigger.py index e1bb31001..4d97caffe 100644 --- a/endpoints/gitlabtrigger.py +++ b/endpoints/gitlabtrigger.py @@ -9,7 +9,7 @@ from app import app, gitlab_trigger from auth.decorators import require_session_login from auth.permissions import AdministerRepositoryPermission from data import model -from endpoints.common import route_show_if +from endpoints.decorators import route_show_if from util.http import abort diff --git a/endpoints/secscan.py b/endpoints/secscan.py index 6ce803e1e..ca061a050 100644 --- a/endpoints/secscan.py +++ b/endpoints/secscan.py @@ -5,7 +5,7 @@ import features from app import secscan_notification_queue 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__) secscan = Blueprint('secscan', __name__) diff --git a/endpoints/v2/__init__.py b/endpoints/v2/__init__.py index db490de02..198b56cbe 100644 --- a/endpoints/v2/__init__.py +++ b/endpoints/v2/__init__.py @@ -15,7 +15,7 @@ from auth.auth_context import get_grant_context from auth.permissions import ( ReadRepositoryPermission, ModifyRepositoryPermission, AdministerRepositoryPermission) 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.models_pre_oci import data_model as model from util.http import abort @@ -126,20 +126,6 @@ def get_input_stream(flask_request): 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('/') @route_show_if(features.ADVERTISE_V2) @process_registry_jwt_auth() diff --git a/endpoints/verbs/__init__.py b/endpoints/verbs/__init__.py index 93f863989..0522c5a38 100644 --- a/endpoints/verbs/__init__.py +++ b/endpoints/verbs/__init__.py @@ -10,8 +10,8 @@ from auth.auth_context import get_authenticated_user from auth.decorators import process_auth from auth.permissions import ReadRepositoryPermission from data import database -from endpoints.common import route_show_if, parse_repository_name -from endpoints.decorators import anon_protect +from endpoints.common import parse_repository_name +from endpoints.decorators import anon_protect, route_show_if from endpoints.verbs.models_pre_oci import pre_oci_model as model from endpoints.v2.blob import BLOB_DIGEST_ROUTE from image.appc import AppCImageFormatter diff --git a/endpoints/web.py b/endpoints/web.py index feefc8465..db4a9d696 100644 --- a/endpoints/web.py +++ b/endpoints/web.py @@ -27,10 +27,10 @@ from buildtrigger.triggerutil import TriggerProviderException from data import model from data.database import db 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) 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 util.cache import no_cache from util.headers import parse_basic_auth