Allow additional config options for external plugins

This commit is contained in:
Unrud 2017-06-21 09:48:57 +02:00
parent 31377bad40
commit 276de4fd3a
6 changed files with 28 additions and 4 deletions

View File

@ -58,6 +58,8 @@ def run():
kwargs["dest"] = "{0}_{1}".format(section, option) kwargs["dest"] = "{0}_{1}".format(section, option)
groups[group].append(kwargs["dest"]) groups[group].append(kwargs["dest"])
del kwargs["value"] del kwargs["value"]
if "internal" in kwargs:
del kwargs["internal"]
if kwargs["type"] == bool: if kwargs["type"] == bool:
del kwargs["type"] del kwargs["type"]

View File

@ -60,6 +60,9 @@ import hmac
import os import os
from importlib import import_module from importlib import import_module
INTERNAL_TYPES = ("None", "none", "remote_user", "http_x_remote_user",
"htpasswd")
def load(configuration, logger): def load(configuration, logger):
"""Load the authentication manager chosen in configuration.""" """Load the authentication manager chosen in configuration."""

View File

@ -28,6 +28,8 @@ import os
from collections import OrderedDict from collections import OrderedDict
from configparser import RawConfigParser as ConfigParser from configparser import RawConfigParser as ConfigParser
from . import auth, rights, storage, web
def positive_int(value): def positive_int(value):
value = int(value) value = int(value)
@ -128,7 +130,8 @@ INITIAL_CONFIG = OrderedDict([
("type", { ("type", {
"value": "none", "value": "none",
"help": "authentication method", "help": "authentication method",
"type": str}), "type": str,
"internal": auth.INTERNAL_TYPES}),
("htpasswd_filename", { ("htpasswd_filename", {
"value": "/etc/radicale/users", "value": "/etc/radicale/users",
"help": "htpasswd filename", "help": "htpasswd filename",
@ -145,7 +148,8 @@ INITIAL_CONFIG = OrderedDict([
("type", { ("type", {
"value": "owner_only", "value": "owner_only",
"help": "rights backend", "help": "rights backend",
"type": str}), "type": str,
"internal": rights.INTERNAL_TYPES}),
("file", { ("file", {
"value": "/etc/radicale/rights", "value": "/etc/radicale/rights",
"help": "file for rights management from_file", "help": "file for rights management from_file",
@ -154,7 +158,8 @@ INITIAL_CONFIG = OrderedDict([
("type", { ("type", {
"value": "multifilesystem", "value": "multifilesystem",
"help": "storage backend", "help": "storage backend",
"type": str}), "type": str,
"internal": storage.INTERNAL_TYPES}),
("filesystem_folder", { ("filesystem_folder", {
"value": os.path.expanduser( "value": os.path.expanduser(
"/var/lib/radicale/collections"), "/var/lib/radicale/collections"),
@ -184,7 +189,8 @@ INITIAL_CONFIG = OrderedDict([
("type", { ("type", {
"value": "internal", "value": "internal",
"help": "web interface backend", "help": "web interface backend",
"type": str})])), "type": str,
"internal": web.INTERNAL_TYPES})])),
("logging", OrderedDict([ ("logging", OrderedDict([
("config", { ("config", {
"value": "", "value": "",
@ -229,8 +235,14 @@ def load(paths=(), extra_config=None, ignore_missing_paths=True):
continue continue
if section not in INITIAL_CONFIG: if section not in INITIAL_CONFIG:
raise RuntimeError("Invalid section %r in config" % section) 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]: for option in config[section]:
if option not in INITIAL_CONFIG[section]: if option not in INITIAL_CONFIG[section]:
if allow_extra_options:
continue
raise RuntimeError("Invalid option %r in section %r in " raise RuntimeError("Invalid option %r in section %r in "
"config" % (option, section)) "config" % (option, section))
type_ = INITIAL_CONFIG[section][option]["type"] type_ = INITIAL_CONFIG[section][option]["type"]

View File

@ -45,6 +45,9 @@ from importlib import import_module
from . import storage from . import storage
INTERNAL_TYPES = ("None", "none", "authenticated", "owner_write", "owner_only",
"from_file")
def load(configuration, logger): def load(configuration, logger):
"""Load the rights manager chosen in configuration.""" """Load the rights manager chosen in configuration."""

View File

@ -88,6 +88,8 @@ if os.name == "nt":
elif os.name == "posix": elif os.name == "posix":
import fcntl import fcntl
INTERNAL_TYPES = ("multifilesystem",)
def load(configuration, logger): def load(configuration, logger):
"""Load the storage manager chosen in configuration.""" """Load the storage manager chosen in configuration."""

View File

@ -44,6 +44,8 @@ MIMETYPES = {
".xml": "text/xml"} ".xml": "text/xml"}
FALLBACK_MIMETYPE = "application/octet-stream" FALLBACK_MIMETYPE = "application/octet-stream"
INTERNAL_TYPES = ("None", "none", "internal")
def load(configuration, logger): def load(configuration, logger):
"""Load the web module chosen in configuration.""" """Load the web module chosen in configuration."""