From 0dae9d0b658f81636a26b6da1ed9cf48a4aac992 Mon Sep 17 00:00:00 2001
From: Eloy Retamino <retamino@ugr.es>
Date: Fri, 16 Oct 2020 14:07:58 +0200
Subject: [PATCH] [NUIT-213] removed proxy from config file, server address is
 explicitly passed to the VC constructor now; added rosbridge to
 proxy-services; config.json is part of the repository now, not copied from
 user-scripts

---
 .gitignore                                    |  3 --
 .../hbp_nrp_virtual_coach/config.json         | 54 +++++++++++++++++++
 .../hbp_nrp_virtual_coach/config.py           |  3 +-
 .../hbp_nrp_virtual_coach/virtual_coach.py    | 10 ++--
 4 files changed, 59 insertions(+), 11 deletions(-)
 create mode 100644 hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.json

diff --git a/.gitignore b/.gitignore
index 1e04ad8..bdab4a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,8 +20,5 @@ coverage.xml
 .pydevproject
 user_makefile
 
-# Config is updated in user-scripts
-hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.json*
-
 # Ignore Jupyter Notebook checkpoints for examples
 examples/**/.ipynb_checkpoints/
diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.json b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.json
new file mode 100644
index 0000000..f59b8a1
--- /dev/null
+++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.json
@@ -0,0 +1,54 @@
+{
+    "oidc": {
+        "user": "https://services.humanbrainproject.eu/idm/v1/api/user"
+    },
+
+    "proxy-services": {
+        "experiment-list": "experiments",
+        "available-servers": "availableServers",
+        "server-info": "server",
+        "experiment-clone": "storage/clone",
+        "experiment-delete": "storage/",
+        "experiment-import": "storage/importExperiment",
+        "storage-authentication": "authentication/authenticate",
+        "storage-experiment-list": "storage/experiments",
+        "csv-files": "experiment/%s/csvfiles",
+        "experiment-file": "storage/%s/%s",
+        "save-data": "experiment",
+        "rosbridge": "rosbridge"
+    },
+
+    "proxy-save": {
+        "transfer-function": "transferFunctions",
+        "state-machine": "stateMachines",
+        "brain": "brain"
+     },
+
+    "simulation-services": {
+        "create": "simulation",
+        "state": "state",
+        "reset": "reset",
+        "csv-recorders": "csv-recorders",
+        "recorder": "recorder"
+    },
+
+    "simulation-scripts": {
+        "transfer-function": "transfer-functions",
+        "state-machine": "state-machines",
+        "brain": "brain",
+        "populations": "populations",
+        "sdf-world": "sdf_world"
+    },
+
+    "reset-services": {
+        "robot_pose": 0,
+        "full": 1,
+        "world": 2,
+        "brain": 3
+    },
+
+    "ros": {
+        "status": "/ros_cle_simulation/status",
+        "error": "/ros_cle_simulation/cle_error"
+    }
+}
diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.py
index 268adb5..a5ecf75 100644
--- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.py
+++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/config.py
@@ -87,7 +87,6 @@ class Config(dict):
 
         # validate required sections of the config, except if any values are missing
         self.__validate('oidc', ['user'])
-        self.__validate('proxy', ['staging', 'dev', 'local', environment])
         self.__validate('proxy-services', ['experiment-list', 'available-servers', 'server-info',
                                            'experiment-clone', 'experiment-delete',
                                            'storage-authentication', 'storage-experiment-list',
@@ -101,7 +100,7 @@ class Config(dict):
         # convenience, prepend the proxy url to all proxy services, we cannot do this
         # for the simulation services because they are backend/experiment id specific
         for k, v in self['proxy-services'].items():
-            self['proxy-services'][k] = '%s/%s' % (self['proxy'][environment], v)
+            self['proxy-services'][k] = '{}/proxy/{}'.format(environment, v)
 
     def __validate(self, key, values):
         """
diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
index a933426..701e1ac 100644
--- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
+++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
@@ -71,18 +71,16 @@ class VirtualCoach(object):
     view available experiments, query currently running experiments, launch a simulation, and more.
     """
 
-    def __init__(self, environment=None, oidc_username=None, oidc_password=None, oidc_token=None,
-                 storage_username=None, storage_password=None):
+    def __init__(self, environment='http://localhost:9000', oidc_username=None, oidc_password=None,
+                 oidc_token=None, storage_username=None, storage_password=None):
         """
         Instantiates the Virtual Coach by loading the configuration file and logging into OIDC for
         the given user. This will only fail if the config file is invalid or if the user
         credentials are incorrect. The user will be prompted to provide a password if they have not
         logged in recently.
 
-        :param environment: (optional) A string representing the backend server environment to
-                            target. The default value will be based on this package release version,
-                            but the user can supply custom backends in their config.json by adding
-                            a key/value pair to the "proxy" section.
+        :param environment: (optional) A string containing the http address of the server running
+                            the NRP. The default value is localhost:9000
         :param oidc_username: (optional) A string representing the OIDC username for the current
                               user, required if the provided environment requires OIDC
                               authentication and no token is provided.
-- 
GitLab