diff options
| author | Barry Warsaw | 2014-12-26 22:59:02 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2014-12-26 22:59:02 -0500 |
| commit | 37ee257a8b0ccdcab41703b04d68e3f939017988 (patch) | |
| tree | 54f5a586f2c8a1f09ccd5ba7826b3646f0e49624 /src/mailman/rest/root.py | |
| parent | ee2fdc578b5e0209a9e661cc1455aaff5dc8443a (diff) | |
| download | mailman-37ee257a8b0ccdcab41703b04d68e3f939017988.tar.gz mailman-37ee257a8b0ccdcab41703b04d68e3f939017988.tar.zst mailman-37ee257a8b0ccdcab41703b04d68e3f939017988.zip | |
Diffstat (limited to 'src/mailman/rest/root.py')
| -rw-r--r-- | src/mailman/rest/root.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py index 8cbe4061a..34f058bf2 100644 --- a/src/mailman/rest/root.py +++ b/src/mailman/rest/root.py @@ -32,7 +32,7 @@ from mailman.interfaces.listmanager import IListManager from mailman.rest.addresses import AllAddresses, AnAddress from mailman.rest.domains import ADomain, AllDomains from mailman.rest.helpers import ( - BadRequest, NotFound, child, etag, okay, path_to) + BadRequest, NotFound, child, etag, not_found, okay, path_to) from mailman.rest.lists import AList, AllLists, Styles from mailman.rest.members import AMember, AllMembers, FindMembers from mailman.rest.preferences import ReadOnlyPreferences @@ -88,6 +88,27 @@ class Versions: okay(response, etag(resource)) +class SystemConfiguration: + def __init__(self, section=None): + self._section = section + + def on_get(self, request, response): + if self._section is None: + resource = dict( + sections=sorted(section.name for section in config)) + okay(response, etag(resource)) + return + missing = object() + section = getattr(config, self._section, missing) + if section is missing: + not_found(response) + return + # Sections don't have .keys(), .values(), or .items() but we can + # iterate over them. + resource = {key: section[key] for key in section} + okay(response, etag(resource)) + + class TopLevel: """Top level collections and entries.""" @@ -97,12 +118,18 @@ class TopLevel: if len(segments) == 0: # This provides backward compatibility; see /system/versions. return Versions() - elif len(segments) > 1: - return BadRequest(), [] elif segments[0] == 'preferences': + if len(segments) > 1: + return BadRequest(), [] return ReadOnlyPreferences(system_preferences, 'system'), [] elif segments[0] == 'versions': + if len(segments) > 1: + return BadRequest(), [] return Versions(), [] + elif segments[0] == 'configuration': + if len(segments) <= 2: + return SystemConfiguration(*segments[1:]), [] + return BadRequest(), [] else: return NotFound(), [] |
