mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-18 23:38:18 +00:00
actually provide validating client-config-from-string function
This commit is contained in:
@ -62,9 +62,17 @@ GiB=1024*MiB
|
|||||||
TiB=1024*GiB
|
TiB=1024*GiB
|
||||||
PiB=1024*TiB
|
PiB=1024*TiB
|
||||||
|
|
||||||
def _valid_config():
|
def _is_valid_section(section_name):
|
||||||
cfg = node._common_valid_config()
|
"""
|
||||||
return cfg.update(configutil.ValidConfiguration({
|
Check for valid dynamic configuration section names.
|
||||||
|
|
||||||
|
Currently considers all possible storage server plugin sections valid.
|
||||||
|
"""
|
||||||
|
return section_name.startswith("storageserver.plugins.")
|
||||||
|
|
||||||
|
|
||||||
|
_client_config = configutil.ValidConfiguration(
|
||||||
|
static_valid_sections={
|
||||||
"client": (
|
"client": (
|
||||||
"helper.furl",
|
"helper.furl",
|
||||||
"introducer.furl",
|
"introducer.furl",
|
||||||
@ -117,7 +125,16 @@ def _valid_config():
|
|||||||
"local.directory",
|
"local.directory",
|
||||||
"poll_interval",
|
"poll_interval",
|
||||||
),
|
),
|
||||||
}))
|
},
|
||||||
|
is_valid_section=_is_valid_section,
|
||||||
|
# Anything in a valid section is a valid item, for now.
|
||||||
|
is_valid_item=lambda section, ignored: _is_valid_section(section),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _valid_config():
|
||||||
|
cfg = node._common_valid_config()
|
||||||
|
return cfg.update(_client_config)
|
||||||
|
|
||||||
# this is put into README in new node-directories
|
# this is put into README in new node-directories
|
||||||
CLIENT_README = """
|
CLIENT_README = """
|
||||||
@ -207,6 +224,12 @@ def read_config(basedir, portnumfile, generated_files=[]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
config_from_string = partial(
|
||||||
|
node.config_from_string,
|
||||||
|
_valid_config=_valid_config(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_client(basedir=u".", _client_factory=None):
|
def create_client(basedir=u".", _client_factory=None):
|
||||||
"""
|
"""
|
||||||
Creates a new client instance (a subclass of Node).
|
Creates a new client instance (a subclass of Node).
|
||||||
|
@ -195,14 +195,20 @@ def read_config(basedir, portnumfile, generated_files=[], _valid_config=None):
|
|||||||
return _Config(parser, portnumfile, basedir, config_fname)
|
return _Config(parser, portnumfile, basedir, config_fname)
|
||||||
|
|
||||||
|
|
||||||
def config_from_string(basedir, portnumfile, config_str):
|
def config_from_string(basedir, portnumfile, config_str, _valid_config=None):
|
||||||
"""
|
"""
|
||||||
load configuration from in-memory string
|
load and validate configuration from in-memory string
|
||||||
"""
|
"""
|
||||||
|
if _valid_config is None:
|
||||||
|
_valid_config = _common_valid_config()
|
||||||
|
|
||||||
# load configuration from in-memory string
|
# load configuration from in-memory string
|
||||||
parser = ConfigParser.SafeConfigParser()
|
parser = ConfigParser.SafeConfigParser()
|
||||||
parser.readfp(BytesIO(config_str))
|
parser.readfp(BytesIO(config_str))
|
||||||
return _Config(parser, portnumfile, basedir, '<in-memory>')
|
|
||||||
|
fname = "<in-memory>"
|
||||||
|
configutil.validate_config(fname, parser, _valid_config)
|
||||||
|
return _Config(parser, portnumfile, basedir, fname)
|
||||||
|
|
||||||
|
|
||||||
def get_app_versions():
|
def get_app_versions():
|
||||||
|
Reference in New Issue
Block a user