From 21a481cdaa25ed8489eabbb22aa64a7d3d8aad7c Mon Sep 17 00:00:00 2001 From: Kevin De Pelseneer Date: Thu, 21 Nov 2024 16:26:16 +0100 Subject: [PATCH] Implement in submission function --- mars-cli/mars_cli.py | 12 +++++++++--- mars-cli/mars_lib/submit.py | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/mars-cli/mars_cli.py b/mars-cli/mars_cli.py index d3b8be7..ffdb077 100644 --- a/mars-cli/mars_cli.py +++ b/mars-cli/mars_cli.py @@ -197,17 +197,22 @@ def cli(ctx, development): @cli.command() @click.option( - "--webin-username", type=click.STRING, help="Username for webin authentication" + "--webin-username", + type=click.STRING, + help="Username for webin authentication", + envvar="WEBIN_USERNAME", ) @click.option( "--metabolights-username", type=click.STRING, help="Username for MetaboLights metadata submission", + envvar="METABOLIGHTS_USERNAME", ) @click.option( "--metabolights-ftp-username", type=click.STRING, help="Username for MetaboLights data submission", + envvar="METABOLIGHTS_FTP_USERNAME", ) @click.option( "--credentials-file", @@ -288,8 +293,9 @@ def submit( data_file_paths = [f.name for f in data_files] if file_transfer else [] submission( - credential_service_name, - username_credentials, + webin_username, + metabolights_username, + metabolights_ftp_username, credentials_file, isa_json_file.name, target_repositories, diff --git a/mars-cli/mars_lib/submit.py b/mars-cli/mars_lib/submit.py index 215a70b..6cf3dcb 100644 --- a/mars-cli/mars_lib/submit.py +++ b/mars-cli/mars_lib/submit.py @@ -10,6 +10,7 @@ get_metabolights_auth_token, get_webin_auth_token, load_credentials, + AuthProvider, ) from mars_lib.biosamples_external_references import ( get_header, @@ -48,8 +49,9 @@ def save_step_to_file(time_stamp: float, filename: str, isa_json: IsaJson): def submission( - credential_service_name: str, - username_credentials: str, + webin_username: str, + metabolights_username: str, + metabolights_ftp_username: str, credentials_file: TextIOWrapper, isa_json_file: str, target_repositories: list[str], @@ -63,11 +65,18 @@ def submission( # Get password from the credential manager # Else: # read credentials from file - if not (credential_service_name is None or username_credentials is None): - cm = CredentialManager(credential_service_name) + if all([webin_username, metabolights_username, metabolights_ftp_username]): user_credentials = { - "username": username_credentials, - "password": cm.get_password_keyring(username_credentials), + cred_pair[0]: { + "username": cred_pair[1], + "password": CredentialManager(cred_pair[0]).get_password_keyring( + cred_pair[1] + ), + } + for cred_pair in zip( + AuthProvider.available_providers(), + [webin_username, metabolights_username, metabolights_ftp_username], + ) } else: if credentials_file == "":