import json


def get_entry(filename):
    """Loads file from filename and returns the stache information as a tuple.

    Arguments:
        filename: name of file which stores X-STACHE-READ-KEY and endpoint as
            a JSON. The stache token file must be in the format:
        {
            "X-STACHE-READ-KEY": "stache_read_key",
            "endpoint": "stache_endpoint"
        }
        and must be saved in the cwd of the file that imports stache_creds.

    Returns:
        returns (key, url) of the api entry as a tuple.
    """
    with open(filename, "r") as file:
        creds = json.loads(file.read())
    # Get key and api endpoint for url.
    read_key = creds["X-STACHE-READ-KEY"]
    end_point = creds["endpoint"]

    # Format for request.
    key = {"X-STACHE-READ-KEY": read_key}
    url = f"https://stache.arizona.edu{end_point}"
    return key, url