def patch_secrets(resources, secret_map, secret_variables):
    """
    Patches the secrests to payload
    Args:
        resources (dict): resources in API request payload
        secret_map (dict): credential secret values
        secret_variables (list): list of secret variables
    Returns:
        dict: payload with secrets patched
    """

    # Add creds back
    creds = resources.get("credential_definition_list", [])
    for cred in creds:
        name = cred["name"]
        cred["secret"] = secret_map[name]

    # Add creds back for HTTP endpoint
    auth = resources.get("authentication", {})
    username = auth.get("username", "")
    if username:
        auth["password"] = secret_map[username]

    for path, secret in secret_variables:
        variable = resources
        for sub_path in path:
            variable = variable[sub_path]
        variable["attrs"] = {"is_secret_modified": True}
        variable["value"] = secret

    return resources