Use doc strings for resource and method docs. Tweak some docs. Switch to 100 length lines.
This commit is contained in:
parent
978d68f0e0
commit
220649e579
3 changed files with 43 additions and 51 deletions
|
@ -5,12 +5,10 @@ from flask.ext.restful import Resource, reqparse, abort
|
|||
from flask.ext.login import current_user
|
||||
|
||||
from data import model
|
||||
from endpoints.api import (truthy_bool, format_date, nickname, log_action,
|
||||
validate_json_request, require_repo_read,
|
||||
RepositoryParamResource, resource, query_parameter,
|
||||
from endpoints.api import (truthy_bool, format_date, nickname, log_action, validate_json_request,
|
||||
require_repo_read, RepositoryParamResource, resource, query_param,
|
||||
parse_args)
|
||||
from auth.permissions import (ReadRepositoryPermission,
|
||||
ModifyRepositoryPermission,
|
||||
from auth.permissions import (ReadRepositoryPermission, ModifyRepositoryPermission,
|
||||
AdministerRepositoryPermission)
|
||||
|
||||
|
||||
|
@ -19,11 +17,12 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
@resource('/v1/repository')
|
||||
class RepositoryList(Resource):
|
||||
"""Operations for creating and listing repositories."""
|
||||
schemas = {
|
||||
'NewRepo': {
|
||||
'id': 'NewRepo',
|
||||
'type': 'object',
|
||||
'description': 'Description of a new repository.',
|
||||
'description': 'Description of a new repository',
|
||||
'required': [
|
||||
'repository',
|
||||
'visibility',
|
||||
|
@ -31,11 +30,11 @@ class RepositoryList(Resource):
|
|||
'properties': {
|
||||
'repository': {
|
||||
'type': 'string',
|
||||
'description': 'Repository name.',
|
||||
'description': 'Repository name',
|
||||
},
|
||||
'visibility': {
|
||||
'type': 'string',
|
||||
'description': 'Visibility which the repository will start with.',
|
||||
'description': 'Visibility which the repository will start with',
|
||||
'enum': [
|
||||
'public',
|
||||
'private',
|
||||
|
@ -43,13 +42,12 @@ class RepositoryList(Resource):
|
|||
},
|
||||
'namespace': {
|
||||
'type': 'string',
|
||||
'description': ('Namespace in which the repository should be '
|
||||
'created. If omitted, the username of the caller is'
|
||||
'used.'),
|
||||
'description': ('Namespace in which the repository should be created. If omitted, the '
|
||||
'username of the caller is used'),
|
||||
},
|
||||
'description': {
|
||||
'type': 'string',
|
||||
'description': 'Markdown encoded description for the repository.',
|
||||
'description': 'Markdown encoded description for the repository',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +56,7 @@ class RepositoryList(Resource):
|
|||
@nickname('createRepo')
|
||||
@validate_json_request('NewRepo')
|
||||
def post(self):
|
||||
"""Create a new repository."""
|
||||
owner = current_user.db_user()
|
||||
req = request.get_json()
|
||||
namespace_name = req['namespace'] if 'namespace' in req else owner.username
|
||||
|
@ -78,9 +77,8 @@ class RepositoryList(Resource):
|
|||
repo.description = req['description']
|
||||
repo.save()
|
||||
|
||||
log_action('create_repo', namespace_name,
|
||||
{'repo': repository_name, 'namespace': namespace_name},
|
||||
repo=repo)
|
||||
log_action('create_repo', namespace_name, {'repo': repository_name,
|
||||
'namespace': namespace_name}, repo=repo)
|
||||
return jsonify({
|
||||
'namespace': namespace_name,
|
||||
'name': repository_name
|
||||
|
@ -90,20 +88,17 @@ class RepositoryList(Resource):
|
|||
|
||||
@nickname('listRepos')
|
||||
@parse_args
|
||||
@query_parameter('page', 'Offset page number. (int)', type=int)
|
||||
@query_parameter('limit', 'Limit on the number of results (int)', type=int)
|
||||
@query_parameter('namespace', ('Namespace to use when querying for org '
|
||||
'repositories.'), type=str)
|
||||
@query_parameter('public', 'Whether to include public repositories.',
|
||||
type=truthy_bool, default=True)
|
||||
@query_parameter('private', 'Whether to inlcude private repositories.',
|
||||
type=truthy_bool, default=True)
|
||||
@query_parameter('sort', 'Whether to sort the results.', type=truthy_bool,
|
||||
default=False)
|
||||
@query_parameter('count', ('Whether to include a count of the total number '
|
||||
'of results available.'), type=truthy_bool,
|
||||
default=False)
|
||||
@query_param('page', 'Offset page number. (int)', type=int)
|
||||
@query_param('limit', 'Limit on the number of results (int)', type=int)
|
||||
@query_param('namespace', 'Namespace to use when querying for org repositories.', type=str)
|
||||
@query_param('public', 'Whether to include public repositories.', type=truthy_bool, default=True)
|
||||
@query_param('private', 'Whether to inlcude private repositories.', type=truthy_bool,
|
||||
default=True)
|
||||
@query_param('sort', 'Whether to sort the results.', type=truthy_bool, default=False)
|
||||
@query_param('count', 'Whether to include a count of the total number of results available.',
|
||||
type=truthy_bool, default=False)
|
||||
def get(self, args):
|
||||
"""Fetch the list of repositories under a variety of situations."""
|
||||
def repo_view(repo_obj):
|
||||
return {
|
||||
'namespace': repo_obj.namespace,
|
||||
|
@ -120,15 +115,12 @@ class RepositoryList(Resource):
|
|||
|
||||
repo_count = None
|
||||
if args['count']:
|
||||
repo_count = model.get_visible_repository_count(username,
|
||||
include_public=args['public'],
|
||||
repo_count = model.get_visible_repository_count(username, include_public=args['public'],
|
||||
namespace=args['namespace'])
|
||||
response['count'] = repo_count
|
||||
|
||||
repo_query = model.get_visible_repositories(username, limit=args['limit'],
|
||||
page=args['page'],
|
||||
include_public=args['public'],
|
||||
sort=args['sort'],
|
||||
repo_query = model.get_visible_repositories(username, limit=args['limit'], page=args['page'],
|
||||
include_public=args['public'], sort=args['sort'],
|
||||
namespace=args['namespace'])
|
||||
|
||||
response['repositories'] = [repo_view(repo) for repo in repo_query]
|
||||
|
@ -153,9 +145,11 @@ def image_view(image):
|
|||
|
||||
@resource('/v1/repository/<path:repository>')
|
||||
class Repository(RepositoryParamResource):
|
||||
"""Operations for managing a specific repository."""
|
||||
@require_repo_read
|
||||
@nickname('getRepo')
|
||||
def get(self, namespace, repository):
|
||||
"""Fetch the specified repository."""
|
||||
logger.debug('Get repo: %s/%s' % (namespace, repository))
|
||||
|
||||
def tag_view(tag):
|
||||
|
|
Reference in a new issue