fix: remove basic auth from ui and bump version to 3.0.2
Deploy contracts-flask / validate (push) Canceled after 0s

This commit is contained in:
Repinoid
2026-10-31 18:06:31 +03:00
parent 05205b09cc
commit 9c73a730d1
3 changed files with 11 additions and 24 deletions
+3 -22
View File
@@ -1,7 +1,7 @@
"""contracts-flask v2.0 — полный перенос с ВМ на Flask.
Больше никаких прокси на contracts.kube5s.ru — всё локально.
"""
import sys, os, hmac
import sys, os
# site/ в sys.path — импортируем модули напрямую, без префиксов
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# корень репо — для переиспользуемого модуля upload/ (как в drhider)
@@ -9,8 +9,8 @@ _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if _REPO_ROOT not in sys.path:
sys.path.insert(0, _REPO_ROOT)
from flask import Flask, jsonify, request
from config import VERSION, MAX_CONTENT_LENGTH, API_KEY
from flask import Flask
from config import VERSION, MAX_CONTENT_LENGTH
from routes import register_routes
@@ -18,29 +18,10 @@ def create_app():
app = Flask(__name__)
app.config["VERSION"] = VERSION
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH
app.config["API_KEY"] = API_KEY
_init_db()
register_routes(app)
@app.before_request
def authorize_request():
if request.endpoint == "health.health":
return None
key = app.config.get("API_KEY", "")
if not key:
return jsonify(ok=False, error="application API_KEY is not configured"), 503
if "X-API-Key" in request.headers:
supplied = request.headers.get("X-API-Key", "")
else:
authorization = request.authorization
supplied = authorization.password if authorization and authorization.type.lower() == "basic" else ""
if not hmac.compare_digest((supplied or "").encode("utf-8"), key.encode("utf-8")):
return jsonify(ok=False, error="unauthorized"), 401, {
"WWW-Authenticate": 'Basic realm="Contracts", charset="UTF-8"',
}
return None
@app.after_request
def no_cache(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"