from pybossa.contributions_guard import ContributionsGuard from pybossa.auth import jwt_authorize_project from werkzeug.exceptions import MethodNotAllowed, Forbidden from completed_task import CompletedTaskAPI from completed_task_run import CompletedTaskRunAPI from pybossa.cache.helpers import n_available_tasks, n_available_tasks_for_user from pybossa.sched import (get_project_scheduler_and_timeout, get_scheduler_and_timeout, has_lock, release_lock, Schedulers, get_locks) from pybossa.api.project_by_name import ProjectByNameAPI from pybossa.api.pwd_manager import get_pwd_manager from pybossa.data_access import data_access_levels blueprint = Blueprint('api', __name__) error = ErrorStatus() @blueprint.route('/') @ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER')) def index(): # pragma: no cover """Return dummy text for welcome page.""" return 'The %s API' % current_app.config.get('BRAND') @blueprint.before_request def _api_authentication_with_api_key(): """ Allow API access with valid api_key.""" secure_app_access = current_app.config.get('SECURE_APP_ACCESS', False) if secure_app_access: grant_access_with_api_key(secure_app_access)
def __init__(self, app=None): self.url = app.config['DISCOURSE_URL'] self.api_key = app.config['DISCOURSE_API_KEY'] self.api_username = app.config['DISCOURSE_API_USERNAME'] self.error_status = ErrorStatus()