async def admin_delete(ini_path: str, ident: str) -> int: """ Set configuration from file, open node pool and anchor, and request deletion from tails file server of tails files that identifier specifies. :param ini_path: path to configuration file :param ident: identifier to specify in deletion request :return: 0 for OK, 1 for failure. """ config = inis2dict(ini_path) pool_data = NodePoolData( config['Node Pool']['name'], config['Node Pool'].get('genesis.txn.path', None) or None) # nudge empty value from '' to None tsan_data = AnchorData( Role.USER, config['VON Anchor']['name'], config['VON Anchor'].get('seed', None) or None, None, config['VON Anchor'].get('wallet.create', '0').lower() in ['1', 'true', 'yes'], config['VON Anchor'].get('wallet.type', None) or None, config['VON Anchor'].get('wallet.access', None) or None) # Set up node pool ledger config and wallet manager = NodePoolManager() if pool_data.name not in await manager.list(): if pool_data.genesis_txn_path: await manager.add_config(pool_data.name, pool_data.genesis_txn_path) else: logging.error( 'Node pool %s has no ledger configuration but %s specifies no genesis transaction path', pool_data.name, ini_path) return 1 wallet = await get_wallet(tsan_data) async with wallet, ( manager.get(pool_data.name)) as pool, ( NominalAnchor(wallet, pool)) as noman: host = config['Tails Server']['host'] port = config['Tails Server']['port'] epoch = int(time()) url = 'http://{}:{}/tails/{}/{}'.format(host, port, quote(ident), epoch) signature = await noman.sign('{}||{}'.format(epoch, ident)) try: resp = requests.delete(url, data=signature) logging.info('DELETE: url %s status %s', url, resp.status_code) if resp.status_code != requests.codes.ok: return 1 except RequestsConnectionError: logging.error('DELETE connection refused: %s', url) return 1
async def test_formalisms(pool_ip, pool_name, pool_genesis_txn_data, seed_trustee1, path_setnym_ini, setnym_ini_file): print(Ink.YELLOW('\n\n== Testing usage screed and data structures')) # Run setnym with no parameters to engage usage message sub_proc = subprocess.run([ 'python', join(dirname(dirname(dirname(realpath(__file__)))), 'von_anchor', 'op', 'setnym.py') ], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) assert sub_proc.returncode == 1 print('\n\n== 1 == Missing parameter invokes usage message OK') # Exercise namedtuples for syntax nodepool_data = NodePoolData('name', None) anchor_data = AnchorData('role', 'name', 'seed', 'did', 'wallet_create', 'wallet_type', 'wallet_access') print('\n\n== 2 == Data structures create OK')
def boot() -> None: """ Boot the service: instantiate tails server anchor. Raise AbsentPool if node pool ledger configuration neither present nor sufficiently specified; raise AbsentNym if tails server anchor nym is not on the ledger. """ config = do_wait(MEM_CACHE.get('config')) # setup pool and wallet pool_data = NodePoolData(config['Node Pool']['name'], config['Node Pool'].get('genesis.txn.path', None) or None) # nudge empty value from '' to None p_mgr = NodePoolManager() if pool_data.name not in do_wait(p_mgr.list()): if pool_data.genesis_txn_path: do_wait( p_mgr.add_config(pool_data.name, pool_data.genesis_txn_path)) else: LOGGER.debug( 'Node pool %s has no ledger configuration but %s specifies no genesis txn path', pool_data.name, do_wait(MEM_CACHE.get('config.ini'))) raise AbsentPool( 'Node pool {} has no ledger configuration but {} specifies no genesis txn path' .format(pool_data.name, do_wait(MEM_CACHE.get('config.ini')))) pool = p_mgr.get(pool_data.name) do_wait(pool.open()) do_wait(MEM_CACHE.set('pool', pool)) # instantiate tails server anchor tsan_data = AnchorData( Role.USER, config['VON Anchor']['name'], config['VON Anchor'].get('seed', None) or None, None, config['VON Anchor'].get('wallet.create', '0').lower() in ['1', 'true', 'yes'], config['VON Anchor'].get('wallet.type', None) or None, config['VON Anchor'].get('wallet.access', None) or None) w_mgr = WalletManager() wallet = None wallet_config = {'id': tsan_data.name} if tsan_data.wallet_type: wallet_config['storage_type'] = tsan_data.wallet_type if tsan_data.wallet_create: if tsan_data.seed: wallet_config['seed'] = tsan_data.seed try: wallet = do_wait( w_mgr.create(wallet_config, access=tsan_data.wallet_access)) LOGGER.info('Created wallet %s', tsan_data.name) except ExtantWallet: wallet = w_mgr.get(wallet_config, access=tsan_data.wallet_access) LOGGER.warning( 'Wallet %s already exists: remove seed and wallet.create from config file', tsan_data.name) else: wallet = w_mgr.get(wallet_config, access=tsan_data.wallet_access) do_wait(wallet.open()) tsan = NominalAnchor(wallet, pool) do_wait(tsan.open()) if not json.loads(do_wait(tsan.get_nym())): LOGGER.debug('Anchor %s has no cryptonym on ledger %s', tsan_data.wallet_name, pool_data.name) raise AbsentNym('Anchor {} has no cryptonym on ledger {}'.format( tsan_data.wallet_name, pool_data.name)) do_wait(MEM_CACHE.set('tsan', tsan))
async def setup(ini_path: str) -> tuple: """ Set configuration from file. If configured profile is issuer, open and return node pool and anchor, then register both for shutdown at program exit. :param ini_path: path to configuration file :return: tuple (profile, issuer anchor) for issuer or (profile, None) for prover. """ global CONFIG CONFIG = inis2dict(ini_path) profile = Profile.get(CONFIG['Tails Client']['profile']) if profile != Profile.ISSUER: return (profile, None) pool_data = NodePoolData(CONFIG['Node Pool']['name'], CONFIG['Node Pool'].get('genesis.txn.path', None) or None) # nudge empty value from '' to None # Set up node pool ledger config and wallet manager = NodePoolManager() if pool_data.name not in await manager.list(): if pool_data.genesis_txn_path: await manager.add_config(pool_data.name, pool_data.genesis_txn_path) else: logging.error( 'Node pool %s has no ledger configuration but %s specifies no genesis txn path', pool_data.name, ini_path) return (None, None) pool = manager.get(pool_data.name) await pool.open() atexit.register(close_pool, pool) noman_data = AnchorData( Role.USER, CONFIG['VON Anchor']['name'], CONFIG['VON Anchor'].get('seed', None) or None, None, CONFIG['VON Anchor'].get('wallet.create', '0').lower() in ['1', 'true', 'yes'], CONFIG['VON Anchor'].get('wallet.type', None) or None, CONFIG['VON Anchor'].get('wallet.access', None) or None) w_mgr = WalletManager() wallet = None wallet_config = {'id': noman_data.name} if noman_data.wallet_type: wallet_config['storage_type'] = noman_data.wallet_type if noman_data.wallet_create: if noman_data.seed: wallet_config['seed'] = noman_data.seed try: wallet = await w_mgr.create(wallet_config, access=noman_data.wallet_access) logging.info('Created wallet %s', noman_data.name) except ExtantWallet: wallet = w_mgr.get(wallet_config, access=noman_data.wallet_access) logging.warning( 'Wallet %s already exists: remove seed and wallet.create from config file', noman_data.name) else: wallet = w_mgr.get(wallet_config, access=noman_data.wallet_access) await wallet.open() noman = NominalAnchor(wallet, pool) await noman.open() atexit.register(close_anchor, noman) return (profile, noman)