from functools import wraps

from anillo.http import Unauthorized
from anillo_auth.backends.token import JWSBackend
from itsdangerous import JSONWebSignatureSerializer

from errors.errors import get_response_error
from settings.base import config

_secret = config.get("login", "secret")
_token_name = "Bearer"


def login_required(func):
    @wraps(func)
    def wrapper(instance, request):
        if request.get('identity') == None:
            return unauthorized()
        else:
            return func(instance, request)

    return wrapper


def unauthorized():
    return Unauthorized({"error": get_response_error("NOT_LOGGED")})


def backend():
    return JWSBackend(secret=_secret, token_name=_token_name)
Exemple #2
0
import redis

from settings.base import config


r = redis.StrictRedis(host=config.get('redis', 'host'),
                      port=config.getint('redis', 'port'),
                      db=config.getint('redis', 'db'))
Exemple #3
0
import sys

from anillo.app import application
from anillo.handlers.routing import router
from anillo.middlewares.json import wrap_json_body, wrap_json_response
from anillo.utils.common import chain
from anillo_auth.auth import wrap_auth

from settings.base import config
from urls import urls
from utils.authorization import backend as auth_backend
from utils.middlewares.cors import wrap_cors_response
from utils.middlewares.sqlalchemy import wrap_sqlalchemy_session

DEFAULT_PORT = config.getint('server', 'port')
DEFAULT_HOST = config.get('server', 'host')


def setup_app():
    main_handler = chain(
            wrap_auth(backend=auth_backend),
            wrap_json_body,
            wrap_json_response,
            wrap_cors_response,
            wrap_sqlalchemy_session,
            router(urls)
    )

    return application(main_handler)