From 724acede4d5ec9116e7b99bf01eb21f60d09e68e Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 19 Aug 2019 11:20:43 -0400 Subject: [PATCH 1/2] news fragment --- newsfragments/3242.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3242.minor diff --git a/newsfragments/3242.minor b/newsfragments/3242.minor new file mode 100644 index 000000000..e69de29bb From a47463e0325966c8c008b04d5e0624a2c1f3a384 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 19 Aug 2019 11:21:03 -0400 Subject: [PATCH 2/2] Pass _Config instead of a smaller dict to get_client_resource --- src/allmydata/client.py | 4 +++- src/allmydata/interfaces.py | 4 ++-- src/allmydata/node.py | 9 +++++++-- src/allmydata/storage_client.py | 10 ++++++++-- src/allmydata/test/storage_plugin.py | 11 +++++++++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 1001b10c8..7739ea42c 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -895,7 +895,9 @@ class _Client(node.Node, pollmixin.PollMixin): :return dict[bytes, IResource provider]: The implementations. """ - return self.storage_broker.get_client_storage_plugin_web_resources() + return self.storage_broker.get_client_storage_plugin_web_resources( + self.config, + ) def _enable_storage_servers(self, announceable_storage_servers): """ diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 012eb53e2..35a88fe08 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -3122,8 +3122,8 @@ class IFoolscapStoragePlugin(IPlugin): Get an ``IResource`` that can be published in the Tahoe-LAFS web interface to expose information related to this plugin. - :param dict configuration: Any configuration given in the section for - this plugin in the node's configuration file. + :param allmydata.node._Config configuration: A representation of the + configuration for the node into which this plugin has been loaded. :rtype: ``IResource`` """ diff --git a/src/allmydata/node.py b/src/allmydata/node.py index a480d5926..6b3911d95 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -292,8 +292,13 @@ class _Config(object): "Unable to write config file '{}'".format(fn), ) - def items(self, section): - return self.config.items(section) + def items(self, section, default=_None): + try: + return self.config.items(section) + except ConfigParser.NoSectionError: + if default is _None: + raise + return default def get_config(self, section, option, default=_None, boolean=False): try: diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index ef148a4c1..84d96cec0 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -197,10 +197,16 @@ class StorageFarmBroker(service.MultiService): storage_server.setServiceParent(self) storage_server.start_connecting(self._trigger_connections) - def get_client_storage_plugin_web_resources(self): + def get_client_storage_plugin_web_resources(self, node_config): """ Get all of the client-side ``IResource`` implementations provided by enabled storage plugins. + + :param allmydata.node._Config node_config: The complete node + configuration for the node from which these web resources will be + served. + + :return dict[unicode, IResource]: Resources for all of the plugins. """ plugins = { plugin.name: plugin @@ -208,7 +214,7 @@ class StorageFarmBroker(service.MultiService): in getPlugins(IFoolscapStoragePlugin) } return { - name: plugins[name].get_client_resource(config) + name: plugins[name].get_client_resource(node_config) for (name, config) in self.storage_client_config.storage_plugins.items() } diff --git a/src/allmydata/test/storage_plugin.py b/src/allmydata/test/storage_plugin.py index ef10ebb30..d78a4d9ec 100644 --- a/src/allmydata/test/storage_plugin.py +++ b/src/allmydata/test/storage_plugin.py @@ -48,6 +48,10 @@ class RIDummy(RemoteInterface): class DummyStorage(object): name = attr.ib() + @property + def _client_section_name(self): + return u"storageclient.plugins.{}".format(self.name) + def get_storage_server(self, configuration, get_anonymous_storage_server): if u"invalid" in configuration: raise Exception("The plugin is unhappy.") @@ -69,8 +73,11 @@ class DummyStorage(object): :return: A static data resource that produces the given configuration when rendered, as an aid to testing. """ - return Data(dumps(configuration), b"text/json") - + items = configuration.items(self._client_section_name, []) + return Data( + dumps(dict(items)), + b"text/json", + ) @implementer(RIDummy)