mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-23 19:31:00 +08:00
always return the raw zone file and name record when looking up a zone file
This commit is contained in:
@@ -178,16 +178,13 @@ def decode_name_zonefile(name, zonefile_txt, allow_legacy=False):
|
||||
return user_zonefile
|
||||
|
||||
|
||||
def load_name_zonefile(name, expected_zonefile_hash, storage_drivers=None, raw_zonefile=False, allow_legacy=False, proxy=None ):
|
||||
def load_name_zonefile(name, expected_zonefile_hash, storage_drivers=None, proxy=None ):
|
||||
"""
|
||||
Fetch and load a user zonefile from the storage implementation with the given hex string hash,
|
||||
Fetch and load a raw user zonefile from the storage implementation with the given hex string hash,
|
||||
The user zonefile hash should have been loaded from the blockchain, and thereby be the
|
||||
authentic hash.
|
||||
|
||||
If raw_zonefile is True, then return the raw zonefile data. Don't parse it.
|
||||
If however, raw_zonefile is False, the zonefile will be parsed. If name is given, the $ORIGIN will be checked.
|
||||
|
||||
Return the user zonefile (as a dict) on success
|
||||
Return the raw user zonefile (as a string)
|
||||
Return None on error
|
||||
"""
|
||||
|
||||
@@ -222,21 +219,17 @@ def load_name_zonefile(name, expected_zonefile_hash, storage_drivers=None, raw_z
|
||||
log.debug('Fetched {} from Atlas peer {}'.format(expected_zonefile_hash, hostport))
|
||||
zonefile_txt = res['zonefiles'][expected_zonefile_hash]
|
||||
|
||||
if raw_zonefile:
|
||||
try:
|
||||
assert isinstance(zonefile_txt, (str, unicode)), msg
|
||||
except AssertionError as ae:
|
||||
if BLOCKSTACK_TEST is not None:
|
||||
log.exception(ae)
|
||||
|
||||
msg = 'Driver did not return a serialized zonefile'
|
||||
try:
|
||||
assert isinstance(zonefile_txt, (str, unicode)), msg
|
||||
except AssertionError as ae:
|
||||
if BLOCKSTACK_TEST is not None:
|
||||
log.exception(ae)
|
||||
log.error(msg)
|
||||
return None
|
||||
|
||||
log.error(msg)
|
||||
return None
|
||||
|
||||
return zonefile_txt
|
||||
|
||||
parsed_zonefile = decode_name_zonefile(name, zonefile_txt, allow_legacy=allow_legacy)
|
||||
return parsed_zonefile
|
||||
return zonefile_txt
|
||||
|
||||
|
||||
def load_data_pubkey_for_new_zonefile(wallet_keys={}, config_path=CONFIG_PATH):
|
||||
@@ -258,22 +251,14 @@ def load_data_pubkey_for_new_zonefile(wallet_keys={}, config_path=CONFIG_PATH):
|
||||
|
||||
|
||||
def get_name_zonefile(name, storage_drivers=None, proxy=None,
|
||||
name_record=None, include_name_record=False,
|
||||
raw_zonefile=False, include_raw_zonefile=False, allow_legacy=False):
|
||||
name_record=None, allow_legacy=False):
|
||||
"""
|
||||
Given a name, go fetch its zonefile.
|
||||
Verifies that the hash on the blockchain matches the zonefile.
|
||||
|
||||
Returns {'status': True, 'zonefile': zonefile dict} on success.
|
||||
Returns a dict with "error" defined and a message on failure to load.
|
||||
Return None if there is no zonefile (i.e. the hash is null)
|
||||
Returns {'status': True, 'zonefile': zonefile dict (if well-formed, otherwise None), 'raw_zonefile': raw bytes, 'name_record': bns name record} on success.
|
||||
Return {'error': ...} if we failed to load the zone file
|
||||
|
||||
if 'include_name_record' is true, then zonefile will contain
|
||||
an extra key called 'name_record' that includes the blockchain name record.
|
||||
|
||||
If 'raw_zonefile' is true, no attempt to parse the zonefile will be made.
|
||||
The raw zonefile will be returned in 'zonefile'. allow_legacy is ignored.
|
||||
|
||||
If 'allow_legacy' is true, then support returning older supported versions of the zone file
|
||||
(including old Onename profiles). Otherwise, this method fails.
|
||||
"""
|
||||
@@ -303,41 +288,19 @@ def get_name_zonefile(name, storage_drivers=None, proxy=None,
|
||||
raw_zonefile_data = None
|
||||
user_zonefile_data = None
|
||||
|
||||
if raw_zonefile or include_raw_zonefile:
|
||||
raw_zonefile_data = load_name_zonefile(
|
||||
name, user_zonefile_hash, storage_drivers=storage_drivers,
|
||||
raw_zonefile=True, proxy=proxy, allow_legacy=allow_legacy
|
||||
)
|
||||
raw_zonefile_data = load_name_zonefile(name, user_zonefile_hash, storage_drivers=storage_drivers, proxy=proxy)
|
||||
if raw_zonefile_data is None:
|
||||
return {'error': 'Failed to load raw name zonefile'}
|
||||
|
||||
if raw_zonefile_data is None:
|
||||
return {'error': 'Failed to load raw name zonefile'}
|
||||
|
||||
if raw_zonefile:
|
||||
user_zonefile_data = raw_zonefile_data
|
||||
|
||||
else:
|
||||
# further decode
|
||||
user_zonefile_data = decode_name_zonefile(name, raw_zonefile_data, allow_legacy=allow_legacy)
|
||||
if user_zonefile_data is None:
|
||||
return {'error': 'Failed to decode name zonefile'}
|
||||
|
||||
else:
|
||||
user_zonefile_data = load_name_zonefile(
|
||||
name, user_zonefile_hash, storage_drivers=storage_drivers, proxy=proxy, allow_legacy=allow_legacy
|
||||
)
|
||||
if user_zonefile_data is None:
|
||||
return {'error': 'Failed to load or decode name zonefile'}
|
||||
# further decode (it's okay if this is None)
|
||||
user_zonefile_data = decode_name_zonefile(name, raw_zonefile_data, allow_legacy=allow_legacy)
|
||||
|
||||
ret = {
|
||||
'zonefile': user_zonefile_data
|
||||
'zonefile': user_zonefile_data,
|
||||
'raw_zonefile': raw_zonefile_data,
|
||||
'name_record': name_record,
|
||||
}
|
||||
|
||||
if include_name_record:
|
||||
ret['name_record'] = name_record
|
||||
|
||||
if include_raw_zonefile:
|
||||
ret['raw_zonefile'] = raw_zonefile_data
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user