From 882d0bff847ab30e25d4da2b06d745b49bcad10d Mon Sep 17 00:00:00 2001 From: psrok1 Date: Thu, 12 Dec 2024 16:17:50 +0100 Subject: [PATCH] Feature: brownout deprecated API features via enable_brownout flag --- mwdb/core/config.py | 1 + mwdb/core/deprecated.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/mwdb/core/config.py b/mwdb/core/config.py index 385cacc69..f58597ae2 100644 --- a/mwdb/core/config.py +++ b/mwdb/core/config.py @@ -136,6 +136,7 @@ class MWDBConfig(Config): log_only_slow_sql = key(cast=intbool, required=False, default=False) use_x_forwarded_for = key(cast=intbool, required=False, default=False) enable_debug_log = key(cast=intbool, required=False, default=False) + enable_brownout = key(cast=intbool, required=False, default=False) @section("karton") diff --git a/mwdb/core/deprecated.py b/mwdb/core/deprecated.py index d3615c698..d6e8542b7 100644 --- a/mwdb/core/deprecated.py +++ b/mwdb/core/deprecated.py @@ -6,7 +6,9 @@ from typing import Optional from flask import g, request +from werkzeug.exceptions import BadRequest +from mwdb.core.config import app_config from mwdb.core.log import getLogger from mwdb.core.metrics import metric_deprecated_usage @@ -60,6 +62,14 @@ def uses_deprecated_api( f"Used deprecated feature: {feature}" + (f" ({method} {endpoint})" if endpoint is not None else "") ) + if app_config.mwdb.enable_brownout: + if feature == DeprecatedFeature.legacy_api_key_v2: + # This feature won't be removed in v3 + return + raise BadRequest( + f"Brownout: {feature} API feature is deprecated and currently disabled. " + f"Please upgrade your MWDB API client." + ) def deprecated_endpoint(feature: DeprecatedFeature):