Move parse_repository_name into decorators
This commit is contained in:
parent
a64f268344
commit
98e2ccf74d
10 changed files with 40 additions and 49 deletions
|
@ -1,14 +1,9 @@
|
|||
import logging
|
||||
import json
|
||||
import string
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
|
||||
from random import SystemRandom
|
||||
from functools import wraps
|
||||
|
||||
from cachetools import lru_cache
|
||||
from flask import make_response, render_template, request, abort, session
|
||||
from flask_login import login_user
|
||||
from flask_principal import identity_changed
|
||||
|
@ -21,11 +16,10 @@ from auth import scopes
|
|||
from auth.permissions import QuayDeferredPermissionUser
|
||||
from config import frontend_visible_config
|
||||
from external_libraries import get_external_javascript, get_external_css
|
||||
from util.names import parse_namespace_repository
|
||||
from util.secscan import PRIORITY_LEVELS
|
||||
from util.saas.useranalytics import build_error_callback
|
||||
from util.timedeltastring import convert_to_timedelta
|
||||
from _init import STATIC_DIR, __version__
|
||||
from _init import __version__
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -33,28 +27,6 @@ logger = logging.getLogger(__name__)
|
|||
route_data = None
|
||||
|
||||
|
||||
def parse_repository_name(include_tag=False,
|
||||
ns_kwarg_name='namespace_name',
|
||||
repo_kwarg_name='repo_name',
|
||||
tag_kwarg_name='tag_name',
|
||||
incoming_repo_kwarg='repository'):
|
||||
def inner(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
repo_name_components = parse_namespace_repository(kwargs[incoming_repo_kwarg],
|
||||
app.config['LIBRARY_NAMESPACE'],
|
||||
include_tag=include_tag)
|
||||
del kwargs[incoming_repo_kwarg]
|
||||
kwargs[ns_kwarg_name] = repo_name_components[0]
|
||||
kwargs[repo_kwarg_name] = repo_name_components[1]
|
||||
if include_tag:
|
||||
kwargs[tag_kwarg_name] = repo_name_components[2]
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return inner
|
||||
|
||||
|
||||
|
||||
def truthy_param(param):
|
||||
return param not in {False, 'false', 'False', '0', 'FALSE', '', 'null'}
|
||||
|
||||
|
@ -99,8 +71,8 @@ def common_login(db_user, permanent_session=True):
|
|||
return False
|
||||
|
||||
|
||||
def list_files(path, extension):
|
||||
import os
|
||||
def _list_files(path, extension):
|
||||
""" Returns a list of all the files with the given extension found under the given path. """
|
||||
def matches(f):
|
||||
return os.path.splitext(f)[1] == '.' + extension and f.split(os.path.extsep)[1] != 'spec'
|
||||
|
||||
|
@ -118,7 +90,7 @@ def render_page_template(name, route_data=None, **kwargs):
|
|||
library_styles = []
|
||||
main_styles = []
|
||||
library_scripts = []
|
||||
main_scripts = list_files('build', 'js')
|
||||
main_scripts = _list_files('build', 'js')
|
||||
|
||||
use_cdn = app.config.get('USE_CDN', True)
|
||||
if request.args.get('use_cdn') is not None:
|
||||
|
|
|
@ -4,8 +4,35 @@ from functools import wraps
|
|||
from flask import abort
|
||||
|
||||
import features
|
||||
|
||||
from app import app
|
||||
from auth.auth_context import (
|
||||
get_validated_oauth_token, get_authenticated_user, get_validated_token, get_grant_context)
|
||||
from util.names import parse_namespace_repository
|
||||
|
||||
|
||||
def parse_repository_name(include_tag=False,
|
||||
ns_kwarg_name='namespace_name',
|
||||
repo_kwarg_name='repo_name',
|
||||
tag_kwarg_name='tag_name',
|
||||
incoming_repo_kwarg='repository'):
|
||||
""" Decorator which parses the repository name found in the incoming_repo_kwarg argument,
|
||||
and applies its pieces to the decorated function.
|
||||
"""
|
||||
def inner(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
repo_name_components = parse_namespace_repository(kwargs[incoming_repo_kwarg],
|
||||
app.config['LIBRARY_NAMESPACE'],
|
||||
include_tag=include_tag)
|
||||
del kwargs[incoming_repo_kwarg]
|
||||
kwargs[ns_kwarg_name] = repo_name_components[0]
|
||||
kwargs[repo_kwarg_name] = repo_name_components[1]
|
||||
if include_tag:
|
||||
kwargs[tag_kwarg_name] = repo_name_components[2]
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return inner
|
||||
|
||||
|
||||
def anon_allowed(func):
|
||||
|
|
|
@ -9,8 +9,7 @@ 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 parse_repository_name
|
||||
from endpoints.decorators import route_show_if
|
||||
from endpoints.decorators import route_show_if, parse_repository_name
|
||||
from util.http import abort
|
||||
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ from auth.permissions import (
|
|||
ModifyRepositoryPermission, UserAdminPermission, ReadRepositoryPermission,
|
||||
CreateRepositoryPermission, repository_read_grant, repository_write_grant)
|
||||
from auth.signedgrant import generate_signed_token
|
||||
from endpoints.common import parse_repository_name
|
||||
from endpoints.decorators import anon_protect, anon_allowed
|
||||
from endpoints.decorators import anon_protect, anon_allowed, parse_repository_name
|
||||
from endpoints.notificationhelper import spawn_notification
|
||||
from endpoints.v1 import v1_bp
|
||||
from endpoints.v1.models_pre_oci import pre_oci_model as model
|
||||
|
|
|
@ -6,8 +6,7 @@ from flask import abort, request, jsonify, make_response, session
|
|||
from auth.decorators import process_auth
|
||||
from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission)
|
||||
from data import model
|
||||
from endpoints.common import parse_repository_name
|
||||
from endpoints.decorators import anon_protect
|
||||
from endpoints.decorators import anon_protect, parse_repository_name
|
||||
from endpoints.v1 import v1_bp
|
||||
from endpoints.v1.models_pre_oci import pre_oci_model as model
|
||||
from util.audit import track_and_log
|
||||
|
|
|
@ -11,8 +11,7 @@ from app import storage, app, get_app_url, metric_queue
|
|||
from auth.registry_jwt_auth import process_registry_jwt_auth
|
||||
from data import database
|
||||
from digest import digest_tools
|
||||
from endpoints.common import parse_repository_name
|
||||
from endpoints.decorators import anon_protect
|
||||
from endpoints.decorators import anon_protect, parse_repository_name
|
||||
from endpoints.v2 import v2_bp, require_repo_read, require_repo_write, get_input_stream
|
||||
from endpoints.v2.errors import (
|
||||
BlobUnknown, BlobUploadInvalid, BlobUploadUnknown, Unsupported, NameUnknown, LayerTooLarge)
|
||||
|
|
|
@ -9,8 +9,7 @@ import features
|
|||
from app import docker_v2_signing_key, app, metric_queue
|
||||
from auth.registry_jwt_auth import process_registry_jwt_auth
|
||||
from digest import digest_tools
|
||||
from endpoints.common import parse_repository_name
|
||||
from endpoints.decorators import anon_protect
|
||||
from endpoints.decorators import anon_protect, parse_repository_name
|
||||
from endpoints.notificationhelper import spawn_notification
|
||||
from endpoints.v2 import v2_bp, require_repo_read, require_repo_write
|
||||
from endpoints.v2.models_interface import Label
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from flask import jsonify
|
||||
|
||||
from auth.registry_jwt_auth import process_registry_jwt_auth
|
||||
from endpoints.common import parse_repository_name
|
||||
from endpoints.decorators import anon_protect
|
||||
from endpoints.decorators import anon_protect, parse_repository_name
|
||||
from endpoints.v2 import v2_bp, require_repo_read, paginate
|
||||
from endpoints.v2.models_pre_oci import data_model as model
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ 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 parse_repository_name
|
||||
from endpoints.decorators import anon_protect, route_show_if
|
||||
from endpoints.decorators import anon_protect, route_show_if, parse_repository_name
|
||||
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
|
||||
|
|
|
@ -27,10 +27,9 @@ 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, param_required,
|
||||
parse_repository_name)
|
||||
from endpoints.common import (common_login, render_page_template, param_required)
|
||||
from endpoints.csrf import csrf_protect, generate_csrf_token, verify_csrf
|
||||
from endpoints.decorators import anon_protect, anon_allowed, route_show_if
|
||||
from endpoints.decorators import anon_protect, anon_allowed, route_show_if, parse_repository_name
|
||||
from health.healthcheck import get_healthchecker
|
||||
from util.cache import no_cache
|
||||
from util.headers import parse_basic_auth
|
||||
|
|
Reference in a new issue