webhook endpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from flask import Flask, Blueprint
|
from flask import Flask, Blueprint
|
||||||
|
|
||||||
from . import commands, login, target_exchange, target, registration
|
from . import commands, login, target_exchange, target, registration, webhook
|
||||||
from .exceptions import ApiException
|
from .exceptions import ApiException
|
||||||
from .extensions import db, migrate, jwt, apispec, rabbit
|
from .extensions import db, migrate, jwt, apispec, rabbit
|
||||||
from .settings import ProdConfig, Config
|
from .settings import ProdConfig, Config
|
||||||
@@ -44,6 +44,7 @@ def register_blueprints(app: Flask):
|
|||||||
api_blueprint.register_blueprint(registration.views.blueprint, url_prefix='/registration')
|
api_blueprint.register_blueprint(registration.views.blueprint, url_prefix='/registration')
|
||||||
|
|
||||||
app.register_blueprint(api_blueprint)
|
app.register_blueprint(api_blueprint)
|
||||||
|
app.register_blueprint(webhook.views.blueprint)
|
||||||
|
|
||||||
|
|
||||||
def register_apispecs(app: Flask):
|
def register_apispecs(app: Flask):
|
||||||
|
|||||||
@@ -19,3 +19,6 @@ class Registration(SurrogatePK, Model):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(Registration, self).__init__(**kwargs)
|
super(Registration, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<{Registration.__name__}({self.id}):{self.name!r}->({",".join([repr(x) for x in self.targets])})>'
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ class Target(SurrogatePK, Model):
|
|||||||
super(Target, self).__init__(**kwargs)
|
super(Target, self).__init__(**kwargs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s(%d):%r->%r>' % (Target.__name__, self.id, self.routing_key, self.exchange.name)
|
return f'<{Target.__name__}({self.id}):{self.routing_key!r}->{self.exchange.name!r}>'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
from flask_apispec import use_kwargs, marshal_with, doc
|
from flask_apispec import use_kwargs, marshal_with
|
||||||
from flask_jwt_extended import jwt_required
|
from flask_jwt_extended import jwt_required
|
||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ class TargetExchange(SurrogatePK, Model):
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(TargetExchange, self).__init__(**kwargs)
|
super(TargetExchange, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<{TargetExchange.__name__}({self.id}):{self.name!r}>'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ensure_created(name):
|
def ensure_created(name):
|
||||||
if TargetExchange.query.filter_by(name=name).first() is None:
|
if TargetExchange.query.filter_by(name=name).first() is None:
|
||||||
|
|||||||
3
api/webhook/__init__.py
Normal file
3
api/webhook/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"""the webhook endpoint"""
|
||||||
|
|
||||||
|
from . import views
|
||||||
22
api/webhook/views.py
Normal file
22
api/webhook/views.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from flask import Blueprint, jsonify
|
||||||
|
from flask_apispec import use_kwargs
|
||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from api.exceptions import NotFoundException
|
||||||
|
from api.registration.models import Registration
|
||||||
|
from api.utils import docwrap
|
||||||
|
|
||||||
|
blueprint = Blueprint('webhook', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@docwrap('webhook', 'api_key')
|
||||||
|
@blueprint.route('/webhook', methods=['GET'])
|
||||||
|
@use_kwargs({'apikey': fields.String(required=True)}, location='query')
|
||||||
|
def webhook(apikey):
|
||||||
|
reg = Registration.query.filter_by(token=apikey).first()
|
||||||
|
|
||||||
|
if reg is None:
|
||||||
|
raise NotFoundException(Registration.__name__)
|
||||||
|
|
||||||
|
return jsonify({'response': repr(reg)})
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user