From 276de4fd3a61f94f0faea8ccce3028fa5a05f5f5 Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 21 Jun 2017 09:48:57 +0200 Subject: [PATCH] Allow additional config options for external plugins --- radicale/__main__.py | 2 ++ radicale/auth.py | 3 +++ radicale/config.py | 20 ++++++++++++++++---- radicale/rights.py | 3 +++ radicale/storage.py | 2 ++ radicale/web.py | 2 ++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 70e1945..cc9cc49 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -58,6 +58,8 @@ def run(): kwargs["dest"] = "{0}_{1}".format(section, option) groups[group].append(kwargs["dest"]) del kwargs["value"] + if "internal" in kwargs: + del kwargs["internal"] if kwargs["type"] == bool: del kwargs["type"] diff --git a/radicale/auth.py b/radicale/auth.py index 29124c5..40bec60 100644 --- a/radicale/auth.py +++ b/radicale/auth.py @@ -60,6 +60,9 @@ import hmac import os from importlib import import_module +INTERNAL_TYPES = ("None", "none", "remote_user", "http_x_remote_user", + "htpasswd") + def load(configuration, logger): """Load the authentication manager chosen in configuration.""" diff --git a/radicale/config.py b/radicale/config.py index 5c55ca0..7a6fa6b 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -28,6 +28,8 @@ import os from collections import OrderedDict from configparser import RawConfigParser as ConfigParser +from . import auth, rights, storage, web + def positive_int(value): value = int(value) @@ -128,7 +130,8 @@ INITIAL_CONFIG = OrderedDict([ ("type", { "value": "none", "help": "authentication method", - "type": str}), + "type": str, + "internal": auth.INTERNAL_TYPES}), ("htpasswd_filename", { "value": "/etc/radicale/users", "help": "htpasswd filename", @@ -145,7 +148,8 @@ INITIAL_CONFIG = OrderedDict([ ("type", { "value": "owner_only", "help": "rights backend", - "type": str}), + "type": str, + "internal": rights.INTERNAL_TYPES}), ("file", { "value": "/etc/radicale/rights", "help": "file for rights management from_file", @@ -154,7 +158,8 @@ INITIAL_CONFIG = OrderedDict([ ("type", { "value": "multifilesystem", "help": "storage backend", - "type": str}), + "type": str, + "internal": storage.INTERNAL_TYPES}), ("filesystem_folder", { "value": os.path.expanduser( "/var/lib/radicale/collections"), @@ -184,7 +189,8 @@ INITIAL_CONFIG = OrderedDict([ ("type", { "value": "internal", "help": "web interface backend", - "type": str})])), + "type": str, + "internal": web.INTERNAL_TYPES})])), ("logging", OrderedDict([ ("config", { "value": "", @@ -229,8 +235,14 @@ def load(paths=(), extra_config=None, ignore_missing_paths=True): continue if section not in INITIAL_CONFIG: raise RuntimeError("Invalid section %r in config" % section) + allow_extra_options = ("type" in INITIAL_CONFIG[section] and + config.get(section, "type") not in + INITIAL_CONFIG[section]["type"].get("internal", + ())) for option in config[section]: if option not in INITIAL_CONFIG[section]: + if allow_extra_options: + continue raise RuntimeError("Invalid option %r in section %r in " "config" % (option, section)) type_ = INITIAL_CONFIG[section][option]["type"] diff --git a/radicale/rights.py b/radicale/rights.py index dcbf0e3..76f4ad3 100644 --- a/radicale/rights.py +++ b/radicale/rights.py @@ -45,6 +45,9 @@ from importlib import import_module from . import storage +INTERNAL_TYPES = ("None", "none", "authenticated", "owner_write", "owner_only", + "from_file") + def load(configuration, logger): """Load the rights manager chosen in configuration.""" diff --git a/radicale/storage.py b/radicale/storage.py index 815d2c3..2909c68 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -88,6 +88,8 @@ if os.name == "nt": elif os.name == "posix": import fcntl +INTERNAL_TYPES = ("multifilesystem",) + def load(configuration, logger): """Load the storage manager chosen in configuration.""" diff --git a/radicale/web.py b/radicale/web.py index d3b96c2..be6ff80 100644 --- a/radicale/web.py +++ b/radicale/web.py @@ -44,6 +44,8 @@ MIMETYPES = { ".xml": "text/xml"} FALLBACK_MIMETYPE = "application/octet-stream" +INTERNAL_TYPES = ("None", "none", "internal") + def load(configuration, logger): """Load the web module chosen in configuration."""