From 260733a13a0ad891e1b10836399dd02af7335fe0 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 6 Jun 2017 01:05:08 +0200 Subject: Add optional external configuration to plugins. - Adds an optional 'conriguration' option similar to the one in [mta] which plugins can use to load their specific configs from. --- src/mailman/config/schema.cfg | 8 ++++++++ src/mailman/rest/docs/plugins.rst | 1 + src/mailman/rest/plugins.py | 3 ++- src/mailman/rest/tests/test_plugins.py | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index 0e7936943..cae95a07f 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -91,6 +91,14 @@ class: # Whether to enable this plugin or not. enable: no +# Additional config for this plugin. The path can be either a file system path +# or a Python import path. If the value starts with python: then it is +# a Python import path, otherwise it is a file system path. File system paths +# must be absolute since no guarantees are made about the current working +# directory. Python paths should not include the trailing .cfg, which the file +# must end with. +configuration: + [shell] # `mailman shell` (also `withlist`) gives you an interactive prompt that you diff --git a/src/mailman/rest/docs/plugins.rst b/src/mailman/rest/docs/plugins.rst index 787726e55..737a911c0 100644 --- a/src/mailman/rest/docs/plugins.rst +++ b/src/mailman/rest/docs/plugins.rst @@ -8,6 +8,7 @@ Plugins can supply REST routes. >>> dump_json('http://localhost:9001/3.1/plugins') entry 0: class: mailman.testing.plugin.ExamplePlugin + configuration: enable: True http_etag: "..." name: example diff --git a/src/mailman/rest/plugins.py b/src/mailman/rest/plugins.py index ac8fc0ace..2209e634e 100644 --- a/src/mailman/rest/plugins.py +++ b/src/mailman/rest/plugins.py @@ -33,7 +33,8 @@ class AllPlugins(CollectionMixin): 'name': plugin_config.name.split('.')[-1], 'class': plugin_config['class'], 'enable': as_boolean(plugin_config['enable']), - 'path': plugin_config['path'] + 'path': plugin_config['path'], + 'configuration': plugin_config['configuration'] } return resource diff --git a/src/mailman/rest/tests/test_plugins.py b/src/mailman/rest/tests/test_plugins.py index f6d7afb76..9c12e1160 100644 --- a/src/mailman/rest/tests/test_plugins.py +++ b/src/mailman/rest/tests/test_plugins.py @@ -41,6 +41,7 @@ class TestAPI31Plugins(unittest.TestCase): self.assertEqual(plugin_conf['class'], 'mailman.testing.plugin.ExamplePlugin') self.assertEqual(plugin_conf['path'], '') + self.assertEqual(plugin_conf['configuration'], '') def test_non_existent_plugin(self): with self.assertRaises(HTTPError) as cm: -- cgit v1.2.3-70-g09d2