From c92bc87295a88ff23095bf6dec8f1c0cc6e34419 Mon Sep 17 00:00:00 2001 From: "Prof. Dr. Matthias Jung DL9MJ" Date: Fri, 16 May 2025 00:19:56 +0200 Subject: [PATCH] feature: add config --- api/config.py | 30 ++++++++++++++++++++++++++++++ config/config.json.example | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 api/config.py create mode 100644 config/config.json.example diff --git a/api/config.py b/api/config.py new file mode 100644 index 0000000..8705346 --- /dev/null +++ b/api/config.py @@ -0,0 +1,30 @@ +import json +import os + + +class Config: + + def __init__(self): + + self.access_token = None + + if os.path.isfile("config/config.json") : + with open ("config/config.json") as fh: + config_doc = json.load(fh) + self.access_token = config_doc["key"] + elif 'DIRECTUS_API_KEY' in os.environ.keys(): + self.access_token = os.environ['DIRECTUS_API_KEY'] + else: + raise Exception("ERROR: Cannot find API key in config or environment!") + + if 'DIRECTUS_BASEURL' in os.environ.keys(): + self.base_url = os.environ['DIRECTUS_BASEURL'] + else: + self.base_url = "https://fragenkatalog.darc.de/" + + if not self.access_token: + raise Exception("ERROR: Cannot find API key in config or environment!") + + + + diff --git a/config/config.json.example b/config/config.json.example new file mode 100644 index 0000000..e9bd579 --- /dev/null +++ b/config/config.json.example @@ -0,0 +1,3 @@ +{ + "key" : "INSERTKEYHERE" +}