feat(static): create web origins for the static mirrors

This commit is contained in:
Iain Learmonth 2023-05-31 13:59:45 +01:00
parent 5d00dc8fe1
commit 51779b6cc3
5 changed files with 92 additions and 17 deletions

View file

@ -1,6 +1,7 @@
import logging
from typing import Optional, List, Any
import sqlalchemy.exc
from flask import flash, redirect, url_for, render_template, Response, Blueprint, current_app
from flask.typing import ResponseReturnValue
from flask_wtf import FlaskForm
@ -11,7 +12,7 @@ from wtforms.validators import DataRequired
from app.brm.static import create_static_origin
from app.models.base import Group
from app.models.cloud import CloudAccount, CloudProvider
from app.models.mirrors import StaticOrigin
from app.models.mirrors import StaticOrigin, Origin
from app.portal.util import response_404, view_lifecycle
bp = Blueprint("static", __name__)
@ -134,28 +135,28 @@ def static_new(group_id: Optional[int] = None) -> ResponseReturnValue:
@bp.route('/edit/<static_id>', methods=['GET', 'POST'])
def static_edit(static_id: int) -> ResponseReturnValue:
static: Optional[StaticOrigin] = StaticOrigin.query.filter(StaticOrigin.id == static_id).first()
if static is None:
static_origin: Optional[StaticOrigin] = StaticOrigin.query.filter(StaticOrigin.id == static_id).first()
if static_origin is None:
return Response(render_template("error.html.j2",
section="static",
header="404 Origin Not Found",
message="The requested static origin could not be found."),
status=404)
form = StaticOriginForm(description=static.description,
group=static.group_id,
storage_cloud_account=static.storage_cloud_account_id,
source_cloud_account=static.source_cloud_account_id,
source_project=static.source_project,
matrix_homeserver=static.matrix_homeserver,
keanu_convene_path=static.keanu_convene_path,
auto_rotate=static.auto_rotate,
enable_clean_insights=bool(static.clean_insights_backend))
form = StaticOriginForm(description=static_origin.description,
group=static_origin.group_id,
storage_cloud_account=static_origin.storage_cloud_account_id,
source_cloud_account=static_origin.source_cloud_account_id,
source_project=static_origin.source_project,
matrix_homeserver=static_origin.matrix_homeserver,
keanu_convene_path=static_origin.keanu_convene_path,
auto_rotate=static_origin.auto_rotate,
enable_clean_insights=bool(static_origin.clean_insights_backend))
form.group.render_kw = {"disabled": ""}
form.storage_cloud_account.render_kw = {"disabled": ""}
form.source_cloud_account.render_kw = {"disabled": ""}
if form.validate_on_submit():
try:
static.update(
static_origin.update(
form.source_project.data,
form.description.data,
form.auto_rotate.data,
@ -173,9 +174,15 @@ def static_edit(static_id: int) -> ResponseReturnValue:
except exc.SQLAlchemyError as e:
logging.warning(e)
flash("An error occurred saving the changes to the static origin due to a database error.", "danger")
try:
origin = Origin.query.filter_by(domain_name=static_origin.origin_domain_name).one()
proxies = origin.proxies
except sqlalchemy.exc.NoResultFound:
proxies = []
return render_template("static.html.j2",
section="static",
static=static, form=form)
static=static_origin, form=form,
proxies=proxies)
@bp.route("/list")