Simplify job_run_file and return 404

This commit is contained in:
Reynir Björnsson 2020-12-22 13:36:14 +01:00
parent bf1777b7cb
commit f2ab0d797f

View file

@ -64,17 +64,20 @@ let routes (t : Model.t) =
let job = Router.param req "job"
and run = Router.param req "run"
and file = Router.splat req |> String.concat "/" in
let+ job_run =
Lwt_result.lift (safe_seg job) >>= fun job ->
Lwt_result.lift (safe_seg run) >>= fun run ->
Model.read_full_with_digests t job run in
match safe_seg job, safe_seg run, Fpath.of_string file with
| Error (`Msg e), _, _ | _, Error (`Msg e), _ | _, _, Error (`Msg e) ->
Log.debug (fun m -> m "bad path: %s" e);
Response.of_plain_text ~status:`Not_found "File not found"
|> Lwt.return
| Ok job, Ok run, Ok filep ->
let+ job_run = Model.read_full_with_digests t job run in
match job_run with
| Error (`Msg e) ->
Log.warn (fun m -> m "Error getting job run: %s" e);
Response.of_plain_text ~status:`Internal_server_error
"Error getting job run"
| Ok (job_run, digests) ->
match List.find_opt (fun (p, _) -> Fpath.(equal (v file) p)) job_run.data with
match List.find_opt (fun (p, _) -> Fpath.(equal filep p)) job_run.data with
| None ->
Log.debug (fun m -> m "Trying to get non-existent build artifact %s"
file);