aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-08-16 23:23:35 +0200
committerJ08nY2017-08-16 23:23:35 +0200
commitcc16622a79975a7e67eac98316ac032711f2add6 (patch)
treea4b095583104031d7e6fddcf94ce70e3eba0229d
parente979464e4cd836cdbfffbb2b803edb71b21a3a86 (diff)
downloadmailman-pgp-cc16622a79975a7e67eac98316ac032711f2add6.tar.gz
mailman-pgp-cc16622a79975a7e67eac98316ac032711f2add6.tar.zst
mailman-pgp-cc16622a79975a7e67eac98316ac032711f2add6.zip
-rw-r--r--src/mailman_pgp/archivers/tests/test_maildir.py2
-rw-r--r--src/mailman_pgp/archivers/tests/test_mbox.py2
-rw-r--r--src/mailman_pgp/config/mailman_pgp.cfg10
-rw-r--r--src/mailman_pgp/config/schema.cfg6
-rw-r--r--src/mailman_pgp/rest/config.py72
-rw-r--r--src/mailman_pgp/rest/lists.py4
-rw-r--r--src/mailman_pgp/rest/root.py26
-rw-r--r--src/mailman_pgp/rest/tests/test_config.py59
-rw-r--r--src/mailman_pgp/testing/mailman_pgp.cfg8
9 files changed, 174 insertions, 15 deletions
diff --git a/src/mailman_pgp/archivers/tests/test_maildir.py b/src/mailman_pgp/archivers/tests/test_maildir.py
index bc810a7..25fc194 100644
--- a/src/mailman_pgp/archivers/tests/test_maildir.py
+++ b/src/mailman_pgp/archivers/tests/test_maildir.py
@@ -66,6 +66,8 @@ but the water deserves to be swum.
def test_archives(self):
with TemporaryDirectory() as maildir_dir:
+ self.addCleanup(config.set, 'archiving', 'maildir_dir',
+ config.get('archiving', 'maildir_dir'))
config.set('archiving', 'maildir_dir', maildir_dir)
LocalMaildirArchiver.archive_message(self.mlist, self.msg)
diff --git a/src/mailman_pgp/archivers/tests/test_mbox.py b/src/mailman_pgp/archivers/tests/test_mbox.py
index fde0e50..50b7113 100644
--- a/src/mailman_pgp/archivers/tests/test_mbox.py
+++ b/src/mailman_pgp/archivers/tests/test_mbox.py
@@ -66,6 +66,8 @@ but the water deserves to be swum.
def test_archives(self):
with TemporaryDirectory() as mailbox_dir:
+ self.addCleanup(config.set, 'archiving', 'mailbox_dir',
+ config.get('archiving', 'mailbox_dir'))
config.set('archiving', 'mailbox_dir', mailbox_dir)
LocalMailboxArchiver.archive_message(self.mlist, self.msg)
diff --git a/src/mailman_pgp/config/mailman_pgp.cfg b/src/mailman_pgp/config/mailman_pgp.cfg
index d2aa84d..5156651 100644
--- a/src/mailman_pgp/config/mailman_pgp.cfg
+++ b/src/mailman_pgp/config/mailman_pgp.cfg
@@ -89,7 +89,7 @@ change_request_lifetime: 1d
[rest]
-# Allow the acessing of a list private key through the REST API.
+# Allow the accessing of a list private key through the REST API.
# This is necessary for the django-pgpmailman web ui to allow a list owner
# to export the list private key.
allow_read_private_key: yes
@@ -97,4 +97,10 @@ allow_read_private_key: yes
# Allow the modification of a list private key through the REST API?
# This is necessary for the django-pgpmailman web ui to allow a list owner
# to change the list private key.
-allow_write_private_key: yes \ No newline at end of file
+allow_write_private_key: yes
+
+# Allow the accessing of this plugin configuration through the REST API.
+allow_read_config: yes
+
+# Allow the modification of this plugin configuration through the REST API.
+allow_write_config: no \ No newline at end of file
diff --git a/src/mailman_pgp/config/schema.cfg b/src/mailman_pgp/config/schema.cfg
index ebd4377..cd3a2c4 100644
--- a/src/mailman_pgp/config/schema.cfg
+++ b/src/mailman_pgp/config/schema.cfg
@@ -59,4 +59,8 @@ change_request_lifetime: lazr.config.as_timedelta
[rest]
allow_read_private_key: lazr.config.as_boolean
-allow_write_private_key: lazr.config.as_boolean \ No newline at end of file
+allow_write_private_key: lazr.config.as_boolean
+
+allow_read_config: lazr.config.as_boolean
+
+allow_write_config: lazr.config.as_boolean \ No newline at end of file
diff --git a/src/mailman_pgp/rest/config.py b/src/mailman_pgp/rest/config.py
new file mode 100644
index 0000000..14a4953
--- /dev/null
+++ b/src/mailman_pgp/rest/config.py
@@ -0,0 +1,72 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program 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.
+#
+# This program 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
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+""""""
+from mailman.rest.helpers import etag, forbidden, not_found, okay
+
+from mailman_pgp.config import config
+
+
+class AConfig:
+ """"""
+
+ def __init__(self, section=None, option=None):
+ self._section = section
+ self._option = option
+
+ def on_get(self, request, response):
+ if not config.get_value('rest', 'allow_read_config'):
+ forbidden(response)
+ return
+ if self._section is None:
+ # return whole config
+ resource = {}
+ for section in config.sections():
+ resource[section] = {key: config.get(section, key)
+ for key in config.options(section)}
+ else:
+ if not config.has_section(self._section):
+ not_found(response)
+ return
+
+ if self._option is None:
+ # return section
+ resource = {key: config.get(self._section, key)
+ for key in config.options(self._section)}
+ else:
+ if not config.has_option(self._section, self._option):
+ not_found(response)
+ return
+ # return value
+ resource = {self._option: config.get(self._section,
+ self._option)}
+ okay(response, etag(resource))
+
+ def on_put(self, request, response):
+ if not config.get_value('rest', 'allow_write_config'):
+ forbidden(response)
+ return
+ if self._section is None:
+ # set whole config
+ pass
+ else:
+ if self._option is None:
+ # set section
+ pass
+ else:
+ # set value
+ pass
diff --git a/src/mailman_pgp/rest/lists.py b/src/mailman_pgp/rest/lists.py
index c7c632a..251ed7a 100644
--- a/src/mailman_pgp/rest/lists.py
+++ b/src/mailman_pgp/rest/lists.py
@@ -22,8 +22,8 @@ from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.member import MemberRole
from mailman.rest.helpers import (accepted, bad_request,
child, CollectionMixin, etag,
- GetterSetter, no_content, not_found,
- NotFound, okay, forbidden)
+ forbidden, GetterSetter, no_content,
+ not_found, NotFound, okay)
from mailman.rest.validator import (enum_validator, PatchValidator,
UnknownPATCHRequestError, Validator)
from pgpy.errors import PGPError
diff --git a/src/mailman_pgp/rest/root.py b/src/mailman_pgp/rest/root.py
index 52ebfbe..2edad2e 100644
--- a/src/mailman_pgp/rest/root.py
+++ b/src/mailman_pgp/rest/root.py
@@ -15,19 +15,13 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-REST root.
+"""REST root."""
-
-/lists/ -> List all known encrypted lists.
-/lists/<list_id>/ ->
-/lists/<list_id>/key -> GET list_public_key
-"""
-
-from mailman.rest.helpers import child
+from mailman.rest.helpers import child, NotFound
from public import public
from mailman_pgp.rest.addresses import AllAddresses, AnAddress
+from mailman_pgp.rest.config import AConfig
from mailman_pgp.rest.lists import AllPGPLists, APGPList
@@ -48,3 +42,17 @@ class RESTRoot:
else:
email = segments.pop(0)
return AnAddress(email), segments
+
+ @child()
+ def config(self, context, segments):
+ if len(segments) == 0:
+ return AConfig(), []
+ elif len(segments) == 1:
+ section = segments.pop(0)
+ return AConfig(section), []
+ elif len(segments) == 2:
+ section = segments.pop(0)
+ attribute = segments.pop(0)
+ return AConfig(section, attribute), []
+ else:
+ return NotFound(), []
diff --git a/src/mailman_pgp/rest/tests/test_config.py b/src/mailman_pgp/rest/tests/test_config.py
new file mode 100644
index 0000000..93766f0
--- /dev/null
+++ b/src/mailman_pgp/rest/tests/test_config.py
@@ -0,0 +1,59 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program 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.
+#
+# This program 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
+# this program. If not, see <http://www.gnu.org/licenses/>.
+import unittest
+
+from mailman.testing.helpers import call_api
+
+from mailman_pgp.config import config
+from mailman_pgp.testing.layers import PGPRESTLayer
+
+
+class TestConfig(unittest.TestCase):
+ layer = PGPRESTLayer
+
+ def setUp(self):
+ pass
+
+ def test_get_config(self):
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/config/')
+ for section in config.sections():
+ self.assertIn(section, json)
+ json_section = json[section]
+ for option in config.options(section):
+ self.assertIn(option, json_section)
+ self.assertEqual(config.get(section, option),
+ json_section[option])
+
+ def test_get_section(self):
+ for section in config.sections():
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/config/' +
+ section + '/')
+ for option in config.options(section):
+ self.assertIn(option, json)
+ self.assertEqual(config.get(section, option),
+ json[option])
+
+ def test_get_option(self):
+ for section in config.sections():
+ for option in config.options(section):
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/config/' +
+ section + '/' + option + '/')
+ self.assertIn(option, json)
+ self.assertEqual(config.get(section, option), json[option])
diff --git a/src/mailman_pgp/testing/mailman_pgp.cfg b/src/mailman_pgp/testing/mailman_pgp.cfg
index aac192e..d7807ba 100644
--- a/src/mailman_pgp/testing/mailman_pgp.cfg
+++ b/src/mailman_pgp/testing/mailman_pgp.cfg
@@ -90,7 +90,7 @@ change_request_lifetime: 1d
[rest]
-# Allow the acessing of a list private key through the REST API.
+# Allow the accessing of a list private key through the REST API.
# This is necessary for the django-pgpmailman web ui to allow a list owner
# to export the list private key.
allow_read_private_key: yes
@@ -99,3 +99,9 @@ allow_read_private_key: yes
# This is necessary for the django-pgpmailman web ui to allow a list owner
# to change the list private key.
allow_write_private_key: yes
+
+# Allow the accessing of this plugin configuration through the REST API.
+allow_read_config: yes
+
+# Allow the modification of this plugin configuration through the REST API.
+allow_write_config: no \ No newline at end of file