from flask import Blueprint, request, abort

from epmanage.lib.auth import AuthController, AuthException

auth_component = Blueprint('auth_component', __name__)


@auth_component.route('/', methods=['POST'])
def auth_do():
    """Perform authentication"""
    try:
        return AuthController.get_token_agent(request.json)
    except AuthException:
        abort(503)
    except:
        abort(503)


@auth_component.route('/enroll', methods=['POST'])
def enroll_do():
    """Perform enrollment"""
    try:
        return AuthController.enroll_agent(request.json)
    except AuthException:
        abort(503)
    except:
        abort(503)
