def download_jars_per_connection()

in awsglue/scripts/activate_etl_connector.py [0:0]


def download_jars_per_connection(conn: str, region: str, endpoint: str, proxy: str = None) -> List[str]:
    # validate connection type
    connection = get_connection(region, endpoint, conn, proxy)
    if connection is None:
        return []
    # download jars from S3 in case of custom connection
    elif connection["Connection"]["ConnectionType"] == CUSTOM:
        logger.info(f"Connection {conn} is a Custom connection, try to download jars for it from S3.")
        return download_custom_jars(connection)
    # return empty list in case of non-marketplace connection
    elif connection["Connection"]["ConnectionType"] != MARKETPLACE:
        logger.warning(f"Connection {conn} is not a Marketplace connection, skip jar downloading for it")
        return []
        
    # get the connection classname
    if "CONNECTOR_CLASS_NAME" in connection["Connection"]["ConnectionProperties"]:
        driver_name = connection["Connection"]["ConnectionProperties"]["CONNECTOR_CLASS_NAME"]

    # get the the connection ecr url
    ecr_url = connection["Connection"]["ConnectionProperties"]["CONNECTOR_URL"]
    ecr_root, _, _ = parse_ecr_url(ecr_url)

    # download the jars
    token = get_ecr_authorization_token(ecr_root)
    http_header = {"Authorization": f"Basic {token}"}

    manifest = get_docker_manifest(ecr_url, http_header)

    # make directory for the jars of the given connection
    dir_prefix = id_generator()
    os.makedirs(f"{dir_prefix}/{LAYER_TAR_DIR}", exist_ok=True)
    os.makedirs(f"{dir_prefix}/{LAYER_GZ_DIR}", exist_ok=True)

    for layer in manifest["layers"]:
        download_and_unpack_docker_layer(ecr_url, layer["digest"], dir_prefix, http_header)

    # return the jar paths
    res = collect_files_by_suffix(f"{dir_prefix}/{LAYER_TAR_DIR}/jars", ".jar")
    logger.info(f"Container paths are: {res}")

    # Write OEM key to /tmp/glue-marketplace.conf
    oem_key_path = f"{dir_prefix}/{LAYER_TAR_DIR}/oem/oem.txt"
    if path.exists(oem_key_path):
        with open(oem_key_path, 'r') as oem_file:
            oem_key = oem_file.readline()
            oem_value = oem_file.readline()
        output = """marketplace_oem = {
        %s = {
            oem_key = %s        oem_value = %s
          }
        }\n""" % (driver_name, oem_key, oem_value)
        with open("/tmp/glue-marketplace.conf", 'a') as opened_file:
            opened_file.write(output)
        logger.info(f"OEM information is written.")

    if not res:
        logger.warning(f"found no connector jars from {ecr_url} provided by {conn}, please contact AWS support of"
                       f" the Connector product owner to debug the issue.")
    else:
        logger.info(f"collected jar paths: {res} for connection: {conn}")
    return res