Merge pull request #2594 from coreos-inc/show-if-ordering

Fix show_if ordering and add a check that fails if misordered
This commit is contained in:
josephschorr 2017-05-01 13:17:39 -04:00 committed by GitHub
commit 02c4d75634
4 changed files with 16 additions and 4 deletions

View file

@ -56,6 +56,7 @@ def resource(*urls, **kwargs):
if not api_resource: if not api_resource:
return None return None
api_resource.registered = True
api.add_resource(api_resource, *urls, **kwargs) api.add_resource(api_resource, *urls, **kwargs)
return api_resource return api_resource
return wrapper return wrapper
@ -63,6 +64,11 @@ def resource(*urls, **kwargs):
def show_if(value): def show_if(value):
def f(inner): def f(inner):
if hasattr(inner, 'registered') and inner.registered:
msg = ('API endpoint %s is already registered; please switch the ' +
'@show_if to be *below* the @resource decorator')
raise Exception(msg % inner)
if not value: if not value:
return None return None
@ -72,6 +78,11 @@ def show_if(value):
def hide_if(value): def hide_if(value):
def f(inner): def f(inner):
if hasattr(inner, 'registered') and inner.registered:
msg = ('API endpoint %s is already registered; please switch the ' +
'@hide_if to be *below* the @resource decorator')
raise Exception(msg % inner)
if value: if value:
return None return None
@ -195,6 +206,7 @@ def parse_repository_name(func):
class ApiResource(Resource): class ApiResource(Resource):
registered = False
method_decorators = [check_anon_protection] method_decorators = [check_anon_protection]
def options(self): def options(self):

View file

@ -29,8 +29,8 @@ def record_view(record):
@internal_only @internal_only
@show_if(features.MAILING)
@resource('/v1/repository/<apirepopath:repository>/authorizedemail/<email>') @resource('/v1/repository/<apirepopath:repository>/authorizedemail/<email>')
@show_if(features.MAILING)
@path_param('repository', 'The full path of the repository. e.g. namespace/name') @path_param('repository', 'The full path of the repository. e.g. namespace/name')
@path_param('email', 'The e-mail address') @path_param('email', 'The e-mail address')
class RepositoryAuthorizedEmail(RepositoryParamResource): class RepositoryAuthorizedEmail(RepositoryParamResource):

View file

@ -58,8 +58,8 @@ def _security_status_for_image(namespace, repository, repo_image, include_vulner
} }
@show_if(features.SECURITY_SCANNER)
@resource('/v1/repository/<apirepopath:repository>/image/<imageid>/security') @resource('/v1/repository/<apirepopath:repository>/image/<imageid>/security')
@show_if(features.SECURITY_SCANNER)
@path_param('repository', 'The full path of the repository. e.g. namespace/name') @path_param('repository', 'The full path of the repository. e.g. namespace/name')
@path_param('imageid', 'The image ID') @path_param('imageid', 'The image ID')
class RepositoryImageSecurity(RepositoryParamResource): class RepositoryImageSecurity(RepositoryParamResource):
@ -80,8 +80,8 @@ class RepositoryImageSecurity(RepositoryParamResource):
return _security_status_for_image(namespace, repository, repo_image, return _security_status_for_image(namespace, repository, repo_image,
parsed_args.vulnerabilities) parsed_args.vulnerabilities)
@show_if(features.SECURITY_SCANNER)
@resource(MANIFEST_DIGEST_ROUTE + '/security') @resource(MANIFEST_DIGEST_ROUTE + '/security')
@show_if(features.SECURITY_SCANNER)
@path_param('repository', 'The full path of the repository. e.g. namespace/name') @path_param('repository', 'The full path of the repository. e.g. namespace/name')
@path_param('manifestref', 'The digest of the manifest') @path_param('manifestref', 'The digest of the manifest')
class RepositoryManifestSecurity(RepositoryParamResource): class RepositoryManifestSecurity(RepositoryParamResource):

View file

@ -12,8 +12,8 @@ from endpoints.api import (require_repo_read, path_param,
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@show_if(features.SIGNING)
@resource('/v1/repository/<apirepopath:repository>/signatures') @resource('/v1/repository/<apirepopath:repository>/signatures')
@show_if(features.SIGNING)
@path_param('repository', 'The full path of the repository. e.g. namespace/name') @path_param('repository', 'The full path of the repository. e.g. namespace/name')
class RepositorySignatures(RepositoryParamResource): class RepositorySignatures(RepositoryParamResource):
""" Operations for managing the signatures in a repository image. """ """ Operations for managing the signatures in a repository image. """