starting work on hub mode and spoke mode -- implemented hub model

This commit is contained in:
2021-01-02 17:10:01 -06:00
parent d8d6124005
commit c59dc21ba6
8 changed files with 563 additions and 26 deletions

22
capsulflask/hub_api.py Normal file
View File

@ -0,0 +1,22 @@
from flask import Blueprint
from flask import current_app
from flask import request
from werkzeug.exceptions import abort
from capsulflask.db import get_model, my_exec_info_message
bp = Blueprint("hosts", __name__, url_prefix="/hosts")
def authorized_for_host(id):
auth_header_value = request.headers.get('Authorization').replace("Bearer ", "")
return get_model().authorized_for_host(id, auth_header_value)
@bp.route("/heartbeat/<string:id>", methods=("POST"))
def heartbeat(id):
if authorized_for_host(id):
get_model().host_heartbeat(id)
else:
current_app.logger.info(f"/hosts/heartbeat/{id} returned 401: invalid token")
return abort(401, "invalid host id or token")