summaryrefslogtreecommitdiff
path: root/src/mailman/rest/root.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/root.py')
-rw-r--r--src/mailman/rest/root.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py
index f29f2ba1d..a3d18c201 100644
--- a/src/mailman/rest/root.py
+++ b/src/mailman/rest/root.py
@@ -37,7 +37,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
@@ -91,6 +91,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."""
@@ -100,12 +121,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(), []