Skip to content

Commit

Permalink
airtable readonly api key is now easier to maintain
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelduranfrigola committed Oct 10, 2022
1 parent 7e7a674 commit 9767a3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/read_only_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"AIRTABLE_READONLY_API_KEY": "keyVMAlJFOvu7vgMR"
}
2 changes: 1 addition & 1 deletion ersilia/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 8 additions & 3 deletions ersilia/hub/content/card.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import json
import collections
import tempfile
import requests
from pyairtable import Table
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9767a3f

Please sign in to comment.