2019-11-19 19:26:05 +03:00
|
|
|
:: link-proxy-hook: make local pages available to foreign ships
|
|
|
|
::
|
|
|
|
:: this is a "proxy" style hook, relaying foreign subscriptions into local
|
|
|
|
:: stores if permission conditions are met.
|
|
|
|
:: the patterns herein should one day be generalized into a proxy-hook lib.
|
|
|
|
::
|
2020-03-01 03:36:52 +03:00
|
|
|
:: this uses metadata-store to discover resources and their associated
|
|
|
|
:: groups. it sets the permission condition to be that a ship must be in a
|
|
|
|
:: group associated with the resource it's subscribing to.
|
|
|
|
:: we check this on-watch, but also subscribe to metadata & groups so that
|
|
|
|
:: we can kick subscriptions if needed (eg ship removed from group).
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
:: we deduplicate incoming subscriptions on the same path, ensuring we have
|
|
|
|
:: exactly one local subscription per unique incoming subscription path.
|
|
|
|
:: this comes at the cost of assuming that the store's initial response is
|
|
|
|
:: whatever's returned by the scry at that path, but perhaps that should
|
|
|
|
:: become part of the stores standard anyway.
|
|
|
|
::
|
2019-12-21 02:51:49 +03:00
|
|
|
:: when adding support for new paths, the only things you'll likely want
|
2020-03-01 03:36:52 +03:00
|
|
|
:: to touch are +permitted, +initial-response, & +kick-proxies.
|
2019-12-21 02:51:49 +03:00
|
|
|
::
|
2020-03-01 03:36:52 +03:00
|
|
|
/- group-store, *metadata-store
|
|
|
|
/+ *link, metadata, default-agent, verb, dbug
|
2019-11-19 19:26:05 +03:00
|
|
|
|%
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
::TODO we use this to detect "first sub started" and "last sub left",
|
|
|
|
:: but can't we use [wex sup]:bowl for that?
|
|
|
|
active=(map path (set ship))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ card card:agent:gall
|
|
|
|
--
|
|
|
|
::
|
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
::
|
2020-01-29 21:21:40 +03:00
|
|
|
%- agent:dbug
|
2019-11-20 18:09:29 +03:00
|
|
|
%+ verb |
|
2019-11-19 19:26:05 +03:00
|
|
|
^- agent:gall
|
|
|
|
=<
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
do ~(. +> bowl)
|
|
|
|
def ~(. (default-agent this %&) bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
:_ this
|
2020-03-01 03:36:52 +03:00
|
|
|
~[watch-groups:do watch-metadata:do]
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
[~ this(state !<(state-0 old))]
|
|
|
|
::
|
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
:: the local ship should just use link-store directly
|
|
|
|
::TODO do we want to allow this anyway, to avoid client-side target checks?
|
|
|
|
::
|
|
|
|
?< (team:title [our src]:bowl)
|
|
|
|
?> (permitted:do src.bowl path)
|
|
|
|
=^ cards state
|
|
|
|
(start-proxy:do src.bowl path)
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ on-leave
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
=^ cards state
|
|
|
|
(stop-proxy:do src.bowl path)
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
|
|
|
?: ?=([%groups ~] wire)
|
|
|
|
=^ cards state
|
|
|
|
(take-groups-sign:do sign)
|
|
|
|
[cards this]
|
|
|
|
?: ?=([%proxy ^] wire)
|
|
|
|
=^ cards state
|
|
|
|
(handle-proxy-sign t.wire sign)
|
|
|
|
[cards this]
|
|
|
|
~| [dap.bowl %weird-wire wire]
|
|
|
|
!!
|
|
|
|
::
|
|
|
|
++ on-poke on-poke:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ =bowl:gall
|
2020-03-01 03:36:52 +03:00
|
|
|
+* md ~(. metadata bowl)
|
|
|
|
::
|
|
|
|
:: permissions
|
|
|
|
::
|
2019-11-19 19:26:05 +03:00
|
|
|
++ permitted
|
|
|
|
|= [who=ship =path]
|
|
|
|
^- ?
|
2020-03-01 03:36:52 +03:00
|
|
|
:: we only expose /local-pages and /annotations,
|
|
|
|
:: to ships in the groups associated with the resource.
|
2020-01-15 04:46:24 +03:00
|
|
|
:: (no url-specific annotations subscriptions, either.)
|
|
|
|
::
|
|
|
|
=/ target=(unit ^path)
|
|
|
|
?: ?=([%local-pages ^] path)
|
|
|
|
`t.path
|
|
|
|
?: ?=([%annotations ~ ^] path)
|
|
|
|
`t.t.path
|
|
|
|
~
|
|
|
|
?~ target |
|
2020-03-01 03:36:52 +03:00
|
|
|
~? !.^(? %gu (scot %p our.bowl) %metadata-store (scot %da now.bowl) ~)
|
|
|
|
%woah-md-s-not-booted ::TODO fallback if needed
|
|
|
|
%+ lien (groups-from-resource:md %link u.target)
|
|
|
|
|= =group-path
|
|
|
|
^- ?
|
|
|
|
=- (~(has in (fall - *group:group-store)) who)
|
|
|
|
%^ scry-for (unit group:group-store)
|
|
|
|
%group-store
|
|
|
|
group-path
|
|
|
|
::
|
|
|
|
++ kick-revoked-permissions
|
|
|
|
|= [=path who=(list ship)]
|
|
|
|
^- (list card)
|
|
|
|
%+ murn who
|
|
|
|
|= =ship
|
|
|
|
^- (unit card)
|
|
|
|
:: no need to remove to ourselves
|
|
|
|
::
|
|
|
|
?: =(our.bowl ship) ~
|
|
|
|
?: (permitted ship path) ~
|
|
|
|
`(kick-proxies ship path)
|
|
|
|
::
|
|
|
|
:: metadata subscription
|
|
|
|
::
|
|
|
|
++ watch-metadata
|
|
|
|
^- card
|
|
|
|
[%pass /metadata %agent [our.bowl %metadata-store] %watch /app-name/link]
|
|
|
|
::
|
|
|
|
++ take-metadata-sign
|
|
|
|
|= =sign:agent:gall
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.sign
|
|
|
|
%poke-ack ~|([dap.bowl %unexpected-poke-ack /metadata] !!)
|
|
|
|
%kick [[watch-metadata]~ state]
|
|
|
|
::
|
|
|
|
%watch-ack
|
|
|
|
?~ p.sign [~ state]
|
|
|
|
=/ =tank
|
|
|
|
:- %leaf
|
|
|
|
"{(trip dap.bowl)} failed subscribe to metadata store. very wrong!"
|
|
|
|
%- (slog tank u.p.sign)
|
|
|
|
[~ state]
|
|
|
|
::
|
|
|
|
%fact
|
|
|
|
=* mark p.cage.sign
|
|
|
|
=* vase q.cage.sign
|
|
|
|
?. ?=(%metadata-update mark)
|
|
|
|
~| [dap.bowl %unexpected-mark mark]
|
|
|
|
!!
|
|
|
|
%- handle-metadata-update
|
|
|
|
!<(metadata-update vase)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-metadata-update
|
|
|
|
|= upd=metadata-update
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state
|
|
|
|
?. ?=(%remove -.upd) ~
|
|
|
|
?> =(%link app-name.resource.upd)
|
|
|
|
:: if a group is no longer associated with a resource,
|
|
|
|
:: we need to re-check permissions for everyone in that group.
|
|
|
|
::
|
|
|
|
%+ kick-revoked-permissions
|
|
|
|
app-path.resource.upd
|
|
|
|
%~ tap in
|
|
|
|
=- (fall - *group:group-store)
|
|
|
|
%^ scry-for (unit group:group-store)
|
|
|
|
%group-store
|
|
|
|
group-path.upd
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
:: groups subscription
|
|
|
|
::TODO largely copied from link-listen-hook. maybe make a store-listener lib?
|
|
|
|
::
|
|
|
|
++ watch-groups
|
|
|
|
^- card
|
|
|
|
[%pass /groups %agent [our.bowl %group-store] %watch /all]
|
|
|
|
::
|
|
|
|
++ take-groups-sign
|
|
|
|
|= =sign:agent:gall
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.sign
|
|
|
|
%poke-ack ~|([dap.bowl %unexpected-poke-ack /groups] !!)
|
|
|
|
%kick [[watch-groups]~ state]
|
|
|
|
::
|
|
|
|
%watch-ack
|
|
|
|
?~ p.sign [~ state]
|
|
|
|
=/ =tank
|
|
|
|
:- %leaf
|
|
|
|
"{(trip dap.bowl)} failed subscribe to group store. very wrong!"
|
|
|
|
%- (slog tank u.p.sign)
|
|
|
|
[~ state]
|
|
|
|
::
|
|
|
|
%fact
|
|
|
|
=* mark p.cage.sign
|
|
|
|
=* vase q.cage.sign
|
|
|
|
?+ mark ~|([dap.bowl %unexpected-mark mark] !!)
|
|
|
|
%group-initial [~ state]
|
|
|
|
%group-update (handle-group-update !<(group-update:group-store vase))
|
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-group-update
|
|
|
|
|= upd=group-update:group-store
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state
|
|
|
|
?. ?=(%remove -.upd) ~
|
2020-03-01 03:36:52 +03:00
|
|
|
:: if someone was removed from a group, find all link resources associated
|
|
|
|
:: with that group, then kick their subscriptions if they're no longer
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
2020-03-01 03:36:52 +03:00
|
|
|
%- zing
|
|
|
|
%+ turn (app-paths-from-group:md %link pax.upd)
|
|
|
|
|= =app-path
|
|
|
|
^- (list card)
|
|
|
|
%+ kick-revoked-permissions
|
|
|
|
app-path
|
|
|
|
~(tap in members.upd)
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
:: proxy subscriptions
|
|
|
|
::
|
2020-01-15 04:46:24 +03:00
|
|
|
++ kick-proxies
|
2020-03-01 03:36:52 +03:00
|
|
|
|= [who=ship =path]
|
2019-11-19 19:26:05 +03:00
|
|
|
^- card
|
2020-03-01 03:36:52 +03:00
|
|
|
=- [%give %kick - `who]
|
|
|
|
:~ [%local-pages path]
|
|
|
|
[%annotations %$ path]
|
|
|
|
==
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
++ handle-proxy-sign
|
2019-12-20 18:02:09 +03:00
|
|
|
|= [=wire =sign:agent:gall]
|
2019-11-19 19:26:05 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
?- -.sign
|
2019-12-20 18:02:09 +03:00
|
|
|
%poke-ack ~|([dap.bowl %unexpected-poke-ack wire] !!)
|
2020-01-08 00:30:55 +03:00
|
|
|
%fact [[%give %fact ~[wire] cage.sign]~ state]
|
2019-12-20 18:02:09 +03:00
|
|
|
%kick [[(proxy-pass-link-store wire %watch wire)]~ state]
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
%watch-ack
|
|
|
|
?~ p.sign [~ state]
|
|
|
|
=/ =tank
|
|
|
|
:- %leaf
|
|
|
|
"{(trip dap.bowl)} failed subscribe to link-store. very wrong!"
|
|
|
|
%- (slog tank u.p.sign)
|
|
|
|
[~ state]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ proxy-pass-link-store
|
|
|
|
|= [=path =task:agent:gall]
|
|
|
|
^- card
|
|
|
|
:* %pass
|
|
|
|
[%proxy path]
|
|
|
|
%agent
|
|
|
|
[our.bowl %link-store]
|
|
|
|
task
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ initial-response
|
|
|
|
|= =path
|
|
|
|
^- card
|
2020-01-15 04:46:24 +03:00
|
|
|
=; =initial
|
|
|
|
[%give %fact ~ %link-initial !>(initial)]
|
2019-12-21 02:51:49 +03:00
|
|
|
?+ path !!
|
|
|
|
[%local-pages ^]
|
2020-03-01 03:36:52 +03:00
|
|
|
[%local-pages .^((map ^path pages) %gx path)]
|
2019-12-21 02:51:49 +03:00
|
|
|
::
|
2020-02-15 01:35:04 +03:00
|
|
|
[%annotations %$ ^]
|
2020-03-01 03:36:52 +03:00
|
|
|
[%annotations .^((per-path-url notes) %gx %$ t.t.path)]
|
2019-12-21 02:51:49 +03:00
|
|
|
==
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
++ start-proxy
|
|
|
|
|= [who=ship =path]
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state(active (~(put ju active) path who))
|
|
|
|
:_ ~
|
|
|
|
:: if we already have a local subscription open,
|
|
|
|
::
|
|
|
|
?. =(~ (~(get ju active) path))
|
|
|
|
:: gather the initial response ourselves, and send that.
|
|
|
|
::
|
|
|
|
(initial-response path)
|
|
|
|
:: else, open a local subscription,
|
|
|
|
:: sending outward its initial response when we hear it.
|
|
|
|
::
|
|
|
|
(proxy-pass-link-store path %watch path)
|
|
|
|
::
|
|
|
|
++ stop-proxy
|
|
|
|
|= [who=ship =path]
|
|
|
|
^- (quip card _state)
|
|
|
|
=. active (~(del ju active) path who)
|
|
|
|
:_ state
|
|
|
|
:: if there are still subscriptions remaining, do nothing.
|
|
|
|
::
|
|
|
|
?. =(~ (~(get ju active) path)) ~
|
|
|
|
:: else, close the local subscription.
|
|
|
|
::
|
|
|
|
[(proxy-pass-link-store path %leave ~)]~
|
2020-02-15 01:35:04 +03:00
|
|
|
::
|
2020-03-01 03:36:52 +03:00
|
|
|
:: helpers
|
|
|
|
::
|
2020-02-15 01:35:04 +03:00
|
|
|
++ scry-for
|
2020-03-01 03:36:52 +03:00
|
|
|
|* [=mold =app-name =path]
|
2020-02-15 01:35:04 +03:00
|
|
|
.^ mold
|
|
|
|
%gx
|
|
|
|
(scot %p our.bowl)
|
2020-03-01 03:36:52 +03:00
|
|
|
app-name
|
2020-02-15 01:35:04 +03:00
|
|
|
(scot %da now.bowl)
|
|
|
|
(snoc `^path`path %noun)
|
|
|
|
==
|
2019-11-19 19:26:05 +03:00
|
|
|
--
|