No middleware if no ipc, add prefix env var

This commit is contained in:
nolash 2020-10-17 14:47:01 +02:00
parent 14e3581b3d
commit 2c34777ff1
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 24 additions and 14 deletions

View File

@ -1,3 +1,6 @@
* 0.2.5
- Add default env override
- Do not create middleware if ipc no set
* 0.2.4 * 0.2.4
- Remove hardcoded ipc path in middleware - Remove hardcoded ipc path in middleware
* 0.2.3 * 0.2.3

View File

@ -1,4 +1,3 @@
[signer] [signer]
secret = deadbeef secret = deadbeef
database = crypto-dev-signer
socket_path = /tmp/crypto-dev-signer/jsonrpc.ipc socket_path = /tmp/crypto-dev-signer/jsonrpc.ipc

View File

@ -8,14 +8,13 @@ re_websocket = re.compile('^wss?://')
re_http = re.compile('^https?://') re_http = re.compile('^https?://')
#def create_middleware(ipcaddr='/var/run/cic-platform/cic.ipc'):
def create_middleware(ipcpath): def create_middleware(ipcpath):
PlatformMiddleware.ipcaddr = ipcpath PlatformMiddleware.ipcaddr = ipcpath
return PlatformMiddleware return PlatformMiddleware
# overrides the original Web3 constructor # overrides the original Web3 constructor
def Web3(blockchain_provider='ws://localhost:8546', ipcpath='/run/crypto-dev-signer/jsonrpc.ipc'): def Web3(blockchain_provider='ws://localhost:8546', ipcpath=None):
provider = None provider = None
if re.match(re_websocket, blockchain_provider) != None: if re.match(re_websocket, blockchain_provider) != None:
provider = WebsocketProvider(blockchain_provider) provider = WebsocketProvider(blockchain_provider)
@ -24,6 +23,8 @@ def Web3(blockchain_provider='ws://localhost:8546', ipcpath='/run/crypto-dev-sig
w3 = Web3super(provider) w3 = Web3super(provider)
w3.middleware_onion.add(create_middleware(ipcpath)) if ipcpath != None:
w3.middleware_onion.add(create_middleware(ipcpath))
w3.eth.personal = w3.geth.personal w3.eth.personal = w3.geth.personal
return w3 return w3

View File

@ -23,12 +23,13 @@ class PlatformMiddleware:
# hack workaround # hack workaround
id_seq = -1 id_seq = -1
re_personal = re.compile('^personal_.*') re_personal = re.compile('^personal_.*')
ipcaddr = '/tmp/foo.ipc' ipcaddr = None
def __init__(self, make_request, w3): def __init__(self, make_request, w3):
self.w3 = w3 self.w3 = w3
self.make_request = make_request self.make_request = make_request
raise AttributeError('ipcaddr not set')
# TODO: understand what format input params come in # TODO: understand what format input params come in
@ -51,7 +52,7 @@ class PlatformMiddleware:
def __call__(self, method, suspect_params): def __call__(self, method, suspect_params):
self.id_seq += 1 self.id_seq += 1
logg.debug('in middleware method {} params {}'.format(method, suspect_params)) logg.debug('in middleware method {} params {} ipcpath {}'.format(method, suspect_params, self.ipcaddr))
if self.re_personal.match(method) != None: if self.re_personal.match(method) != None:
params = PlatformMiddleware._translate_params(suspect_params) params = PlatformMiddleware._translate_params(suspect_params)

View File

@ -39,6 +39,7 @@ class ReferenceKeystore(Keystore):
logg.debug('dsn {}'.format(dsn)) logg.debug('dsn {}'.format(dsn))
self.conn = psycopg2.connect(make_dsn(dsn)) self.conn = psycopg2.connect(make_dsn(dsn))
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
self.cur.execute(self.schema[0])
self.symmetric_key = kwargs.get('symmetric_key') self.symmetric_key = kwargs.get('symmetric_key')

View File

@ -28,29 +28,32 @@ socket_path = '/run/crypto-dev-signer/jsonrpc.ipc'
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument('-c', type=str, default=config_dir, help='config file') argparser.add_argument('-c', type=str, default=config_dir, help='config file')
argparser.add_argument('--env-prefix', dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
argparser.add_argument('-i', type=int, help='default chain id for EIP155') argparser.add_argument('-i', type=int, help='default chain id for EIP155')
argparser.add_argument('-s', type=str, help='socket path') argparser.add_argument('-s', type=str, help='socket path')
argparser.add_argument('-v', action='store_true', help='be verbose') argparser.add_argument('-v', action='store_true', help='be verbose')
argparser.add_argument('-vv', action='store_true', help='be more verbose') argparser.add_argument('-vv', action='store_true', help='be more verbose')
args = argparser.parse_args() args = argparser.parse_args()
config = confini.Config(args.c, args.env_prefix)
config.process()
if args.vv: if args.vv:
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
elif args.v: elif args.v:
logging.getLogger().setLevel(logging.INFO) logging.getLogger().setLevel(logging.INFO)
config = confini.Config(args.c, args.env_prefix)
config.process()
config.censor('PASSWORD', 'DATABASE')
config.censor('SECRET', 'SIGNER')
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
if args.i: if args.i:
chainId = args.i chainId = args.i
if args.s: if args.s:
socket_path = args.s socket_path = 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 # connect to database
dsn = 'postgresql://{}:{}@{}:{}/{}'.format( dsn = 'postgresql://{}:{}@{}:{}/{}'.format(
config.get('DATABASE_USER'), config.get('DATABASE_USER'),
@ -60,6 +63,10 @@ dsn = 'postgresql://{}:{}@{}:{}/{}'.format(
config.get('DATABASE_NAME'), config.get('DATABASE_NAME'),
) )
logg.info('using dsn {}'.format(dsn))
logg.info('using socket {}'.format(socket_path))
class MissingSecretError(BaseException): class MissingSecretError(BaseException):
def __init__(self, message): def __init__(self, message):
@ -201,8 +208,6 @@ def init():
kw = { kw = {
'symmetric_key': secret, 'symmetric_key': secret,
} }
#db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw)
#db = ReferenceKeystore(config.get('SIGNER_DATABASE'), **kw)
db = ReferenceKeystore(dsn, **kw) db = ReferenceKeystore(dsn, **kw)
signer = ReferenceSigner(db) signer = ReferenceSigner(db)

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name="crypto-dev-signer", name="crypto-dev-signer",
version="0.2.4", version="0.2.5",
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",