From f92e2878cd96e528d032100c5501a43e862b8e5c Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 17 Oct 2020 11:06:52 +0200 Subject: [PATCH] Add configurable dsn for postgres connection --- CHANGELOG | 2 ++ config/database.ini | 6 ++++++ crypto_dev_signer/keystore/postgres.py | 6 ++++-- scripts/crypto-dev-daemon | 11 ++++++++++- setup.py | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 config/database.ini diff --git a/CHANGELOG b/CHANGELOG index 780583c..f0afeaf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* 0.2.3 + - Use dsn and config for keystore database settings * 0.2.2 - Use confini for configurations * 0.2.1 diff --git a/config/database.ini b/config/database.ini new file mode 100644 index 0000000..3f06eb8 --- /dev/null +++ b/config/database.ini @@ -0,0 +1,6 @@ +[database] +NAME=cic-signer +USER=postgres +PASSWORD= +HOST=localhost +PORT=5432 diff --git a/crypto_dev_signer/keystore/postgres.py b/crypto_dev_signer/keystore/postgres.py index 069b464..add6cf6 100644 --- a/crypto_dev_signer/keystore/postgres.py +++ b/crypto_dev_signer/keystore/postgres.py @@ -6,6 +6,7 @@ import base64 from cryptography.fernet import Fernet import psycopg2 from psycopg2 import sql +from psycopg2.extensions import make_dsn import sha3 # local imports @@ -34,8 +35,9 @@ class ReferenceKeystore(Keystore): """, ] - def __init__(self, dbname, **kwargs): - self.conn = psycopg2.connect('dbname=' + dbname) + def __init__(self, dsn, **kwargs): + logg.debug('dsn {}'.format(dsn)) + self.conn = psycopg2.connect(make_dsn(dsn)) self.cur = self.conn.cursor() self.symmetric_key = kwargs.get('symmetric_key') diff --git a/scripts/crypto-dev-daemon b/scripts/crypto-dev-daemon index 791a04f..c855c39 100755 --- a/scripts/crypto-dev-daemon +++ b/scripts/crypto-dev-daemon @@ -51,6 +51,14 @@ if args.s: elif config.get('SIGNER_SOCKET_PATH'): socket_path = config.get('SIGNER_SOCKET_PATH') +# connect to database +dsn = 'postgresql://{}:{}@{}:{}/{}'.format( + config.get('DATABASE_USER'), + config.get('DATABASE_PASSWORD'), + config.get('DATABASE_HOST'), + config.get('DATABASE_PORT'), + config.get('DATABASE_NAME'), + ) class MissingSecretError(BaseException): @@ -194,7 +202,8 @@ def init(): 'symmetric_key': secret, } #db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw) - db = ReferenceKeystore(config.get('SIGNER_DATABASE'), **kw) + #db = ReferenceKeystore(config.get('SIGNER_DATABASE'), **kw) + db = ReferenceKeystore(dsn, **kw) signer = ReferenceSigner(db) diff --git a/setup.py b/setup.py index f5481f7..c9d95ef 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="crypto-dev-signer", - version="0.2.2", + version="0.2.3", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no",