Refactor looking up SIG reference details into a common location, taking it out of the individual spot providers. This means we can now look up references properly from Cluster spot comments, etc. Closes #74 as there is no longer any duplication of these lookups. Works towards #54 as sig_refs now specify their sig internally.

This commit is contained in:
Ian Renton
2025-11-02 15:45:19 +00:00
parent 28010a68ae
commit 286ff66721
22 changed files with 192 additions and 233 deletions

View File

@@ -106,29 +106,28 @@ class WebServer:
try:
# Reject if no sig or sig_ref
query = bottle.request.query
if not "sig" in query.keys() or not "sig_ref_id" in query.keys():
if not "sig" in query.keys() or not "id" in query.keys():
response.content_type = 'application/json'
response.status = 422
return json.dumps("Error - sig and sig_ref_id must be provided", default=serialize_everything)
return json.dumps("Error - sig and id must be provided", default=serialize_everything)
sig = query.get("sig").upper()
id = query.get("id").upper()
# Reject if sig unknown
if not sig in list(map(lambda p: p.name, SIGS)):
response.content_type = 'application/json'
response.status = 422
return json.dumps("Error - sig '" + sig + "' is not known.", default=serialize_everything)
# Reject if sig_ref format incorrect for sig
sig = query.get("sig")
sig_ref_id = query.get("sig_ref_id")
if get_ref_regex_for_sig(sig) and not re.match(get_ref_regex_for_sig(sig), sig_ref_id):
if get_ref_regex_for_sig(sig) and not re.match(get_ref_regex_for_sig(sig), id):
response.content_type = 'application/json'
response.status = 422
return json.dumps("Error - '" + sig_ref_id + "' does not look like a valid reference for " + sig + ".", default=serialize_everything)
return json.dumps("Error - '" + id + "' does not look like a valid reference ID for " + sig + ".", default=serialize_everything)
data = get_sig_ref_info(sig, sig_ref_id)
# 404 if we don't have any data
if not data:
response.content_type = 'application/json'
response.status = 404
return json.dumps("Error - could not find any data for this reference.", default=serialize_everything)
# Return success
data = get_sig_ref_info(sig, id)
return self.serve_api(data)
except Exception as e:
logging.error(e)
response.content_type = 'application/json'