mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-19 00:06:57 +00:00
_load_grid_manager_certificates -> method
This commit is contained in:
parent
42b7d3974f
commit
da0fe23082
@ -576,34 +576,6 @@ def create_storage_farm_broker(config, default_connection_handlers, foolscap_con
|
||||
return sb
|
||||
|
||||
|
||||
def _load_grid_manager_certificates(config):
|
||||
"""
|
||||
Load all Grid Manager certificates in the config in a list. An
|
||||
empty list is returned if there are none.
|
||||
"""
|
||||
grid_manager_certificates = []
|
||||
|
||||
cert_fnames = list(config.enumerate_section("grid_manager_certificates").values())
|
||||
for fname in cert_fnames:
|
||||
fname = config.get_config_path(fname.decode('utf8'))
|
||||
if not os.path.exists(fname):
|
||||
raise ValueError(
|
||||
"Grid Manager certificate file '{}' doesn't exist".format(
|
||||
fname
|
||||
)
|
||||
)
|
||||
with open(fname, 'r') as f:
|
||||
cert = json.load(f)
|
||||
if set(cert.keys()) != {"certificate", "signature"}:
|
||||
raise ValueError(
|
||||
"Unknown key in Grid Manager certificate '{}'".format(
|
||||
fname
|
||||
)
|
||||
)
|
||||
grid_manager_certificates.append(cert)
|
||||
return grid_manager_certificates
|
||||
|
||||
|
||||
def _register_reference(key, config, tub, referenceable):
|
||||
"""
|
||||
Register a referenceable in a tub with a stable fURL.
|
||||
@ -936,7 +908,7 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
announcement.update(plugins_announcement)
|
||||
|
||||
if self.config.get_config("storage", "grid_management", default=False, boolean=True):
|
||||
grid_manager_certificates = _load_grid_manager_certificates(self.config)
|
||||
grid_manager_certificates = self.config.get_grid_manager_certificates()
|
||||
announcement[u"grid-manager-certificates"] = grid_manager_certificates
|
||||
|
||||
# XXX we should probably verify that the certificates are
|
||||
|
@ -464,6 +464,12 @@ class _Config(object):
|
||||
"""
|
||||
returns an absolute path inside the 'private' directory with any
|
||||
extra args join()-ed
|
||||
|
||||
This exists for historical reasons. New code should ideally
|
||||
not call this because it makes it harder for e.g. a SQL-based
|
||||
_Config object to exist. Code that needs to call this method
|
||||
should probably be a _Config method itself. See
|
||||
e.g. get_grid_manager_certificates()
|
||||
"""
|
||||
return os.path.join(self._basedir, "private", *args)
|
||||
|
||||
@ -471,6 +477,12 @@ class _Config(object):
|
||||
"""
|
||||
returns an absolute path inside the config directory with any
|
||||
extra args join()-ed
|
||||
|
||||
This exists for historical reasons. New code should ideally
|
||||
not call this because it makes it harder for e.g. a SQL-based
|
||||
_Config object to exist. Code that needs to call this method
|
||||
should probably be a _Config method itself. See
|
||||
e.g. get_grid_manager_certificates()
|
||||
"""
|
||||
# note: we re-expand here (_basedir already went through this
|
||||
# expanduser function) in case the path we're being asked for
|
||||
@ -479,6 +491,35 @@ class _Config(object):
|
||||
os.path.join(self._basedir, *args)
|
||||
)
|
||||
|
||||
def get_grid_manager_certificates(self):
|
||||
"""
|
||||
Load all Grid Manager certificates in the config.
|
||||
|
||||
:returns: A list of all certificates. An empty list is
|
||||
returned if there are none.
|
||||
"""
|
||||
grid_manager_certificates = []
|
||||
|
||||
cert_fnames = list(self.enumerate_section("grid_manager_certificates").values())
|
||||
for fname in cert_fnames:
|
||||
fname = self.get_config_path(fname.decode('utf8'))
|
||||
if not os.path.exists(fname):
|
||||
raise ValueError(
|
||||
"Grid Manager certificate file '{}' doesn't exist".format(
|
||||
fname
|
||||
)
|
||||
)
|
||||
with open(fname, 'r') as f:
|
||||
cert = json.load(f)
|
||||
if set(cert.keys()) != {"certificate", "signature"}:
|
||||
raise ValueError(
|
||||
"Unknown key in Grid Manager certificate '{}'".format(
|
||||
fname
|
||||
)
|
||||
)
|
||||
grid_manager_certificates.append(cert)
|
||||
return grid_manager_certificates
|
||||
|
||||
|
||||
def create_tub_options(config):
|
||||
"""
|
||||
|
@ -7,9 +7,6 @@ from twisted.python.filepath import (
|
||||
FilePath,
|
||||
)
|
||||
|
||||
from allmydata.client import (
|
||||
_load_grid_manager_certificates,
|
||||
)
|
||||
from allmydata.node import (
|
||||
config_from_string,
|
||||
)
|
||||
@ -60,7 +57,7 @@ class GridManagerUtilities(SyncTestCase):
|
||||
{"fluffy": "pub-v0-vqimc4s5eflwajttsofisp5st566dbq36xnpp4siz57ufdavpvlq"},
|
||||
config.enumerate_section("grid_managers")
|
||||
)
|
||||
certs = _load_grid_manager_certificates(config)
|
||||
certs = config.get_grid_manager_certificates()
|
||||
self.assertEqual([fake_cert], certs)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user