From 180e96b332ce98527ae802977b4c3ddb17a4df12 Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 19 Feb 2020 09:50:36 +0100 Subject: [PATCH] Move internal options to other sections --- radicale/app/__init__.py | 2 +- radicale/config.py | 23 ++++++++++---------- radicale/server.py | 2 +- radicale/storage/multifilesystem/__init__.py | 4 ++-- radicale/tests/test_auth.py | 6 ++--- radicale/tests/test_base.py | 8 +++---- radicale/tests/test_config.py | 8 +++---- radicale/tests/test_rights.py | 6 ++--- radicale/tests/test_server.py | 8 +++---- radicale/tests/test_web.py | 6 ++--- 10 files changed, 36 insertions(+), 37 deletions(-) diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index f8357c8..c6607a2 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -281,7 +281,7 @@ class Application( logger.warning("Access to principal path %r denied by " "rights backend", principal_path) - if self.configuration.get("_internal", "internal_server"): + if self.configuration.get("server", "_internal_server"): # Verify content length content_length = int(environ.get("CONTENT_LENGTH") or 0) if content_length: diff --git a/radicale/config.py b/radicale/config.py index d209467..79a3f69 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -132,7 +132,11 @@ DEFAULT_CONFIG_SCHEMA = OrderedDict([ "value": "", "help": "set CA certificate for validating clients", "aliases": ["--certificate-authority"], - "type": filepath})])), + "type": filepath}), + ("_internal_server", { + "value": "False", + "help": "the internal server is used", + "type": bool})])), ("encoding", OrderedDict([ ("request", { "value": "utf-8", @@ -191,7 +195,11 @@ DEFAULT_CONFIG_SCHEMA = OrderedDict([ ("hook", { "value": "", "help": "command that is run after changes to storage", - "type": str})])), + "type": str}), + ("_filesystem_fsync", { + "value": "True", + "help": "sync all changes to filesystem during requests", + "type": bool})])), ("web", OrderedDict([ ("type", { "value": "internal", @@ -208,16 +216,7 @@ DEFAULT_CONFIG_SCHEMA = OrderedDict([ "help": "mask passwords in logs", "type": bool})])), ("headers", OrderedDict([ - ("_allow_extra", str)])), - ("_internal", OrderedDict([ - ("filesystem_fsync", { - "value": "True", - "help": "sync all changes to filesystem during requests", - "type": bool}), - ("internal_server", { - "value": "False", - "help": "the internal server is used", - "type": bool})]))]) + ("_allow_extra", str)]))]) def parse_compound_paths(*compound_paths): diff --git a/radicale/server.py b/radicale/server.py index 4adbe0c..22ee62f 100644 --- a/radicale/server.py +++ b/radicale/server.py @@ -200,7 +200,7 @@ def serve(configuration, shutdown_socket): logger.info("Starting Radicale") # Copy configuration before modifying configuration = configuration.copy() - configuration.update({"_internal": {"internal_server": "True"}}, "server", + configuration.update({"server": {"_internal_server": "True"}}, "server", privileged=True) use_ssl = configuration.get("server", "ssl") diff --git a/radicale/storage/multifilesystem/__init__.py b/radicale/storage/multifilesystem/__init__.py index ce3169e..b5ac0c5 100644 --- a/radicale/storage/multifilesystem/__init__.py +++ b/radicale/storage/multifilesystem/__init__.py @@ -125,7 +125,7 @@ class Storage( return os.path.join(filesystem_folder, "collection-root") def _fsync(self, fd): - if self.configuration.get("_internal", "filesystem_fsync"): + if self.configuration.get("storage", "_filesystem_fsync"): pathutils.fsync(fd) def _sync_directory(self, path): @@ -134,7 +134,7 @@ class Storage( This only works on POSIX and does nothing on other systems. """ - if not self.configuration.get("_internal", "filesystem_fsync"): + if not self.configuration.get("storage", "_filesystem_fsync"): return if os.name == "posix": try: diff --git a/radicale/tests/test_auth.py b/radicale/tests/test_auth.py index c5b22dd..b83bee1 100644 --- a/radicale/tests/test_auth.py +++ b/radicale/tests/test_auth.py @@ -42,9 +42,9 @@ class TestBaseAuthRequests(BaseTest): self.configuration = config.load() self.colpath = tempfile.mkdtemp() self.configuration.update({ - "storage": {"filesystem_folder": self.colpath}, - # Disable syncing to disk for better performance - "_internal": {"filesystem_fsync": "False"}, + "storage": {"filesystem_folder": self.colpath, + # Disable syncing to disk for better performance + "_filesystem_fsync": "False"}, # Set incorrect authentication delay to a very low value "auth": {"delay": "0.002"}}, "test", privileged=True) diff --git a/radicale/tests/test_base.py b/radicale/tests/test_base.py index d9bd04d..fc1fdf6 100644 --- a/radicale/tests/test_base.py +++ b/radicale/tests/test_base.py @@ -1348,9 +1348,9 @@ collection: .* permissions: RrWw""") self.configuration.update({ "storage": {"type": self.storage_type, - "filesystem_folder": self.colpath}, - # Disable syncing to disk for better performance - "_internal": {"filesystem_fsync": "False"}, + "filesystem_folder": self.colpath, + # Disable syncing to disk for better performance + "_filesystem_fsync": "False"}, "rights": {"file": rights_file_path, "type": "from_file"}}, "test", privileged=True) self.application = Application(self.configuration) @@ -1373,7 +1373,7 @@ class TestMultiFileSystem(BaseFileSystemTest, BaseRequestsMixIn): def test_fsync(self): """Create a directory and file with syncing enabled.""" - self.configuration.update({"_internal": {"filesystem_fsync": "True"}}, + self.configuration.update({"storage": {"_filesystem_fsync": "True"}}, "test", privileged=True) self.application = Application(self.configuration) self.mkcalendar("/calendar.ics/") diff --git a/radicale/tests/test_config.py b/radicale/tests/test_config.py index 54965c2..e9177cb 100644 --- a/radicale/tests/test_config.py +++ b/radicale/tests/test_config.py @@ -131,15 +131,15 @@ class TestConfig: assert "section 'server" in str(e) assert "'x'" in str(e) - def test_internal(self): + def test_privileged(self): configuration = config.load() - configuration.update({"_internal": {"internal_server": "True"}}, + configuration.update({"server": {"_internal_server": "True"}}, "test", privileged=True) with pytest.raises(Exception) as exc_info: configuration.update( - {"_internal": {"internal_server": "True"}}, "test") + {"server": {"_internal_server": "True"}}, "test") e = exc_info.value - assert "Invalid section '_internal'" in str(e) + assert "Invalid option '_internal_server'" in str(e) def test_plugin_schema(self): plugin_schema = {"auth": {"new_option": {"value": "False", diff --git a/radicale/tests/test_rights.py b/radicale/tests/test_rights.py index f0a94cc..ebe821a 100644 --- a/radicale/tests/test_rights.py +++ b/radicale/tests/test_rights.py @@ -35,9 +35,9 @@ class TestBaseRightsRequests(BaseTest): self.configuration = config.load() self.colpath = tempfile.mkdtemp() self.configuration.update({ - "storage": {"filesystem_folder": self.colpath}, - # Disable syncing to disk for better performance - "_internal": {"filesystem_fsync": "False"}}, + "storage": {"filesystem_folder": self.colpath, + # Disable syncing to disk for better performance + "_filesystem_fsync": "False"}}, "test", privileged=True) def teardown(self): diff --git a/radicale/tests/test_server.py b/radicale/tests/test_server.py index 1f91869..ac7f24e 100644 --- a/radicale/tests/test_server.py +++ b/radicale/tests/test_server.py @@ -63,12 +63,12 @@ class TestBaseServerRequests(BaseTest): sock.bind(("127.0.0.1", 0)) self.sockname = sock.getsockname() self.configuration.update({ - "storage": {"filesystem_folder": self.colpath}, + "storage": {"filesystem_folder": self.colpath, + # Disable syncing to disk for better performance + "_filesystem_fsync": "False"}, "server": {"hosts": "[%s]:%d" % self.sockname}, # Enable debugging for new processes - "logging": {"level": "debug"}, - # Disable syncing to disk for better performance - "_internal": {"filesystem_fsync": "False"}}, + "logging": {"level": "debug"}}, "test", privileged=True) self.thread = threading.Thread(target=server.serve, args=( self.configuration, shutdown_socket_out)) diff --git a/radicale/tests/test_web.py b/radicale/tests/test_web.py index a5a56a4..578897a 100644 --- a/radicale/tests/test_web.py +++ b/radicale/tests/test_web.py @@ -33,9 +33,9 @@ class TestBaseWebRequests(BaseTest): self.configuration = config.load() self.colpath = tempfile.mkdtemp() self.configuration.update({ - "storage": {"filesystem_folder": self.colpath}, - # Disable syncing to disk for better performance - "_internal": {"filesystem_fsync": "False"}}, + "storage": {"filesystem_folder": self.colpath, + # Disable syncing to disk for better performance + "_filesystem_fsync": "False"}}, "test", privileged=True) self.application = Application(self.configuration)