let input_url url =
let open KEDSL in
let uri = Uri.of_string url in
let path_of_uri uri =
let basename =
match Uri.get_query_param uri "filename" with
| Some f -> f
| None ->
Digest.(string url |> to_hex) ^ (Uri.path uri |> Filename.basename)
in
Config.work_dir // basename
in
begin match Uri.scheme uri with
| None | Some "file" ->
let raw_file =
workflow_node (Uri.path uri |> single_file ~host)
~name:(sprintf "Input file: %s" url)
in
Raw_file (deal_with_input_file raw_file (single_file ~host))
| Some "http" | Some "https" ->
let path = path_of_uri uri in
Raw_file Biokepi_run_environment.(
Workflow_utilities.Download.wget
~host
~run_program:(Machine.run_download_program Config.machine) url path
)
| Some "gs" ->
let path = path_of_uri uri in
Raw_file Biokepi_run_environment.(
Workflow_utilities.Download.gsutil_cp
~host
~run_program:(Machine.run_download_program Config.machine)
~url ~local_path:path
)
| Some other ->
ksprintf failwith "URI scheme %S (in %s) NOT SUPPORTED" other url
end
|> AF.with_provenance "input-url" ~string_arguments:["url", url] []