adds a zonefile announce endpoint

This commit is contained in:
Aaron Blankstein
2017-12-22 16:21:32 -05:00
parent 29da3723d7
commit f6baa8d78c
2 changed files with 72 additions and 0 deletions

View File

@@ -1011,6 +1011,43 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
self._reply_json(resp, status_code=202)
return
def POST_raw_zonefile( self, ses, path_info ):
"""
Publish a zonefile which has *already* been announced.
Return 200 and {'status': True, 'servers': ...} on success
Return 401 when zonefile invalid with {'error': ...}
"""
request_schema = {
'type': 'object',
'properties': {
'zonefile': {
'type': 'string',
'maxLength': RPC_MAX_ZONEFILE_LEN
}
}
}
conf = blockstack_config.get_config(self.server.config_path)
server = (conf['server'], conf['port'])
request = self._read_json(schema=request_schema)
if request is None:
self._reply_json({"error": 'Invalid request'}, status_code=401)
return
elif 'error' in request:
self._reply_json({"error": request["error"]}, status_code=401)
return
zonefile_str = request.get('zonefile')
resp = zonefile.zonefile_data_publish(None, zonefile_str, [ server ])
status_code = 200
if 'error' in resp:
status_code = 401
self._reply_json(resp, status_code=status_code)
return
def PUT_name_zonefile( self, ses, path_info, name ):
"""
@@ -3271,6 +3308,20 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
},
},
},
r'^/v1/zonefile/': {
'routes': {
'POST' : self.POST_raw_zonefile
},
'whitelist': {
'POST': {
'name': 'zonefiles',
'desc': 'publish a zonefile',
'auth_session': False,
'auth_pass': False,
'need_data_key': False,
},
},
},
r'^/v1/names/({})/zonefile$'.format(NAME_CLASS): {
'routes': {
'GET': self.GET_name_zonefile,