artifact-get.tri (1529B)
1 !import base as B 2 !import handlers as H 3 !import handler_log as Log 4 !import handler_artifacts as Artifacts 5 !import http as HTTP 6 !export getBundle 7 !export main 8 9 -- The application chooses HTTP policy; the artifact service returns domain 10 -- Results. Read failures deliberately do not reveal filesystem paths to clients. 11 status ((t t), _) = 200 12 status (t, (["invalid-digest" message], t)) = 400 13 status _ = 404 14 response ((t t), (bytes, t)) = HTTP.response 200 "application/vnd.arboricx.bundle" bytes 15 response (t, (["invalid-digest" message], t)) = HTTP.badRequestResponse message 16 response _ = HTTP.errorResponse 404 "Artifact unavailable\n" 17 18 getBundle digest = H.label "bundle-get" <| do H.bind 19 reply <- Artifacts.load digest 20 logged <- Log.info [digest (status reply)] 21 case logged of 22 ((t t), _) = H.pure (response reply) 23 (t, (message, _)) = H.fail "application-failure" "logging" "emit" message 24 _ = H.fail "application-failure" "logging" "emit" "invalid logger reply" 25 26 -- Substitute Artifacts.withFilesystem root for this scripted handler to read 27 -- real objects, then run with H.runIO inside an IO.io envelope. Host read grants 28 -- are still required. Capture remains an ordinary composable wrapper. 29 exampleStore "load" _ = H.pure (B.ok [0 255 65] t) 30 exampleStore operation payload = H.forward "artifacts" operation payload 31 main = getBundle "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 32 |> Log.withContext [["request" 7]] 33 |> H.handle "artifacts" exampleStore 34 |> Log.capture 35 |> H.runPure