more apispec setup
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
class TokenResponse(object):
|
||||
def __init__(self, token: str) -> None:
|
||||
super().__init__()
|
||||
self.token = token
|
||||
@@ -1,22 +1,25 @@
|
||||
from flask import Blueprint, current_app
|
||||
from flask_jwt_extended import jwt_required, create_access_token
|
||||
from flask_apispec import use_kwargs, marshal_with
|
||||
from flask_apispec import use_kwargs, marshal_with, doc
|
||||
from marshmallow import fields
|
||||
|
||||
from api.exceptions import BadRequestException
|
||||
import api.constants as constants
|
||||
|
||||
from .models import TokenResponse
|
||||
from .serializers import login_schema, token_response_schema
|
||||
|
||||
from .serializers import token_response_schema
|
||||
blueprint = Blueprint('login', __name__)
|
||||
|
||||
|
||||
@doc(tags=['login'])
|
||||
@blueprint.route('', methods=['POST'])
|
||||
@jwt_required(optional=True)
|
||||
@use_kwargs(login_schema)
|
||||
@use_kwargs({
|
||||
'username': fields.Str(required=True),
|
||||
'password': fields.Str(required=True)
|
||||
})
|
||||
@marshal_with(token_response_schema)
|
||||
def login_user(username, password, **kwargs):
|
||||
if username == constants.API_USER and password == current_app.config[constants.API_PASS]:
|
||||
return TokenResponse(create_access_token(identity=username, fresh=True))
|
||||
return {'token': create_access_token(identity=username, fresh=True, expires_delta=False)}
|
||||
else:
|
||||
raise BadRequestException("Wrong combination of username and password")
|
||||
|
||||
@@ -16,6 +16,8 @@ class Config(object):
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
JWT_AUTH_USERNAME_KEY = 'email'
|
||||
JWT_AUTH_HEADER_PREFIX = 'Token'
|
||||
APISPEC_TITLE = 'MahssageBus API'
|
||||
APISPEC_VERSION = 'v0.1'
|
||||
|
||||
|
||||
class ProdConfig(Config):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from flask import Blueprint
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_apispec import use_kwargs, marshal_with
|
||||
from flask_apispec import use_kwargs, marshal_with, doc
|
||||
|
||||
from api.exceptions import NotFoundException
|
||||
|
||||
@@ -10,6 +10,7 @@ from .serializers import target_exchange_schema, target_exchanges_schema
|
||||
blueprint = Blueprint('target_exchange', __name__)
|
||||
|
||||
|
||||
@doc(tags=['TargetExchange'])
|
||||
@blueprint.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@marshal_with(target_exchanges_schema)
|
||||
@@ -17,6 +18,7 @@ def get_list():
|
||||
return TargetExchange.query.all()
|
||||
|
||||
|
||||
@doc(tags=['TargetExchange'])
|
||||
@blueprint.route('', methods=['POST'])
|
||||
@jwt_required()
|
||||
@use_kwargs(target_exchange_schema)
|
||||
@@ -27,6 +29,7 @@ def create(name):
|
||||
return target_exchange
|
||||
|
||||
|
||||
@doc(tags=['TargetExchange'])
|
||||
@blueprint.route('/<id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@marshal_with(target_exchange_schema)
|
||||
@@ -37,6 +40,8 @@ def get_by_id(id):
|
||||
else:
|
||||
return NotFoundException(__name__)
|
||||
|
||||
|
||||
@doc(tags=['TargetExchange'])
|
||||
@blueprint.route('/<id>', methods=['PUT'])
|
||||
@jwt_required()
|
||||
@use_kwargs(target_exchange_schema)
|
||||
|
||||
Reference in New Issue
Block a user