From e1c5e970c461707e5f40769af556e4928a40a930 Mon Sep 17 00:00:00 2001 From: Eneko Illarramendi Date: Tue, 21 Apr 2020 16:50:40 +0200 Subject: [PATCH] feat: allow disabling extensions at installation level --- .env.example | 1 + lnbits/__init__.py | 4 +++- lnbits/helpers.py | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index e7576471..5669286b 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,7 @@ FLASK_ENV=development LNBITS_SITE_TITLE=LNbits LNBITS_DEFAULT_WALLET_NAME="LNbits wallet" LNBITS_DATA_FOLDER="/your_custom_data_folder" +LNBITS_DISABLED_EXTENSIONS="amilk,events" LNBITS_SERVICE_FEE="0.0" LNBITS_WITH_ONION=0 diff --git a/lnbits/__init__.py b/lnbits/__init__.py index da8ef749..a2e83a79 100644 --- a/lnbits/__init__.py +++ b/lnbits/__init__.py @@ -11,9 +11,11 @@ from .core import core_app, migrations as core_migrations from .helpers import ExtensionManager +disabled_extensions = getenv("LNBITS_DISABLED_EXTENSIONS", "").split(",") + app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1) -valid_extensions = [ext for ext in ExtensionManager().extensions if ext.is_valid] +valid_extensions = [ext for ext in ExtensionManager(disabled=disabled_extensions).extensions if ext.is_valid] # optimization & security diff --git a/lnbits/helpers.py b/lnbits/helpers.py index 1242115f..9e7a7670 100644 --- a/lnbits/helpers.py +++ b/lnbits/helpers.py @@ -17,14 +17,15 @@ class Extension(NamedTuple): class ExtensionManager: - def __init__(self): + def __init__(self, *, disabled: list = []): + self._disabled = disabled self._extension_folders: List[str] = [x[1] for x in os.walk(os.path.join(LNBITS_PATH, "extensions"))][0] @property def extensions(self) -> List[Extension]: output = [] - for extension in self._extension_folders: + for extension in [ext for ext in self._extension_folders if ext not in self._disabled]: try: with open(os.path.join(LNBITS_PATH, "extensions", extension, "config.json")) as json_file: config = json.load(json_file)