diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/config/schema.cfg | 15 | ||||
| -rw-r--r-- | src/mailman/interfaces/system.py | 1 | ||||
| -rw-r--r-- | src/mailman/rest/configuration.py | 74 | ||||
| -rw-r--r-- | src/mailman/rest/configure.zcml | 17 | ||||
| -rw-r--r-- | src/mailman/rest/initialize.py | 34 | ||||
| -rw-r--r-- | src/mailman/rest/publication.py | 29 | ||||
| -rw-r--r-- | src/mailman/rest/root.py | 30 | ||||
| -rw-r--r-- | src/mailman/rest/security.py | 37 |
8 files changed, 235 insertions, 2 deletions
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index cad604b3d..a2003d034 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -207,6 +207,21 @@ failure: $msgid delivery to $recip failed with code $smtpcode, $smtpmsg [logging.vette] +[webservice] +# The hostname at which admin web service resources are exposed. +hostname: localhost + +# Whether or not requests to the web service are secured through SSL. +use_https: no + +# Default view permission for the admin web service. +view_permission: zope.Public + +# Whether or not to show tracebacks in an HTTP response for a request that +# raised an exception. +show_tracebacks: yes + + [domain.master] # Site-wide domain defaults. To configure an individual # domain, add a [domain.example_com] section with the overrides. diff --git a/src/mailman/interfaces/system.py b/src/mailman/interfaces/system.py index 62270803d..6088f7624 100644 --- a/src/mailman/interfaces/system.py +++ b/src/mailman/interfaces/system.py @@ -26,6 +26,7 @@ __all__ = [ from lazr.restful.declarations import export_as_webservice_entry, exported +from zope.interface import Interface from zope.schema import TextLine from mailman.i18n import _ diff --git a/src/mailman/rest/configuration.py b/src/mailman/rest/configuration.py new file mode 100644 index 000000000..36a7449a1 --- /dev/null +++ b/src/mailman/rest/configuration.py @@ -0,0 +1,74 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Mailman admin web service configuration.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'AdminWebServiceConfiguration', + ] + + +from lazr.restful.interfaces import IWebServiceConfiguration + +from mailman.config import config +from mailman.rest.publication import AdminWebServicePublication +from mailman.rest.root import AdminWebServiceRootResource +from mailman.version import VERSION + + + +class AdminWebServiceConfiguration: + """A configuration object for the Mailman admin web service.""" + + implements(IWebServiceConfiguration) + + @property + def view_permission(self): + return config.webservice.view_permission + + path_override = 'admin' + + @property + def use_https(self): + """See `IWebServiceConfiguration`.""" + return config.webservice.use_https + + # This should match the major.minor Mailman version. + service_version_uri_prefix = '3.0' + code_revision = VERSION + + @property + def show_tracebacks(self): + """See `IWebServiceConfiguration`.""" + return config.webservice.show_tracebacks + + default_batch_size = 50 + max_batch_size = 300 + + def createRequest(self, body_instream, environ): + """See `IWebServiceConfiguration`.""" + request = AdminWebServiceRequest(body_instream, environ) + request.setPublication( + AdminWebServicePublication(AdminWebServiceRootResource()) + return request + + def get_request_user(self): + """See `IWebServiceConfiguration`.""" + return None diff --git a/src/mailman/rest/configure.zcml b/src/mailman/rest/configure.zcml new file mode 100644 index 000000000..236365a5c --- /dev/null +++ b/src/mailman/rest/configure.zcml @@ -0,0 +1,17 @@ +<!-- -*- xml -*- --> +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:webservice="http://namespaces.canonical.com/webservice"> + + <webservice:register module="mailman.interfaces.rest" /> + + <adapter factory="mailman.rest.traversal.Traverse" /> + + <adapter factory="mailman.rest.root.AdminWebServiceRootAbsoluteURL" /> + + <adapter + factory="mailman.rest.root.AdminWebServiceRootAbsoluteURL" + name="absolute_url" + /> + +</configure> diff --git a/src/mailman/rest/initialize.py b/src/mailman/rest/initialize.py new file mode 100644 index 000000000..daa0af430 --- /dev/null +++ b/src/mailman/rest/initialize.py @@ -0,0 +1,34 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Admin web service initialization.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'initialize', + ] + + +from zope.configuration import xmlconfig + + + +def initialize(): + """Initialize the admin web service and the Zope Component Architecture.""" + xmlconfig.file('mailman', 'mailman.rest') diff --git a/src/mailman/rest/publication.py b/src/mailman/rest/publication.py new file mode 100644 index 000000000..54fedab76 --- /dev/null +++ b/src/mailman/rest/publication.py @@ -0,0 +1,29 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Module stuff.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + ] + + + +class WebServiceTestPublication(WebServicePublicationMixin, TestPublication): + """Test publication that mixes in the necessary web service stuff.""" diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py index 5b2949b3e..c050ebc1c 100644 --- a/src/mailman/rest/root.py +++ b/src/mailman/rest/root.py @@ -21,19 +21,25 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ - 'AdminServiceRootResource', + 'AdminWebServiceRootResource', + 'AdminWebServiceRootAbsoluteURL', ] from lazr.restful import ServiceRootResource +from zope.component import adapts from zope.interface import implements +from zope.publisher.interfaces.browser import IDefaultBrowserLayer +from zope.traversing.browser.interfaces import IAbsoluteURL +from mailman.config import config from mailman.core.system import system from mailman.interfaces.rest import IHasGet +from mailman.rest.configuration import AdminWebServiceConfiguration -class AdminServiceRootResource(ServiceRootResource): +class AdminWebServiceRootResource(ServiceRootResource): """The root of the Mailman RESTful admin web service.""" implements(IHasGet) @@ -44,3 +50,23 @@ class AdminServiceRootResource(ServiceRootResource): 'sys': system, } return top_level.get(name) + + +class AdminWebServiceRootAbsoluteURL: + """A basic implementation of `IAbsoluteURL` for the root object.""" + + implements(IAbsoluteURL) + adapts(AdminWebServiceRootResource, IDefaultBrowserLayer) + + def __init__(self, context, request): + """Initialize with respect to a context and request.""" + self.webservice_config = AdminWebServiceConfiguration() + self.version = webservice_config.service_version_uri_prefix + self.schema = ('https' if self.webservice_config.use_https else 'http') + self.hostname = config.webservice.hostname + + def __str__(self): + """Return the semi-hard-coded URL to the service root.""" + return '{0.schema}://{0.hostname}/{0.version}'.format(self) + + __call__ = __str__ diff --git a/src/mailman/rest/security.py b/src/mailman/rest/security.py new file mode 100644 index 000000000..7531f377f --- /dev/null +++ b/src/mailman/rest/security.py @@ -0,0 +1,37 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Default security policy for the admin web service.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'AdminWebServiceSecurityPolicy', + ] + + +from zope.security.simplepolicies import PermissiveSecurityPolicy + + + +class AdminWebServiceSecurityPolicy(PermissiveSecurityPolicy): + """A very basic wide-open security policy.""" + + def checkPermission(self, permission, object): + """By default, allow all access!""" + return True |
