1 # Copyright (C) 2010-2019 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """REST for plugins, dynamically proxies requests to plugin's rest_object."""
20 from lazr
.config
import as_boolean
21 from mailman
.config
import config
22 from mailman
.rest
.helpers
import CollectionMixin
, NotFound
, etag
, okay
23 from operator
import itemgetter
24 from public
import public
28 class AllPlugins(CollectionMixin
):
29 """Read-only list of all plugin configs."""
31 def _resource_as_dict(self
, plugin_config
):
32 """See `CollectionMixin`."""
33 name
, plugin_section
= plugin_config
36 'class': plugin_section
['class'],
37 'enabled': as_boolean(plugin_section
['enabled']),
39 # Add the path to the plugin's own configuration file, if one was
41 plugin_config
= plugin_section
['configuration'].strip()
42 if len(plugin_config
) > 0:
43 resource
['configuration'] = plugin_config
46 def _get_collection(self
, request
):
47 """See `CollectionMixin`."""
48 # plugin_configs returns a 2-tuple of (name, section), so sort
49 # alphabetically on the plugin name.
50 return sorted(config
.plugin_configs
, key
=itemgetter(0))
52 def on_get(self
, request
, response
):
54 resource
= self
._make
_collection
(request
)
55 okay(response
, etag(resource
))
60 """REST proxy to the plugin's rest_object."""
62 def __init__(self
, plugin_name
):
64 if plugin_name
in config
.plugins
:
65 plugin
= config
.plugins
[plugin_name
]
66 self
._resource
= plugin
.resource
67 # If the plugin doesn't exist or doesn't provide a resource, just proxy
69 if self
._resource
is None:
70 self
._resource
= NotFound()
72 def __getattr__(self
, attrib
):
73 return getattr(self
._resource
, attrib
)
76 return dir(self
._resource
)