from typing import Dict
import re


def extract_access_tokens(text: str) -> Dict[str, str]:
    """
    Parses the given text for https URLs with an attached access token. Returns a dictionary mapping from
    file to file with access token, like `knee.tar.gz` -> `?AWSAccessKeyId=...`
    :param text: The text with https URLs
    :return:
    """
    result: Dict[str, str] = {}
    for match in re.finditer(r'(https://fastmri-dataset.s3.amazonaws.com/)([._a-zA-Z0-9]+)(\?[a-zA-Z0-9=&%]+)', text):
        file = match.group(2)
        token = match.group(3)
        if file in result:
            raise ValueError(f"Input file contains multiple entries for file {file}")
        print(f"Found access token for {file}: {token}")
        result[file] = token
    return result