From 703e17b694680a551caa49b0ca59a0fa48df43f4 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Mon, 21 Jun 2021 17:35:06 +0200
Subject: [PATCH] implemented set_token method

---
 pybis/src/python/pybis/pybis.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/pybis/src/python/pybis/pybis.py b/pybis/src/python/pybis/pybis.py
index d99b145240b..da2b1045d3b 100644
--- a/pybis/src/python/pybis/pybis.py
+++ b/pybis/src/python/pybis/pybis.py
@@ -988,6 +988,7 @@ class Openbis:
             'new_transaction()',
             'update_sample()',
             'update_object()', 
+            'set_token()',
         ]
 
     def _repr_html_(self):
@@ -3763,6 +3764,7 @@ class Openbis:
         """ checks whether a session is still active. Returns true or false.
         """
         return self.is_token_valid(self.token)
+        self._save_token(token)
 
     def is_token_valid(self, token=None):
         """Check if the connection to openBIS is valid.
@@ -3786,7 +3788,15 @@ class Openbis:
             return False
 
         return resp
-
+    
+    def set_token(self, token, save_token=True):
+        """Checks the validity of a token, sets it as the current token and (by default) saves it
+        to the disk, i.e. in the ~/.pybis directory
+        """
+        if not self.is_token_valid(token):
+            raise ValueError("session token seems not to be valid.")
+        
+        self._save_token(token=token)
 
     def get_dataset(self, permIds, only_data=False, props=None):
         """fetch a dataset and some metadata attached to it:
-- 
GitLab