From f5e4d6a1dff40dd9315f1fe737d37f3831886c7c Mon Sep 17 00:00:00 2001 From: Brian Richard Pauw Date: Fri, 21 Jan 2022 15:04:27 +0100 Subject: [PATCH] added input flexibility in ScicatClient --- pyscicat/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyscicat/client.py b/pyscicat/client.py index f3397ac..017c3d6 100644 --- a/pyscicat/client.py +++ b/pyscicat/client.py @@ -40,8 +40,8 @@ class ScicatClient: def __init__( self, - base_url: str, - token: str, + base_url: str = None, + token: str = False, username: str = None, password: str = None, timeout_seconds: int = None, @@ -67,11 +67,15 @@ def __init__( self._username = username # default username self._password = password # default password self._token = token # store token here + assert self._base_url is not None, "SciCat database URL must be provided" logger.info(f"Starting ingestor talking to scicat at: {self._base_url}") if not self._token: - self._get_token() + assert (self._username is not None) and ( + self._password is not None + ), "SciCat login credentials (username, password) must be provided if token is not provided" + self._token = get_token(self._base_url, self._username, self._password) def _send_to_scicat(self, url, dataDict=None, cmd="post"): """sends a command to the SciCat API server using url and token, returns the response JSON