From efe2c2c06f08b8b0782e5dc50c15c381631b568f Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Wed, 11 May 2022 16:25:05 +0200
Subject: [PATCH] Rename mdc_config to restful_config and add CalCat
 credentials

---
 README.rst                        |  4 ++--
 src/cal_tools/mdc_config.py       | 15 ---------------
 src/cal_tools/mdc_config.yaml     |  8 --------
 src/cal_tools/restful_config.py   | 15 +++++++++++++++
 src/cal_tools/restful_config.yaml | 20 ++++++++++++++++++++
 src/cal_tools/tools.py            |  3 ++-
 6 files changed, 39 insertions(+), 26 deletions(-)
 delete mode 100644 src/cal_tools/mdc_config.py
 delete mode 100644 src/cal_tools/mdc_config.yaml
 create mode 100644 src/cal_tools/restful_config.py
 create mode 100644 src/cal_tools/restful_config.yaml

diff --git a/README.rst b/README.rst
index 44369bdf1..e0217e1f0 100644
--- a/README.rst
+++ b/README.rst
@@ -110,7 +110,7 @@ The offline calibration package is configured with three configuration files:
 
 - `webservice/config/webservice.yaml` - configuration for the web service
 - `webservice/config/serve_overview.yaml` - configuration for the overview page
-- `src/cal_tools/mdc_config.yaml` - configuration for MDC access by cal tools
+- `src/cal_tools/restful_config.yaml` - configuration for RESTful access to myMDC and CalCat by cal tools
 
 These configuration files should not be modified directly, instead you should
 create a file `$CONFIG.secrets.yaml` (e.g. `webservice.secrets.yaml`) in the
@@ -131,7 +131,7 @@ tests in a CI environment. The environment variables should be prefixed with:
 
 - `webservice/config/webservice.yaml` - `CAL_WEBSERVICE`
 - `webservice/config/serve_overview.yaml` - `CAL_SERVE_OVERVIEW`
-- `src/cal_tools/mdc_config.yaml` - `CAL_CAL_TOOLS`
+- `src/cal_tools/restful_config.yaml` - `CAL_CAL_TOOLS`
 
 Followed by an underscore and the configuration key you wish to change. Nested
 keys can be accessed with two underscores, e.g.
diff --git a/src/cal_tools/mdc_config.py b/src/cal_tools/mdc_config.py
deleted file mode 100644
index 3c491e0ef..000000000
--- a/src/cal_tools/mdc_config.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from pathlib import Path
-
-from dynaconf import Dynaconf
-
-config_dir = Path(__file__).parent.resolve()
-
-mdc_config = Dynaconf(
-    envvar_prefix="CAL_CAL_TOOLS",
-    settings_files=[
-        config_dir / "mdc_config.yaml",
-        config_dir / "mdc_config.secrets.yaml",
-        Path("~/.config/pycalibration/cal_tools/mdc_config.yaml").expanduser(),
-    ],
-    merge_enabled=True,
-)
diff --git a/src/cal_tools/mdc_config.yaml b/src/cal_tools/mdc_config.yaml
deleted file mode 100644
index 923407bfb..000000000
--- a/src/cal_tools/mdc_config.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-auth-url: https://in.xfel.eu/metadata/oauth/authorize
-base-api-url: https://in.xfel.eu/metadata/api/
-refresh-url: https://in.xfel.eu/metadata/oauth/token
-scope: ''
-token-url: https://in.xfel.eu/metadata/oauth/token
-user-email: calibration@example.com
-user-id: '@note add this to secrets file'
-user-secret: '@note add this to secrets file'
diff --git a/src/cal_tools/restful_config.py b/src/cal_tools/restful_config.py
new file mode 100644
index 000000000..7a7944080
--- /dev/null
+++ b/src/cal_tools/restful_config.py
@@ -0,0 +1,15 @@
+from pathlib import Path
+
+from dynaconf import Dynaconf
+
+config_dir = Path(__file__).parent.resolve()
+
+restful_config = Dynaconf(
+    envvar_prefix="CAL_CAL_TOOLS",
+    settings_files=[
+        config_dir / "restful_config.yaml",
+        config_dir / "restful_config.secrets.yaml",
+        Path("~/.config/pycalibration/cal_tools/restful_config.yaml").expanduser(),
+    ],
+    merge_enabled=True,
+)
diff --git a/src/cal_tools/restful_config.yaml b/src/cal_tools/restful_config.yaml
new file mode 100644
index 000000000..813d1467d
--- /dev/null
+++ b/src/cal_tools/restful_config.yaml
@@ -0,0 +1,20 @@
+
+mdc:
+  auth-url: https://in.xfel.eu/metadata/oauth/authorize
+  base-api-url: https://in.xfel.eu/metadata/api/
+  refresh-url: https://in.xfel.eu/metadata/oauth/token
+  scope: ''
+  token-url: https://in.xfel.eu/metadata/oauth/token
+  user-email: calibration@example.com
+  user-id: '@note add this to secrets file'
+  user-secret: '@note add this to secrets file'
+
+calcat:
+  auth-url: https://in.xfel.eu/calibration/oauth/authorize
+  base-api-url: https://in.xfel.eu/calibration/api
+  refresh-url: https://in.xfel.eu/calibration/oauth/token
+  scope: ''
+  token-url: https://in.xfel.eu/calibration/oauth/token
+  user-email: calibration@example.com
+  user-id: '@note add this to secrets file'
+  user-secret: '@note add this to secrets file'
diff --git a/src/cal_tools/tools.py b/src/cal_tools/tools.py
index f8e316ccf..88a974c27 100644
--- a/src/cal_tools/tools.py
+++ b/src/cal_tools/tools.py
@@ -25,7 +25,7 @@ from metadata_client.metadata_client import MetadataClient
 from notebook.notebookapp import list_running_servers
 
 from .ana_tools import save_dict_to_hdf5
-from .mdc_config import mdc_config
+from .restful_config import restful_config
 
 
 def parse_runs(runs, return_type=str):
@@ -253,6 +253,7 @@ def get_run_info(proposal, run):
     :return: dictionary with run information
     """
 
+    mdc_config = restful_config['mdc']
     mdc = MetadataClient(
         client_id=mdc_config['user-id'],
         client_secret=mdc_config['user-secret'],
-- 
GitLab