def file_key_lookup( blockchain_id, index, hostname, key_id=None, config_path=CONFIG_PATH, wallet_keys=None ):
log.debug("<STR_LIT>" % (hostname, blockchain_id, index, key_id))<EOL>conf = get_config( config_path )<EOL>config_dir = os.path.dirname(config_path)<EOL>proxy = blockstack_client.get_default_proxy( config_path=config_path )<EOL>immutable = conf['<STR_LIT>']<EOL>if key_id is not None:<EOL><INDENT>hosts_listing = file_list_hosts( blockchain_id, wallet_keys=wallet_keys, config_path=config_path )<EOL>if '<STR_LIT:error>' in hosts_listing:<EOL><INDENT>log.error("<STR_LIT>" % (blockchain_id, hosts_listing['<STR_LIT:error>']))<EOL>return {'<STR_LIT:error>': '<STR_LIT>'}<EOL><DEDENT>hosts = hosts_listing['<STR_LIT>']<EOL>for hostname in hosts:<EOL><INDENT>file_key = blockstack_gpg.gpg_app_get_key( blockchain_id, APP_NAME, hostname, immutable=immutable, key_id=key_id, config_dir=config_dir )<EOL>if '<STR_LIT:error>' not in file_key:<EOL><INDENT>if key_id == file_key['<STR_LIT>']:<EOL><INDENT>return file_key<EOL><DEDENT><DEDENT><DEDENT>url = file_url_expired_keys( blockchain_id )<EOL>old_key_bundle_res = blockstack_client.data_get( url, wallet_keys=wallet_keys, proxy=proxy )<EOL>if '<STR_LIT:error>' in old_key_bundle_res:<EOL><INDENT>return old_key_bundle_res<EOL><DEDENT>old_key_list = old_key_bundle_res['<STR_LIT:data>']['<STR_LIT>']<EOL>for i in range(<NUM_LIT:0>, len(old_key_list)):<EOL><INDENT>old_key = old_key_list[i]<EOL>if old_key['<STR_LIT>'] == key_id:<EOL><INDENT>ret = {}<EOL>ret.update( old_key )<EOL>ret['<STR_LIT>'] = i+<NUM_LIT:1> <EOL>return old_key<EOL><DEDENT><DEDENT>return {'<STR_LIT:error>': '<STR_LIT>' % key_id}<EOL><DEDENT>elif index == <NUM_LIT:0>:<EOL><INDENT>file_key = blockstack_gpg.gpg_app_get_key( blockchain_id, APP_NAME, hostname, immutable=immutable, key_id=key_id, config_dir=config_dir )<EOL>if '<STR_LIT:error>' in file_key:<EOL><INDENT>return file_key<EOL><DEDENT>return file_key<EOL><DEDENT>else:<EOL><INDENT>url = file_url_expired_keys( blockchain_id )<EOL>old_key_bundle_res = blockstack_client.data_get( url, wallet_keys=wallet_keys, proxy=proxy )<EOL>if '<STR_LIT:error>' in old_key_bundle_res:<EOL><INDENT>return old_key_bundle_res<EOL><DEDENT>old_key_list = old_key_bundle_res['<STR_LIT:data>']['<STR_LIT>']<EOL>if index >= len(old_key_list)+<NUM_LIT:1>:<EOL><INDENT>return {'<STR_LIT:error>': '<STR_LIT>' % index}<EOL><DEDENT>return old_key_list[index-<NUM_LIT:1>]<EOL><DEDENT>
Get the file-encryption GPG key for the given blockchain ID, by index.

if index == 0, then give back the current key
if index > 0, then give back an older (revoked) key.
if key_id is given, index and hostname will be ignored

Return {'status': True, 'key_data': ..., 'key_id': key_id, OPTIONAL['stale_key_index': idx]} on success
Return {'error': ...} on failure