Add configurable dsn for postgres connection
This commit is contained in:
parent
06962b3365
commit
f92e2878cd
@ -1,3 +1,5 @@
|
|||||||
|
* 0.2.3
|
||||||
|
- Use dsn and config for keystore database settings
|
||||||
* 0.2.2
|
* 0.2.2
|
||||||
- Use confini for configurations
|
- Use confini for configurations
|
||||||
* 0.2.1
|
* 0.2.1
|
||||||
|
6
config/database.ini
Normal file
6
config/database.ini
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[database]
|
||||||
|
NAME=cic-signer
|
||||||
|
USER=postgres
|
||||||
|
PASSWORD=
|
||||||
|
HOST=localhost
|
||||||
|
PORT=5432
|
@ -6,6 +6,7 @@ import base64
|
|||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import sql
|
from psycopg2 import sql
|
||||||
|
from psycopg2.extensions import make_dsn
|
||||||
import sha3
|
import sha3
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@ -34,8 +35,9 @@ class ReferenceKeystore(Keystore):
|
|||||||
""",
|
""",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, dbname, **kwargs):
|
def __init__(self, dsn, **kwargs):
|
||||||
self.conn = psycopg2.connect('dbname=' + dbname)
|
logg.debug('dsn {}'.format(dsn))
|
||||||
|
self.conn = psycopg2.connect(make_dsn(dsn))
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
self.symmetric_key = kwargs.get('symmetric_key')
|
self.symmetric_key = kwargs.get('symmetric_key')
|
||||||
|
|
||||||
|
@ -51,6 +51,14 @@ if args.s:
|
|||||||
elif config.get('SIGNER_SOCKET_PATH'):
|
elif config.get('SIGNER_SOCKET_PATH'):
|
||||||
socket_path = 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):
|
class MissingSecretError(BaseException):
|
||||||
|
|
||||||
@ -194,7 +202,8 @@ def init():
|
|||||||
'symmetric_key': secret,
|
'symmetric_key': secret,
|
||||||
}
|
}
|
||||||
#db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw)
|
#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)
|
signer = ReferenceSigner(db)
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="crypto-dev-signer",
|
name="crypto-dev-signer",
|
||||||
version="0.2.2",
|
version="0.2.3",
|
||||||
description="A signer and keystore daemon and library for cryptocurrency software development",
|
description="A signer and keystore daemon and library for cryptocurrency software development",
|
||||||
author="Louis Holbrook",
|
author="Louis Holbrook",
|
||||||
author_email="dev@holbrook.no",
|
author_email="dev@holbrook.no",
|
||||||
|
Loading…
Reference in New Issue
Block a user