forked from 3wordchant/capsul-flask
add hub-and-spoke diagrams to readme
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
|
||||
import aiohttp
|
||||
from flask import Blueprint
|
||||
from flask import current_app
|
||||
from flask import request
|
||||
@ -6,17 +7,19 @@ from werkzeug.exceptions import abort
|
||||
|
||||
from capsulflask.db import get_model, my_exec_info_message
|
||||
|
||||
bp = Blueprint("hosts", __name__, url_prefix="/hosts")
|
||||
bp = Blueprint("spoke", __name__, url_prefix="/spoke")
|
||||
|
||||
def authorized_for_host(id):
|
||||
def authorized_as_hub(id):
|
||||
auth_header_value = request.headers.get('Authorization').replace("Bearer ", "")
|
||||
return get_model().authorized_for_host(id, auth_header_value)
|
||||
return auth_header_value == current_app.config["HUB_TOKEN"]
|
||||
|
||||
@bp.route("/heartbeat/<string:id>", methods=("POST"))
|
||||
def heartbeat(id):
|
||||
if authorized_for_host(id):
|
||||
get_model().host_heartbeat(id)
|
||||
@bp.route("/heartbeat", methods=("POST"))
|
||||
def heartbeat():
|
||||
if authorized_as_hub(id):
|
||||
# make request to hub-domain.com/hub/heartbeat/{current_app.config["SPOKE_HOST_ID"]}
|
||||
# succeed or fail based on whether the request succeeds or fails.
|
||||
pass
|
||||
else:
|
||||
current_app.logger.info(f"/hosts/heartbeat/{id} returned 401: invalid token")
|
||||
return abort(401, "invalid host id or token")
|
||||
current_app.logger.info(f"/hosts/heartbeat returned 401: invalid token")
|
||||
return abort(401, "invalid hub token")
|
||||
|
||||
|
Reference in New Issue
Block a user