2020-09-01 04:54:39 +03:00
|
|
|
:: link-proxy-hook [landscape]:
|
|
|
|
::
|
|
|
|
:: make local pages available to foreign ships
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
:: 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-06-27 03:29:09 +03:00
|
|
|
/- *link, *metadata-store, *group
|
|
|
|
/+ metadata, default-agent, verb, dbug, group-store, grpl=group,
|
|
|
|
resource, store=link-store
|
2020-04-03 00:49:46 +03:00
|
|
|
~% %link-proxy-hook-top ..is ~
|
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))
|
|
|
|
==
|
2020-06-24 03:28:57 +03:00
|
|
|
+$ state-1
|
|
|
|
$: %1
|
|
|
|
active=(map path (set ship))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
|
|
|
state-1
|
|
|
|
==
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
+$ card card:agent:gall
|
|
|
|
--
|
|
|
|
::
|
2020-06-24 03:28:57 +03:00
|
|
|
=| state-1
|
2019-11-19 19:26:05 +03:00
|
|
|
=* 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
|
2020-06-24 03:28:57 +03:00
|
|
|
|= old-vase=vase
|
2019-11-19 19:26:05 +03:00
|
|
|
^- (quip card _this)
|
2020-06-24 03:28:57 +03:00
|
|
|
=/ old
|
|
|
|
!<(versioned-state old-vase)
|
|
|
|
?- -.old
|
|
|
|
%1 [~ this(state old)]
|
|
|
|
::
|
|
|
|
%0
|
|
|
|
:_ this(state [%1 +.old])
|
2020-06-26 05:45:02 +03:00
|
|
|
:~ [%pass /groups %agent [our.bowl %group-store] %leave ~]
|
2020-06-24 03:28:57 +03:00
|
|
|
watch-groups:do
|
|
|
|
==
|
|
|
|
==
|
|
|
|
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
++ 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)
|
2020-05-26 02:50:29 +03:00
|
|
|
grp ~(. grpl bowl)
|
2020-03-01 03:36:52 +03:00
|
|
|
::
|
|
|
|
:: 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
|
|
|
%+ lien (groups-from-resource:md %link u.target)
|
|
|
|
|= =group-path
|
|
|
|
^- ?
|
2020-05-26 02:50:29 +03:00
|
|
|
(~(has in (members-from-path:grp group-path)) who)
|
2020-03-01 03:36:52 +03:00
|
|
|
::
|
|
|
|
++ 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
|
2020-05-26 02:50:29 +03:00
|
|
|
(members-from-path:grp 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
|
2020-05-26 02:50:29 +03:00
|
|
|
[%pass /groups %agent [our.bowl %group-store] %watch /groups]
|
2019-11-19 19:26:05 +03:00
|
|
|
::
|
|
|
|
++ 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]
|
2020-05-26 02:50:29 +03:00
|
|
|
%group-update (handle-group-update !<(update:group-store vase))
|
2019-11-19 19:26:05 +03:00
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-group-update
|
2020-05-26 02:50:29 +03:00
|
|
|
|= upd=update:group-store
|
2019-11-19 19:26:05 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
:_ state
|
2020-05-26 02:50:29 +03:00
|
|
|
?. ?=(%remove-members -.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
|
2020-06-08 10:53:16 +03:00
|
|
|
%+ turn (app-paths-from-group:md %link (en-path:resource resource.upd))
|
2020-03-01 03:36:52 +03:00
|
|
|
|= =app-path
|
|
|
|
^- (list card)
|
|
|
|
%+ kick-revoked-permissions
|
|
|
|
app-path
|
2020-05-26 02:50:29 +03:00
|
|
|
~(tap in ships.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-05-08 08:33:04 +03:00
|
|
|
=; =initial:store
|
2020-01-15 04:46:24 +03:00
|
|
|
[%give %fact ~ %link-initial !>(initial)]
|
2019-12-21 02:51:49 +03:00
|
|
|
?+ path !!
|
|
|
|
[%local-pages ^]
|
2020-03-12 01:38:09 +03:00
|
|
|
[%local-pages (scry-for (map ^path pages) %link-store path)]
|
2019-12-21 02:51:49 +03:00
|
|
|
::
|
2020-02-15 01:35:04 +03:00
|
|
|
[%annotations %$ ^]
|
2020-03-12 01:38:09 +03:00
|
|
|
[%annotations (scry-for (per-path-url notes) %link-store 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
|
|
|
--
|