funga

Signer and keystore daemon and library for cryptocurrency software development
Info | Log | Files | Refs | README | LICENSE

import.py (1769B)


      1 # standard imports
      2 import os
      3 import sys
      4 import logging 
      5 import argparse
      6 
      7 # third-party imports
      8 import confini
      9 
     10 # local imports
     11 from crypto_dev_signer.keystore import ReferenceKeystore
     12 
     13 logging.basicConfig(level=logging.WARNING)
     14 logg = logging.getLogger()
     15 
     16 config_dir = os.path.join('/usr/local/etc/cic-eth')
     17 
     18 db = None
     19 
     20 
     21 argparser = argparse.ArgumentParser()
     22 argparser.add_argument('-c', type=str, default=config_dir, help='config file')
     23 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')
     24 argparser.add_argument('-v', action='store_true', help='be verbose')
     25 argparser.add_argument('-vv', action='store_true', help='be more verbose')
     26 argparser.add_argument('private_key', type=str, help='private key to add, 0x hex format')
     27 args = argparser.parse_args()
     28 
     29 if args.vv:
     30     logging.getLogger().setLevel(logging.DEBUG)
     31 elif args.v:
     32     logging.getLogger().setLevel(logging.INFO)
     33 
     34 config = confini.Config(args.c, args.env_prefix)
     35 config.process()
     36 config.censor('PASSWORD', 'DATABASE')
     37 config.censor('SECRET', 'SIGNER')
     38 logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
     39 
     40 # connect to database
     41 dsn = 'postgresql://{}:{}@{}:{}/{}'.format(
     42         config.get('DATABASE_USER'),
     43         config.get('DATABASE_PASSWORD'),
     44         config.get('DATABASE_HOST'),
     45         config.get('DATABASE_PORT'),
     46         config.get('DATABASE_NAME'),    
     47     )
     48 
     49 logg.info('using dsn {}'.format(dsn))
     50 
     51 
     52 if __name__ == '__main__':
     53     kw = {
     54         'symmetric_key': bytes.fromhex(config.get('SIGNER_SECRET')),
     55         }
     56     r = ReferenceKeystore(dsn, **kw)
     57     private_key_bytes = bytes.fromhex(args.private_key)
     58     r.import_raw_key(private_key_bytes)