import json


def harmonize_credentials(secrets_file=None, cromwell_username=None, cromwell_password=None):
    """
    Takes all of the valid ways of providing authentication to cromwell and returns a username
    and password

    :param str cromwell_password:
    :param str cromwell_username:
    :param str secrets_file: json file containing fields cromwell_user and cromwell_password

    :return tuple: (string of cromwell username, string of cromwell password)
    """
    if cromwell_username is None or cromwell_password is None:
        if secrets_file is None:
            raise ValueError('One form of cromwell authentication must be provided, please pass '
                             'either cromwell_user and cromwell_password or a secrets_file.')
        else:
            with open(secrets_file) as f:
                secrets = json.load(f)
                cromwell_username = secrets['cromwell_user']
                cromwell_password = secrets['cromwell_password']
    return cromwell_username, cromwell_password