lint
This commit is contained in:
parent
f81ff2e1de
commit
afb98724d3
6 changed files with 10 additions and 8 deletions
|
@ -107,7 +107,6 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
||||||
# to be logged for investigation. Catching more specific exceptions would just mean that
|
# to be logged for investigation. Catching more specific exceptions would just mean that
|
||||||
# others go unrecorded and are difficult to debug.
|
# others go unrecorded and are difficult to debug.
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
raise exc
|
|
||||||
trace = TracebackException.from_exception(exc)
|
trace = TracebackException.from_exception(exc)
|
||||||
success = False
|
success = False
|
||||||
logs = "\n".join(trace.format())
|
logs = "\n".join(trace.format())
|
||||||
|
@ -125,6 +124,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
||||||
log.updated = datetime.datetime.utcnow()
|
log.updated = datetime.datetime.utcnow()
|
||||||
log.logs = str(logs)
|
log.logs = str(logs)
|
||||||
db.session.add(log)
|
db.session.add(log)
|
||||||
|
db.session.commit()
|
||||||
activity = Activity(
|
activity = Activity(
|
||||||
activity_type="automation",
|
activity_type="automation",
|
||||||
text=(f"[{automation.short_name}] 🚨 Automation failure: It was not possible to handle this failure safely "
|
text=(f"[{automation.short_name}] 🚨 Automation failure: It was not possible to handle this failure safely "
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
|
||||||
|
|
||||||
class TerraformState(db.Model):
|
class TerraformState(db.Model): # type: ignore
|
||||||
key = db.Column(db.String, primary_key=True)
|
key = db.Column(db.String, primary_key=True)
|
||||||
state = db.Column(db.String)
|
state = db.Column(db.String)
|
||||||
lock = db.Column(db.String)
|
lock = db.Column(db.String)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Optional
|
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 flask.typing import ResponseReturnValue
|
||||||
from jinja2.utils import markupsafe
|
from jinja2.utils import markupsafe
|
||||||
from sqlalchemy import desc, or_, func
|
from sqlalchemy import desc, or_, func
|
||||||
|
@ -129,6 +129,8 @@ def portal_home() -> ResponseReturnValue:
|
||||||
@portal.route("/search")
|
@portal.route("/search")
|
||||||
def search() -> ResponseReturnValue:
|
def search() -> ResponseReturnValue:
|
||||||
query = request.args.get("query")
|
query = request.args.get("query")
|
||||||
|
if query is None:
|
||||||
|
return redirect(url_for("portal.portal_home"))
|
||||||
proxies = Proxy.query.filter(
|
proxies = Proxy.query.filter(
|
||||||
or_(func.lower(Proxy.url).contains(query.lower())), Proxy.destroyed.is_(None)).all()
|
or_(func.lower(Proxy.url).contains(query.lower())), Proxy.destroyed.is_(None)).all()
|
||||||
origins = Origin.query.filter(
|
origins = Origin.query.filter(
|
||||||
|
|
|
@ -26,4 +26,3 @@ class BlockBridgeGitlabAutomation(BlockBridgeReachabilityAutomation):
|
||||||
)
|
)
|
||||||
# Decode the base64 first, then decode the UTF-8 string
|
# Decode the base64 first, then decode the UTF-8 string
|
||||||
self._lines = contents.decode().decode('utf-8').splitlines()
|
self._lines = contents.decode().decode('utf-8').splitlines()
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ListGitlabAutomation(ListAutomation):
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if 'GITLAB_URL' in current_app.config:
|
if 'GITLAB_URL' in current_app.config:
|
||||||
self.template_parameters.append("gitlab_url")
|
self.template_parameters.append("gitlab_url")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from flask import Blueprint, request, Response
|
from flask import Blueprint, request, Response
|
||||||
|
from flask.typing import ResponseReturnValue
|
||||||
|
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models.tfstate import TerraformState
|
from app.models.tfstate import TerraformState
|
||||||
|
@ -9,7 +10,7 @@ tfstate = Blueprint("tfstate", __name__)
|
||||||
|
|
||||||
|
|
||||||
@tfstate.route("/<key>", methods=['GET'])
|
@tfstate.route("/<key>", methods=['GET'])
|
||||||
def handle_get(key):
|
def handle_get(key: str) -> ResponseReturnValue:
|
||||||
state = TerraformState.query.filter(TerraformState.key == key).first()
|
state = TerraformState.query.filter(TerraformState.key == key).first()
|
||||||
if state is None or state.state is None:
|
if state is None or state.state is None:
|
||||||
return "Not Found", 404
|
return "Not Found", 404
|
||||||
|
@ -17,7 +18,7 @@ def handle_get(key):
|
||||||
|
|
||||||
|
|
||||||
@tfstate.route("/<key>", methods=['POST', 'DELETE', 'UNLOCK'])
|
@tfstate.route("/<key>", methods=['POST', 'DELETE', 'UNLOCK'])
|
||||||
def handle_update(key):
|
def handle_update(key: str) -> ResponseReturnValue:
|
||||||
state = TerraformState.query.filter(TerraformState.key == key).first()
|
state = TerraformState.query.filter(TerraformState.key == key).first()
|
||||||
if not state:
|
if not state:
|
||||||
if request.method in ["DELETE", "UNLOCK"]:
|
if request.method in ["DELETE", "UNLOCK"]:
|
||||||
|
@ -38,7 +39,7 @@ def handle_update(key):
|
||||||
|
|
||||||
|
|
||||||
@tfstate.route("/<key>", methods=['LOCK'])
|
@tfstate.route("/<key>", methods=['LOCK'])
|
||||||
def handle_lock(key):
|
def handle_lock(key: str) -> ResponseReturnValue:
|
||||||
state = TerraformState.query.filter(TerraformState.key == key).with_for_update().first()
|
state = TerraformState.query.filter(TerraformState.key == key).with_for_update().first()
|
||||||
if state is None:
|
if state is None:
|
||||||
state = TerraformState(key=key)
|
state = TerraformState(key=key)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue