Handle gpg-mailgate.py missing params better
This commit is contained in:
parent
a3eb892df9
commit
7ac928af76
5 changed files with 33 additions and 7 deletions
|
@ -36,9 +36,11 @@ import lacre.core as core
|
|||
|
||||
LOG = logging.getLogger('gpg-mailgate.py')
|
||||
|
||||
missing_params = conf.validate_config()
|
||||
missing_params = conf.validate_config(additional=conf.SCRIPT_REQUIRED)
|
||||
config_file = conf.config_source()
|
||||
|
||||
if missing_params:
|
||||
LOG.error(f"Aborting delivery! Following mandatory config parameters are missing: {missing_params!r}")
|
||||
LOG.error(f"Aborting delivery! Following mandatory config parameters are missing in {config_file!r}: {missing_params}")
|
||||
sys.exit(lacre.EX_CONFIG)
|
||||
|
||||
delivered = False
|
||||
|
|
|
@ -22,6 +22,9 @@ MANDATORY_CONFIG_ITEMS = [("relay", "host"),
|
|||
("daemon", "port"),
|
||||
("gpg", "keyhome")]
|
||||
|
||||
SCRIPT_REQUIRED = [('database', 'enabled'),
|
||||
('database', 'url')]
|
||||
|
||||
CRON_REQUIRED = [('database', 'enabled'),
|
||||
('database', 'url'),
|
||||
('cron', 'mail_templates')]
|
||||
|
@ -40,9 +43,9 @@ def load_config() -> dict:
|
|||
path. Otherwise, the default is taken
|
||||
('/etc/gpg-mailgate.conf').
|
||||
"""
|
||||
configFile = os.getenv(CONFIG_PATH_ENV, '/etc/gpg-mailgate.conf')
|
||||
config_file = config_source()
|
||||
|
||||
parser = _read_config(configFile)
|
||||
parser = _read_config(config_file)
|
||||
|
||||
# XXX: Global variable. It is a left-over from old GPG-Mailgate code. We
|
||||
# should drop it and probably use ConfigParser instance where configuration
|
||||
|
@ -52,6 +55,14 @@ def load_config() -> dict:
|
|||
return cfg
|
||||
|
||||
|
||||
def config_source() -> str:
|
||||
"""Return path of configuration file.
|
||||
|
||||
Taken from GPG_MAILGATE_CONFIG environment variable, and if it's not
|
||||
set, defaults to /etc/gpg-mailgate.conf."""
|
||||
return os.getenv(CONFIG_PATH_ENV, '/etc/gpg-mailgate.conf')
|
||||
|
||||
|
||||
def _read_config(fileName) -> RawConfigParser:
|
||||
cp = RawConfigParser()
|
||||
cp.read(fileName)
|
||||
|
|
|
@ -18,3 +18,12 @@ def init_keyring() -> KeyRing:
|
|||
schema = dbk.KeyRingSchema()
|
||||
LOG.info('Initialising database keyring from %s', url)
|
||||
return dbk.DatabaseKeyRing(url, schema)
|
||||
|
||||
|
||||
def freeze_and_load_keys():
|
||||
"""Load and return keys.
|
||||
|
||||
Doesn't refresh the keys when they change on disk.
|
||||
"""
|
||||
keyring = init_keyring()
|
||||
return keyring.freeze_identities()
|
||||
|
|
|
@ -39,6 +39,10 @@ def _build_config(config):
|
|||
cp.add_section("gpg")
|
||||
cp.set("gpg", "keyhome", config["gpg_keyhome"])
|
||||
|
||||
cp.add_section('database')
|
||||
cp.set('database', 'enabled', 'yes')
|
||||
cp.set('database', 'url', 'sqlite:///test/lacre.db')
|
||||
|
||||
cp.add_section("smime")
|
||||
cp.set("smime", "cert_path", config["smime_certpath"])
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ import lacre.dbkeyring as dbk
|
|||
|
||||
import unittest
|
||||
|
||||
class LacreDbKeyringTest(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_load_keys(self):
|
||||
class LacreDbKeyringTest(unittest.TestCase):
|
||||
def test_load_keys(self):
|
||||
db_url = 'sqlite:///test/lacre.db'
|
||||
schema = dbk.KeyRingSchema()
|
||||
db = dbk.DatabaseKeyRing(db_url, schema)
|
||||
|
||||
identities = await db.freeze_identities()
|
||||
identities = db.freeze_identities()
|
||||
|
||||
self.assertTrue('1CD245308F0963D038E88357973CF4D9387C44D7' in identities)
|
||||
self.assertTrue(identities.has_email('alice@disposlab'))
|
||||
|
|
Loading…
Reference in a new issue