Allow [storage]anonymous through the validator

And provide a helpful accessor for reading it
This commit is contained in:
Jean-Paul Calderone 2019-07-03 14:30:36 -04:00
parent b50e20b58c
commit 853cf62530
2 changed files with 90 additions and 1 deletions

View File

@ -97,6 +97,7 @@ _client_config = configutil.ValidConfiguration(
"storage": (
"debug_discard",
"enabled",
"anonymous",
"expire.cutoff_date",
"expire.enabled",
"expire.immutable",
@ -619,6 +620,31 @@ def _add_to_announcement(information, announceable_storage_server):
)
def storage_enabled(config):
"""
Is storage enabled according to the given configuration object?
:param _Config config: The configuration to inspect.
:return bool: ``True`` if storage is enabled, ``False`` otherwise.
"""
return config.get_config(b"storage", b"enabled", True, boolean=True)
def anonymous_storage_enabled(config):
"""
Is anonymous access to storage enabled according to the given
configuration object?
:param _Config config: The configuration to inspect.
:return bool: ``True`` if storage is enabled, ``False`` otherwise.
"""
return (
storage_enabled(config) and
config.get_config(b"storage", b"anonymous", True, boolean=True)
)
@implementer(IStatsProducer)
class _Client(node.Node, pollmixin.PollMixin):
@ -828,7 +854,7 @@ class _Client(node.Node, pollmixin.PollMixin):
def init_storage(self, announceable_storage_servers):
# should we run a storage server (and publish it for others to use)?
if not self.config.get_config("storage", "enabled", True, boolean=True):
if not storage_enabled(self.config):
return
if not self._is_tub_listening():
raise ValueError("config error: storage is enabled, but tub "

View File

@ -238,6 +238,69 @@ class Basic(testutil.ReallyEqualMixin, testutil.NonASCIIPathMixin, unittest.Test
c = yield client.create_client(basedir)
self.failUnless(c.get_long_nodeid().startswith("v0-"))
def test_storage_anonymous_enabled_by_default(self):
"""
Anonymous storage access is enabled if storage is enabled and *anonymous*
is not set.
"""
config = client.config_from_string(
b"test_storage_default_anonymous_enabled",
b"tub.port",
BASECONFIG + (
b"[storage]\n"
b"enabled = true\n"
)
)
self.assertTrue(client.anonymous_storage_enabled(config))
def test_storage_anonymous_enabled_explicitly(self):
"""
Anonymous storage access is enabled if storage is enabled and *anonymous*
is set to true.
"""
config = client.config_from_string(
self.id(),
b"tub.port",
BASECONFIG + (
b"[storage]\n"
b"enabled = true\n"
b"anonymous = true\n"
)
)
self.assertTrue(client.anonymous_storage_enabled(config))
def test_storage_anonymous_disabled_explicitly(self):
"""
Anonymous storage access is disabled if storage is enabled and *anonymous*
is set to false.
"""
config = client.config_from_string(
self.id(),
b"tub.port",
BASECONFIG + (
b"[storage]\n"
b"enabled = true\n"
b"anonymous = false\n"
)
)
self.assertFalse(client.anonymous_storage_enabled(config))
def test_storage_anonymous_disabled_by_storage(self):
"""
Anonymous storage access is disabled if storage is disabled and *anonymous*
is set to true.
"""
config = client.config_from_string(
self.id(),
b"tub.port",
BASECONFIG + (
b"[storage]\n"
b"enabled = false\n"
b"anonymous = true\n"
)
)
self.assertFalse(client.anonymous_storage_enabled(config))
@defer.inlineCallbacks
def test_reserved_1(self):
"""