add hub-and-spoke diagrams to readme

This commit is contained in:
2021-01-02 19:07:43 -06:00
parent b991ec89d2
commit 0a379b74ad
7 changed files with 47 additions and 20 deletions

View File

@ -6,7 +6,7 @@ from werkzeug.exceptions import abort
from capsulflask.db import get_model, my_exec_info_message
bp = Blueprint("hosts", __name__, url_prefix="/hosts")
bp = Blueprint("hub", __name__, url_prefix="/hub")
def authorized_for_host(id):
auth_header_value = request.headers.get('Authorization').replace("Bearer ", "")
@ -17,6 +17,6 @@ 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")
current_app.logger.info(f"/hub/heartbeat/{id} returned 401: invalid token")
return abort(401, "invalid host id or token")

View File

@ -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")

View File

@ -54,7 +54,6 @@ class MockSpoke(SpokeInterface):
def destroy(self, email: str, id: str):
current_app.logger.info(f"mock destroy: {id} for {email}")
class ShellScriptSpoke(SpokeInterface):
def validate_completed_process(self, completedProcess, email=None):
@ -157,17 +156,12 @@ class ShellScriptSpoke(SpokeInterface):
{completedProcess.stderr}
""")
def destroy(self, email: str, id: str):
def destroy(self, email: str, id: str) -> str:
validate_capsul_id(id)
completedProcess = run([join(current_app.root_path, 'shell_scripts/destroy.sh'), id], capture_output=True)
self.validate_completed_process(completedProcess, email)
lines = completedProcess.stdout.splitlines()
status = lines[len(lines)-1].decode("utf-8")
return status
if not status == "success":
raise ValueError(f"""failed to destroy vm "{id}" for {email}:
stdout:
{completedProcess.stdout}
stderr:
{completedProcess.stderr}
""")