def get_cached_zonefile( zonefile_hash, zonefile_dir=None ): """ Get a cached zonefile from local disk Return None if not found """ if zonefile_dir is None: zonefile_dir = get_zonefile_dir() zonefile_path = os.path.join( zonefile_dir, zonefile_hash ) if not os.path.exists( zonefile_path ): return None with open(zonefile_path, "r") as f: data = f.read() # sanity check if not verify_zonefile( data, zonefile_hash ): log.debug("Corrupt zonefile '%s'; uncaching" % zonefile_hash) remove_cached_zonefile( zonefile_hash, zonefile_dir=zonefile_dir ) return None try: zonefile_dict = blockstack_zones.parse_zone_file( data ) assert blockstack_client.is_user_zonefile( zonefile_dict ), "Not a user zonefile: %s" % zonefile_hash return zonefile_dict except Exception, e: log.error("Failed to parse zonefile") return None
def get_zonefile_from_storage(zonefile_hash, drivers=None): """ Get a zonefile from our storage drivers. Return the zonefile dict on success. Raise on error """ if not is_current_zonefile_hash(zonefile_hash): raise Exception("Unknown zonefile hash") zonefile_txt = blockstack_client.storage.get_immutable_data( zonefile_hash, hash_func=blockstack_client.get_blockchain_compat_hash, deserialize=False, drivers=drivers) if zonefile_txt is None: raise Exception("Failed to get data") # verify if blockstack_client.storage.get_zonefile_data_hash( zonefile_txt) != zonefile_hash: raise Exception("Corrupt zonefile: %s" % zonefile_hash) # parse try: user_zonefile = blockstack_zones.parse_zone_file(zonefile_txt) assert blockstack_client.is_user_zonefile( user_zonefile), "Not a user zonefile: %s" % zonefile_hash except AssertionError, ValueError: raise Exception("Failed to load zonefile %s" % zonefile_hash)
def get_cached_zonefile(zonefile_hash, zonefile_dir=None): """ Get a cached zonefile from local disk Return None if not found """ if zonefile_dir is None: zonefile_dir = get_zonefile_dir() zonefile_path = os.path.join(zonefile_dir, zonefile_hash) if not os.path.exists(zonefile_path): return None with open(zonefile_path, "r") as f: data = f.read() # sanity check if not verify_zonefile(data, zonefile_hash): log.debug("Corrupt zonefile '%s'; uncaching" % zonefile_hash) remove_cached_zonefile(zonefile_hash, zonefile_dir=zonefile_dir) return None try: zonefile_dict = blockstack_zones.parse_zone_file(data) assert blockstack_client.is_user_zonefile( zonefile_dict), "Not a user zonefile: %s" % zonefile_hash return zonefile_dict except Exception, e: log.error("Failed to parse zonefile") return None
def get_cached_zonefile( zonefile_hash, zonefile_dir=None ): """ Get a cached zonefile dict from local disk Return None if not found """ data = get_cached_zonefile_data( zonefile_hash, zonefile_dir=zonefile_dir ) if data is None: return None try: zonefile_dict = blockstack_zones.parse_zone_file( data ) assert blockstack_client.is_user_zonefile( zonefile_dict ), "Not a user zonefile: %s" % zonefile_hash return zonefile_dict except Exception, e: log.error("Failed to parse zonefile") return None
def get_cached_zonefile( zonefile_hash, zonefile_dir=None ): """ Get a cached zonefile dict from local disk Return None if not found """ data = get_cached_zonefile_data( zonefile_hash, zonefile_dir=zonefile_dir ) if data is None: return None try: zonefile_dict = blockstack_zones.parse_zone_file( data ) assert blockstack_client.is_user_zonefile( zonefile_dict ), "Not a user zonefile: %s" % zonefile_hash return zonefile_dict except Exception, e: log.error("Failed to parse zonefile") return None
def get_zonefile_from_storage( zonefile_hash, drivers=None ): """ Get a zonefile from our storage drivers. Return the zonefile dict on success. Raise on error """ if not is_current_zonefile_hash( zonefile_hash ): raise Exception("Unknown zonefile hash") zonefile_txt = blockstack_client.storage.get_immutable_data( zonefile_hash, hash_func=blockstack_client.get_blockchain_compat_hash, deserialize=False, drivers=drivers ) if zonefile_txt is None: raise Exception("Failed to get data") # verify if blockstack_client.storage.get_zonefile_data_hash( zonefile_txt ) != zonefile_hash: raise Exception("Corrupt zonefile: %s" % zonefile_hash) # parse try: user_zonefile = blockstack_zones.parse_zone_file( zonefile_txt ) assert blockstack_client.is_user_zonefile( user_zonefile ), "Not a user zonefile: %s" % zonefile_hash except AssertionError, ValueError: raise Exception("Failed to load zonefile %s" % zonefile_hash)