From 9767a3f93213f57d28b85e958a71d3a4b2e94162 Mon Sep 17 00:00:00 2001 From: miquelduranfrigola Date: Mon, 10 Oct 2022 10:28:58 +0200 Subject: [PATCH] airtable readonly api key is now easier to maintain --- config/read_only_keys.json | 3 +++ ersilia/default.py | 2 +- ersilia/hub/content/card.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 config/read_only_keys.json diff --git a/config/read_only_keys.json b/config/read_only_keys.json new file mode 100644 index 000000000..18f567bb4 --- /dev/null +++ b/config/read_only_keys.json @@ -0,0 +1,3 @@ +{ + "AIRTABLE_READONLY_API_KEY": "keyVMAlJFOvu7vgMR" +} \ No newline at end of file diff --git a/ersilia/default.py b/ersilia/default.py index 69459a29b..cdc896b1c 100644 --- a/ersilia/default.py +++ b/ersilia/default.py @@ -46,7 +46,7 @@ FEATURE_MERGE_PATTERN = "---" # Airtable -AIRTABLE_READONLY_API_KEY = "keycTTh5uQ7v2CPbI" +AIRTABLE_READONLY_API_KEY = "keyVMAlJFOvu7vgMR" AIRTABLE_MODEL_HUB_BASE_ID = "appgxpCzCDNyGjWc8" AIRTABLE_MODEL_HUB_TABLE_NAME = "Models" diff --git a/ersilia/hub/content/card.py b/ersilia/hub/content/card.py index a5a2f1de2..2e577eea4 100644 --- a/ersilia/hub/content/card.py +++ b/ersilia/hub/content/card.py @@ -1,6 +1,5 @@ import os import json -import collections import tempfile import requests from pyairtable import Table @@ -14,7 +13,6 @@ Hdf5Explorer = None from ...default import ( - AIRTABLE_READONLY_API_KEY, AIRTABLE_MODEL_HUB_BASE_ID, AIRTABLE_MODEL_HUB_TABLE_NAME, ISAURA_DIR, @@ -101,13 +99,20 @@ def get(self, model_id): class AirtableCard(ErsiliaBase): def __init__(self, config_json): ErsiliaBase.__init__(self, config_json=config_json) - self.api_key = AIRTABLE_READONLY_API_KEY + self.api_key = self._get_read_only_airtable_api_key() self.base_id = AIRTABLE_MODEL_HUB_BASE_ID self.table_name = AIRTABLE_MODEL_HUB_TABLE_NAME self.max_rows = AIRTABLE_MAX_ROWS self.page_size = AIRTABLE_PAGE_SIZE self.table = Table(self.api_key, self.base_id, self.table_name) + @staticmethod + def _get_read_only_airtable_api_key(): + url = "https://raw.githubusercontent.com/ersilia-os/ersilia/config/read_only_keys.json" + r = requests.get(url) + data = r.json() + return data["AIRTABLE_READONLY_API_KEY"] + def _find_card(self, text, field): card = None for records in self.table.iterate(