From d8ff95db8491f711a5dfaffb7964683fec281e3d Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 1 Aug 2022 01:50:36 +0300 Subject: [PATCH] eyre: add /~/name endpoint --- pkg/arvo/sys/lull.hoon | 3 ++ pkg/arvo/sys/vane/eyre.hoon | 87 ++++++++++++++++++++++++++++--------- tests/sys/vane/eyre.hoon | 2 +- 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/pkg/arvo/sys/lull.hoon b/pkg/arvo/sys/lull.hoon index e05500f74..f565e237a 100644 --- a/pkg/arvo/sys/lull.hoon +++ b/pkg/arvo/sys/lull.hoon @@ -1551,6 +1551,9 @@ :: gall scry endpoint :: [%scry ~] + :: internal name endpoint, returns ship @p + :: + [%name ~] :: respond with the default file not found page :: [%four-oh-four ~] diff --git a/pkg/arvo/sys/vane/eyre.hoon b/pkg/arvo/sys/vane/eyre.hoon index f3ebe9583..88998ad69 100644 --- a/pkg/arvo/sys/vane/eyre.hoon +++ b/pkg/arvo/sys/vane/eyre.hoon @@ -70,7 +70,7 @@ ++ axle $: :: date: date at which http-server's state was updated to this data structure :: - date=%~2020.10.18 + date=%~2022.7.26 :: server-state: state of inbound requests :: =server-state @@ -744,44 +744,58 @@ :: %scry (handle-scry authenticated address request(url suburl)) + :: + %name + (handle-name authenticated request) :: %four-oh-four %^ return-static-data-on-duct 404 'text/html' (error-page 404 authenticated url.request ~) == + :: +handle-name: respond with our @p or 403 + :: + ++ handle-name + |= [authenticated=? =request:http] + ^- (quip move server-state) + ?. authenticated + (error-response authenticated url.request 403 ~) + ?. =(%'GET' method.request) + (error-response authenticated url.request 405 "may only GET name") + %^ return-static-data-on-duct 200 'text/plain' + (as-octs:mimes:html (scot %p our)) :: +handle-scry: respond with scry result, 404 or 500 :: ++ handle-scry |= [authenticated=? =address =request:http] |^ ^- (quip move server-state) ?. authenticated - (error-response 403 ~) + (error-response authenticated url.request 403 ~) ?. =(%'GET' method.request) - (error-response 405 "may only GET scries") + (error-response authenticated url.request 405 "may only GET scries") :: make sure the path contains an app to scry into :: =+ req=(parse-request-line url.request) ?. ?=(^ site.req) - (error-response 400 "scry path must start with app name") + (error-response authenticated url.request 400 "scry path must start with app name") :: attempt the scry that was asked for :: =/ res=(unit (unit cage)) (do-scry %gx i.site.req (snoc t.site.req (fall ext.req %mime))) - ?~ res (error-response 500 "failed scry") - ?~ u.res (error-response 404 "no scry result") + ?~ res (error-response authenticated url.request 500 "failed scry") + ?~ u.res (error-response authenticated url.request 404 "no scry result") =* mark p.u.u.res =* vase q.u.u.res :: attempt to find conversion gate to mime :: =/ tub=(unit tube:clay) (find-tube i.site.req mark %mime) - ?~ tub (error-response 500 "no tube from {(trip mark)} to mime") + ?~ tub (error-response authenticated url.request 500 "no tube from {(trip mark)} to mime") :: attempt conversion, then send results :: =/ mym=(each mime tang) (mule |.(!<(mime (u.tub vase)))) ?- -.mym - %| (error-response 500 "failed tube from {(trip mark)} to mime") + %| (error-response authenticated url.request 500 "failed tube from {(trip mark)} to mime") %& %+ return-static-data-on-duct 200 [(rsh 3 (spat p.p.mym)) q.p.mym] == @@ -804,11 +818,6 @@ ^- (unit (unit cage)) (rof ~ care [our desk da+now] path) :: - ++ error-response - |= [status=@ud =tape] - ^- (quip move server-state) - %^ return-static-data-on-duct status 'text/html' - (error-page status authenticated url.request tape) -- :: +subscribe-to-app: subscribe to app and poke it with request data :: @@ -848,7 +857,7 @@ %leave ~ == :: - ?(%authentication %logout) + ?(%authentication %logout %name) [~ state] :: %channel @@ -875,6 +884,13 @@ data=[~ data] complete=%.y == + :: +error-response: return error data all at once + :: + ++ error-response + |= [authenticated=? url=@t status=@ud =tape] + ^- (quip move server-state) + %^ return-static-data-on-duct status 'text/html' + (error-page status authenticated url tape) :: +authentication: per-event authentication as this Urbit's owner :: :: Right now this hard codes the authentication page using the old +code @@ -1071,7 +1087,7 @@ ^- @t %- crip =; max-age=tape - "urbauth-{(scow %p our)}={(scow %uv session)}; Path=/; Max-Age={max-age}" + "urbauth-{(scow %p our)}={(scow %uv session)}; Path=/; Max-Age={max-age}; HttpOnly" %- format-ud-as-integer ?. extend 0 (div (msec:milly session-timeout) 1.000) @@ -2207,6 +2223,7 @@ [[~ /~/logout] duct [%logout ~]] [[~ /~/channel] duct [%channel ~]] [[~ /~/scry] duct [%scry ~]] + [[~ /~/name] duct [%name ~]] == [~ http-server-gate] :: %trim: in response to memory pressure @@ -2577,15 +2594,43 @@ :: +load: migrate old state to new state (called on vane reload) :: ++ load - |= old=axle + => |% + ++ axle-old + %+ cork + axle + |= =axle + axle(date %~2020.10.18) + -- + |= old=$%(axle axle-old) ^+ ..^$ - :: enable https redirects if certificate configured :: - =. redirect.http-config.server-state.old - ?& ?=(^ secure.ports.server-state.old) - ?=(^ secure.http-config.server-state.old) + ~! %loading + ?- -.old + %~2020.10.18 + =/ [* d=duct *] + %+ snag 0 + %+ skim bindings.server-state.old + |= [=binding =duct =action] + =(%authentication -.action) + =/ new + %= old + date %~2022.7.26 + :: + bindings.server-state + ^- (list [binding duct action]) + :- [[~ /~/name] d [%name ~]] bindings.server-state.old == - ..^$(ax old) + $(old new) + :: + %~2022.7.26 + :: enable https redirects if certificate configured + :: + =. redirect.http-config.server-state.old + ?& ?=(^ secure.ports.server-state.old) + ?=(^ secure.http-config.server-state.old) + == + ..^$(ax old) + == :: +stay: produce current state :: ++ stay `axle`ax diff --git a/tests/sys/vane/eyre.hoon b/tests/sys/vane/eyre.hoon index f8fd9ba0f..c9c115a6e 100644 --- a/tests/sys/vane/eyre.hoon +++ b/tests/sys/vane/eyre.hoon @@ -2347,5 +2347,5 @@ :: ++ cookie-string %^ cat 3 cookie-value - '; Path=/; Max-Age=604800' + '; Path=/; Max-Age=604800; HttpOnly' --