Skip to content

Commit

Permalink
Merge pull request #4 from BAMresearch/main
Browse files Browse the repository at this point in the history
added input flexibility in ScicatClient. Now can use either token or credentials in ScicatClient initialisation
  • Loading branch information
dylanmcreynolds authored Jan 21, 2022
2 parents e3014ca + f5e4d6a commit 37fdcb6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyscicat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 37fdcb6

Please sign in to comment.