2017-03-23 01:52:45 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from functools import wraps
|
|
|
|
|
2017-08-10 00:45:46 +00:00
|
|
|
from cnr.exception import Forbidden
|
2017-03-23 01:52:45 +00:00
|
|
|
from flask import Blueprint
|
|
|
|
|
|
|
|
from app import metric_queue
|
|
|
|
from auth.permissions import (AdministerRepositoryPermission, ReadRepositoryPermission,
|
|
|
|
ModifyRepositoryPermission)
|
2017-03-23 03:53:03 +00:00
|
|
|
from endpoints.appr.decorators import require_repo_permission
|
2017-03-23 01:52:45 +00:00
|
|
|
from util.metrics.metricqueue import time_blueprint
|
|
|
|
|
|
|
|
|
|
|
|
appr_bp = Blueprint('appr', __name__)
|
|
|
|
time_blueprint(appr_bp, metric_queue)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def _raise_method(repository, scopes):
|
2017-03-24 11:01:11 +00:00
|
|
|
raise Forbidden("Unauthorized access for: %s" % repository,
|
|
|
|
{"package": repository, "scopes": scopes})
|
2017-03-23 01:52:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _get_reponame_kwargs(*args, **kwargs):
|
|
|
|
return [kwargs['namespace'], kwargs['package_name']]
|
|
|
|
|
|
|
|
|
|
|
|
require_app_repo_read = require_repo_permission(ReadRepositoryPermission,
|
|
|
|
scopes=['pull'],
|
|
|
|
allow_public=True,
|
|
|
|
raise_method=_raise_method,
|
|
|
|
get_reponame_method=_get_reponame_kwargs)
|
|
|
|
|
|
|
|
require_app_repo_write = require_repo_permission(ModifyRepositoryPermission,
|
|
|
|
scopes=['pull', 'push'],
|
|
|
|
raise_method=_raise_method,
|
|
|
|
get_reponame_method=_get_reponame_kwargs)
|
|
|
|
|
|
|
|
require_app_repo_admin = require_repo_permission(AdministerRepositoryPermission,
|
|
|
|
scopes=['pull', 'push'],
|
|
|
|
raise_method=_raise_method,
|
|
|
|
get_reponame_method=_get_reponame_kwargs)
|