From afb98724d3fb30623e3d765ab5376a641a170b83 Mon Sep 17 00:00:00 2001 From: Iain Learmonth Date: Tue, 30 Aug 2022 14:15:06 +0100 Subject: [PATCH] lint --- app/cli/automate.py | 2 +- app/models/tfstate.py | 2 +- app/portal/__init__.py | 4 +++- app/terraform/block/bridge_gitlab.py | 1 - app/terraform/list/gitlab.py | 2 +- app/tfstate.py | 7 ++++--- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/cli/automate.py b/app/cli/automate.py index c1de03b..d0038dc 100644 --- a/app/cli/automate.py +++ b/app/cli/automate.py @@ -107,7 +107,6 @@ def run_job(job_cls: Type[BaseAutomation], *, # to be logged for investigation. Catching more specific exceptions would just mean that # others go unrecorded and are difficult to debug. except Exception as exc: # pylint: disable=broad-except - raise exc trace = TracebackException.from_exception(exc) success = False logs = "\n".join(trace.format()) @@ -125,6 +124,7 @@ def run_job(job_cls: Type[BaseAutomation], *, log.updated = datetime.datetime.utcnow() log.logs = str(logs) db.session.add(log) + db.session.commit() activity = Activity( activity_type="automation", text=(f"[{automation.short_name}] 🚨 Automation failure: It was not possible to handle this failure safely " diff --git a/app/models/tfstate.py b/app/models/tfstate.py index 62dbf9a..0529435 100644 --- a/app/models/tfstate.py +++ b/app/models/tfstate.py @@ -1,7 +1,7 @@ from app.extensions import db -class TerraformState(db.Model): +class TerraformState(db.Model): # type: ignore key = db.Column(db.String, primary_key=True) state = db.Column(db.String) lock = db.Column(db.String) diff --git a/app/portal/__init__.py b/app/portal/__init__.py index 8a6169b..719e36b 100644 --- a/app/portal/__init__.py +++ b/app/portal/__init__.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta, timezone from typing import Optional -from flask import Blueprint, render_template, request +from flask import Blueprint, render_template, request, url_for, redirect from flask.typing import ResponseReturnValue from jinja2.utils import markupsafe from sqlalchemy import desc, or_, func @@ -129,6 +129,8 @@ def portal_home() -> ResponseReturnValue: @portal.route("/search") def search() -> ResponseReturnValue: query = request.args.get("query") + if query is None: + return redirect(url_for("portal.portal_home")) proxies = Proxy.query.filter( or_(func.lower(Proxy.url).contains(query.lower())), Proxy.destroyed.is_(None)).all() origins = Origin.query.filter( diff --git a/app/terraform/block/bridge_gitlab.py b/app/terraform/block/bridge_gitlab.py index 8f2f2c1..b184b4c 100644 --- a/app/terraform/block/bridge_gitlab.py +++ b/app/terraform/block/bridge_gitlab.py @@ -26,4 +26,3 @@ class BlockBridgeGitlabAutomation(BlockBridgeReachabilityAutomation): ) # Decode the base64 first, then decode the UTF-8 string self._lines = contents.decode().decode('utf-8').splitlines() - diff --git a/app/terraform/list/gitlab.py b/app/terraform/list/gitlab.py index 61efd0d..9e797d6 100644 --- a/app/terraform/list/gitlab.py +++ b/app/terraform/list/gitlab.py @@ -52,7 +52,7 @@ class ListGitlabAutomation(ListAutomation): {% endfor %} """ - def __init__(self): + def __init__(self) -> None: super().__init__() if 'GITLAB_URL' in current_app.config: self.template_parameters.append("gitlab_url") diff --git a/app/tfstate.py b/app/tfstate.py index d079450..152e4e1 100644 --- a/app/tfstate.py +++ b/app/tfstate.py @@ -1,6 +1,7 @@ import json from flask import Blueprint, request, Response +from flask.typing import ResponseReturnValue from app.extensions import db from app.models.tfstate import TerraformState @@ -9,7 +10,7 @@ tfstate = Blueprint("tfstate", __name__) @tfstate.route("/", methods=['GET']) -def handle_get(key): +def handle_get(key: str) -> ResponseReturnValue: state = TerraformState.query.filter(TerraformState.key == key).first() if state is None or state.state is None: return "Not Found", 404 @@ -17,7 +18,7 @@ def handle_get(key): @tfstate.route("/", methods=['POST', 'DELETE', 'UNLOCK']) -def handle_update(key): +def handle_update(key: str) -> ResponseReturnValue: state = TerraformState.query.filter(TerraformState.key == key).first() if not state: if request.method in ["DELETE", "UNLOCK"]: @@ -38,7 +39,7 @@ def handle_update(key): @tfstate.route("/", methods=['LOCK']) -def handle_lock(key): +def handle_lock(key: str) -> ResponseReturnValue: state = TerraformState.query.filter(TerraformState.key == key).with_for_update().first() if state is None: state = TerraformState(key=key)