From 5cdb36f3f1b92e9bbf571ad0eca0177657f14cbd Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Tue, 10 Apr 2018 17:08:39 +0200 Subject: [PATCH] prevent non-https connections. Always try to use the token in the environment variable --- src/python/PyBis/pybis/__init__.py | 2 +- src/python/PyBis/pybis/pybis.py | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/python/PyBis/pybis/__init__.py b/src/python/PyBis/pybis/__init__.py index 435ad8b1b03..0a23ea22f9b 100644 --- a/src/python/PyBis/pybis/__init__.py +++ b/src/python/PyBis/pybis/__init__.py @@ -1,6 +1,6 @@ __author__ = 'Swen Vermeul' __email__ = 'swen@ethz.ch' -__version__ = '0.3.0' +__version__ = '1.6.0' from . import pybis from .pybis import Openbis diff --git a/src/python/PyBis/pybis/pybis.py b/src/python/PyBis/pybis/pybis.py index 3c3473740cb..5d1520d535b 100644 --- a/src/python/PyBis/pybis/pybis.py +++ b/src/python/PyBis/pybis/pybis.py @@ -477,13 +477,23 @@ class Openbis: except KeyError: raise ValueError("please provide a URL you want to connect to.") + else: + # url has been provided. If the environment variable OPENBIS_URL points to the same URL, + # use the OPENBIS_TOKEN as well. + if 'OPENBIS_URL' in os.environ: + if url == os.environ["OPENBIS_URL"]: + token = os.environ["OPENBIS_TOKEN"] if "OPENBIS_TOKEN" in os.environ else None + + url_obj = urlparse(url) - if url_obj.netloc is None: + if url_obj.netloc is None or url_obj.netloc == '': raise ValueError("please provide the url in this format: https://openbis.host.ch:8443") if url_obj.hostname is None: raise ValueError("hostname is missing") - - + if url_obj.scheme == 'http': + raise ValueError("always use https!") + + self.url = url_obj.geturl() self.port = url_obj.port self.hostname = url_obj.hostname @@ -2128,9 +2138,14 @@ class Openbis: "method": "isSessionActive", "params": [token], } - resp = self._post_request(self.as_v1, request) + try: + resp = self._post_request(self.as_v1, request) + except Exception as e: + return False + return resp + def get_dataset(self, permid, only_data=False): """fetch a dataset and some metadata attached to it: - properties @@ -2459,8 +2474,6 @@ class PhysicalData(): return tabulate(lines, headers=headers) - - class ExternalDMS(): """ managing openBIS external data management systems """ -- GitLab