glygener / glygen-issues

Repository for public GlyGen tickets
GNU General Public License v3.0
0 stars 0 forks source link

Breaking BCODB API Change #1375

Open HadleyKing opened 1 month ago

HadleyKing commented 1 month ago

When I was doing the API code refactor I noticed that the GET request to retrieve a single BCO was returning a list. So I changed the response to return a single object.

I did not realize that our database creators were relying on this one endpoint. I had asked about what the APIs being used were but did not follow up when I did not get any responses.

Anyway Sean has identified the fix (about 10 min after identifying the problem) and it's pretty simple.

dataset-maker/check_bco_sanity.py line 145 and object-maker/make-bcodb.py line 46 change bco_obj_list = json.loads(cn) bco_doc = bco_obj_list[0] to bco_obj_list = json.loads(cn) bco_doc = bco_obj_list

HadleyKing commented 1 month ago

We have implemented the use of https://docs.python.org/3/library/configparser.html and a .secrets for the authentication token required to access protected BCOs

#!/usr/bin/python
# object=-maker/make-bcodb.py
...

secrets = configparser.ConfigParser()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
secrets.read(BASE_DIR + "/.secrets")
api_token = secrets["ARGOS_KEYS"]["API_TOKEN"]

....

    for obj in bco_list:
        url = "https://biocomputeobject.org/%s/%s" % (obj["bcoid"], obj["bcoversion"])

       headers = {
            'Authorization': f'Token {api_token}',
            "accept": "application/json"
        }

        res = requests.get(url, headers=headers)

        if str(res.content).find("No object") != -1:
            print (url.split("/")[-1], bco2filename[obj["bcoid"]], "failed", "getting response")
            continue
        cn = res.content
        bco_obj_list = json.loads(cn)
        bco_doc = bco_obj_list
        bco_id = bco_doc["object_id"].split("/")[-2]
        if bco_id != obj["bcoid"]:
            print ("BCO ID mismatch for: (%s,%s)" % (obj["bcoid"], bco_id))
            exit()