got httpclient working, spoke heartbeat is working
This commit is contained in:
@ -7,17 +7,13 @@ from flask import request
|
||||
from flask.json import jsonify
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
from capsulflask.db import my_exec_info_message
|
||||
from capsulflask.shared import my_exec_info_message, authorized_as_hub
|
||||
|
||||
bp = Blueprint("spoke", __name__, url_prefix="/spoke")
|
||||
|
||||
def authorized_as_hub(id):
|
||||
auth_header_value = request.headers.get('Authorization').replace("Bearer ", "")
|
||||
return auth_header_value == current_app.config["HUB_TOKEN"]
|
||||
|
||||
@bp.route("/heartbeat", methods=("POST"))
|
||||
@bp.route("/heartbeat", methods=("POST",))
|
||||
def heartbeat():
|
||||
if authorized_as_hub(id):
|
||||
if authorized_as_hub(request.headers):
|
||||
url = f"{current_app.config['HUB_URL']}/hub/heartbeat/{current_app.config['SPOKE_HOST_ID']}"
|
||||
authorization_header = f"Bearer {current_app.config['SPOKE_HOST_TOKEN']}"
|
||||
result = current_app.config['HTTP_CLIENT'].post_json_sync(url, body=None, authorization_header=authorization_header)
|
||||
@ -36,9 +32,9 @@ def heartbeat():
|
||||
current_app.logger.info(f"/hosts/heartbeat returned 401: invalid hub token")
|
||||
return abort(401, "invalid hub token")
|
||||
|
||||
@bp.route("/operation", methods=("POST"))
|
||||
@bp.route("/operation", methods=("POST",))
|
||||
def operation():
|
||||
if authorized_as_hub(id):
|
||||
if authorized_as_hub(request.headers):
|
||||
request_body = request.json()
|
||||
handlers = {
|
||||
"capacity_avaliable": handle_capacity_avaliable,
|
||||
|
Reference in New Issue
Block a user