feat: allow disabling extensions at installation level

This commit is contained in:
Eneko Illarramendi 2020-04-21 16:50:40 +02:00
parent f12f52db2d
commit e1c5e970c4
3 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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)