about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/load_phenotypes_to_db.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py
index e303bb3..9b70fed 100644
--- a/scripts/load_phenotypes_to_db.py
+++ b/scripts/load_phenotypes_to_db.py
@@ -5,7 +5,6 @@ import json
 import time
 import logging
 import argparse
-import datetime
 from pathlib import Path
 from zipfile import ZipFile
 from typing import Any, Iterable
@@ -198,13 +197,14 @@ save_phenotypes_n = partial(save_numeric_data,
 
 
 def update_auth(# pylint: disable=[too-many-locals,too-many-positional-arguments,too-many-arguments]
-        authserver,
-        token,
+        auth_details,
+        resource_details,
         species,
         population,
         dataset,
         xrefdata):
     """Grant the user access to their data."""
+    authserver, token = auth_details
     _tries = 0
     _delay = 1
     headers = {
@@ -259,14 +259,12 @@ def update_auth(# pylint: disable=[too-many-locals,too-many-positional-arguments
 
     def __create_resource__(user, linkeddata, category):
         logger.debug("… creating authorisation resource object")
-        now = datetime.datetime.now().isoformat()
         return mrequests.post(
             authserveruri("/auth/resource/create"),
             headers=headers,
             json={
+                **resource_details,
                 "resource_category": category["resource_category_id"],
-                "resource_name": (f"{user['email']}—{dataset['Name']}—{now}—"
-                                  f"{len(xrefdata)} phenotypes"),
                 "public": "off"
             }).then(lambda cr_results: (user, linkeddata, cr_results))
 
@@ -516,8 +514,23 @@ if __name__ == "__main__":
         # Update authorisations (break this down) — maybe loop until it works?
         logger.info("Updating authorisation.")
         _job_metadata = job["metadata"]
-        return update_auth(_job_metadata["authserver"],
-                           _job_metadata["token"],
+
+        def __parse_resource_details__(meta) -> dict:
+            _key_mappings_ = {
+                "data_description": "description",
+            }
+            return {
+                "resource_name": _job_metadata["dataname"],
+                "resource_metadata": {
+                    rkey: meta[mkey]
+                    for mkey, rkey in _key_mappings_.items()
+                    if mkey in meta
+                }
+            }
+
+        return update_auth((_job_metadata["authserver"],
+                            _job_metadata["token"]),
+                           __parse_resource_details__(_job_metadata),
                            *db_results)