Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions bam_masterdata/openbis/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@


# Connect to openBIS
def ologin(url: str = "") -> Openbis:
def ologin(url: str | Openbis = "") -> Openbis:
"""
Connect to openBIS using the credentials stored in the environment variables.

If an existing Openbis session is provided, the session is returned.

Args:
url (str): The URL of the openBIS instance. Defaults to the value of the `OPENBIS_URL` environment variable.
url (str, Openbis): The URL of the openBIS instance. Defaults to the value of the `OPENBIS_URL` environment variable.
An existing Openbis session can be provided.

Returns:
Openbis: Openbis object for the specific openBIS instance defined in `URL`.
"""
o = Openbis(url)
o.login(environ("OPENBIS_USERNAME"), environ("OPENBIS_PASSWORD"), save_token=True)
if not isinstance(url, Openbis):
o = Openbis(url)

if not o.is_session_activ():
o.login(environ("OPENBIS_USERNAME"), environ("OPENBIS_PASSWORD"), save_token=True)

return o