aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/model/list.py
diff options
context:
space:
mode:
authorJ08nY2017-07-07 17:36:12 +0200
committerJ08nY2017-07-07 17:36:12 +0200
commit45174af3b9b410102022cb5c335e42c7e0052b19 (patch)
tree346fd6ccad4c5abe548eb71a819f390d31974403 /src/mailman_pgp/model/list.py
parent6b627e130ad1a2fa453045b76b8f9a08e9520c34 (diff)
downloadmailman-pgp-45174af3b9b410102022cb5c335e42c7e0052b19.tar.gz
mailman-pgp-45174af3b9b410102022cb5c335e42c7e0052b19.tar.zst
mailman-pgp-45174af3b9b410102022cb5c335e42c7e0052b19.zip
Diffstat (limited to 'src/mailman_pgp/model/list.py')
-rw-r--r--src/mailman_pgp/model/list.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py
index f8efdd4..eaeb7a3 100644
--- a/src/mailman_pgp/model/list.py
+++ b/src/mailman_pgp/model/list.py
@@ -19,6 +19,7 @@
from os.path import exists, isfile, join
+from flufl.lock import Lock
from mailman.database.types import Enum, SAUnicode
from mailman.interfaces.action import Action
from mailman.interfaces.listmanager import IListManager
@@ -61,7 +62,6 @@ class PGPMailingList(Base):
self._defaults()
self.list_id = mlist.list_id
self._mlist = mlist
- self._generate(mlist)
def _defaults(self):
self.unsigned_msg_action = Action.reject
@@ -80,14 +80,6 @@ class PGPMailingList(Base):
self._key = None
self._key_generator = None
- def _generate(self, mlist):
- self._key_generator = ListKeyGenerator(config.pgp.keypair_config,
- mlist.display_name,
- mlist.posting_address,
- mlist.request_address,
- self.key_path)
- self._key_generator.start()
-
@property
def mlist(self):
"""
@@ -110,17 +102,25 @@ class PGPMailingList(Base):
# Check the file
if exists(self.key_path) and isfile(self.key_path):
self._key, _ = PGPKey.from_file(self.key_path)
- else:
- # Check if key generator is running or what? Restart it if not.
- # If we race it shutting down and saving the key file
- # it will simply check the key_file exists and exit.
- if self._key_generator is None or \
- not self._key_generator.is_alive():
- self._generate(self.mlist)
- else:
- self._key_generator.join(0.2)
return self._key
+ @key.setter
+ def key(self, value):
+ with Lock(self.key_path + '.lock'):
+ self._key = value
+ with open(self.key_path, 'w') as key_file:
+ key_file.write(str(value))
+
+ def generate_key(self, block=False):
+ self._key_generator = ListKeyGenerator(config.pgp.keypair_config,
+ self.mlist.display_name,
+ self.mlist.posting_address,
+ self.mlist.request_address,
+ self.key_path)
+ self._key_generator.start()
+ if block:
+ self._key_generator.join()
+
@property
def pubkey(self):
"""