[Proposal] Alternate configuration schema #3

Closed
opened 2022-03-18 10:51:42 +00:00 by tonyg · 3 comments
Contributor

I'd like to suggest the following configuration schema for uri_runner:

version 1 .

XdgOpen = <xdg-open @uris [string ...]> .

UriRunnerConfig = ListenOn / ActionHandler .
ListenOn = <listen-on @dataspace #!any> .
ActionHandler = <action-handler @pat string @cmd [string ...]> .

The idea is that you'd assert each ActionHandler separately to uri_runner, which would internally bring them all together; and you'd assert dataspaces to listen for XdgOpen messages separately, so that (1) uri_runner doesn't have to have a sturdyref to the dataspace inside it, it can have all its extrinsic authority passed in, and (2) you can listen on multiple dataspaces for requests.

Then, you could have a uri_runner.pr like this:

; Expose a dataspace over a unix socket
let ?root_ds = dataspace
<require-service <relay-listener <unix "/run/user/1000/dataspace"> $gatekeeper>>
<bind "syndicate" #x"" $root_ds>

<require-service <daemon uri_runner>>

<daemon uri_runner {
  argv: ["./uri_runner"]
  protocol: text/syndicate
}>

? <service-object <daemon uri_runner> ?cap> [
  $cap [
    <listen-on $root_ds>
    <action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" "\\1"]>
    <action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/firefox" "\\1"]>
    <action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" "\\1"]>
    <action-handler ".*\\.avi|.*\\.mp4|.*mkv", ["/run/current-system/sw/bin/mpv" "\\1"]>
  ]
]

or even

? <service-object <daemon uri_runner> ?cap> [
  $cap <listen-on $root_ds>
  $config ? <action-handler ?pat ?cmd> [
    $cap <action-handler $pat $cmd>
  ]
]
<action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" "\\1"]>
<action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/firefox" "\\1"]>
<action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" "\\1"]>
<action-handler ".*\\.avi|.*\\.mp4|.*mkv", ["/run/current-system/sw/bin/mpv" "\\1"]>

in order to allow dynamic adding/removal of handlers from the surrounding dataspace.

Another small change that might be worthwhile is to use something like

ActionHandler = <action-handler @pat string @cmd [TemplatePiece ...]> .
TemplatePiece = @constant string / @filename =filename / @submatch int .

allowing e.g.

<action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" filename]>

but I'm not sure if this particular little template language pays for itself properly...

I'd like to suggest the following configuration schema for `uri_runner`: ``` version 1 . XdgOpen = <xdg-open @uris [string ...]> . UriRunnerConfig = ListenOn / ActionHandler . ListenOn = <listen-on @dataspace #!any> . ActionHandler = <action-handler @pat string @cmd [string ...]> . ``` The idea is that you'd assert each `ActionHandler` separately to `uri_runner`, which would internally bring them all together; and you'd assert dataspaces to listen for `XdgOpen` messages separately, so that (1) `uri_runner` doesn't have to have a sturdyref to the dataspace inside it, it can have all its extrinsic authority passed in, and (2) you can listen on multiple dataspaces for requests. Then, you could have a `uri_runner.pr` like this: ``` ; Expose a dataspace over a unix socket let ?root_ds = dataspace <require-service <relay-listener <unix "/run/user/1000/dataspace"> $gatekeeper>> <bind "syndicate" #x"" $root_ds> <require-service <daemon uri_runner>> <daemon uri_runner { argv: ["./uri_runner"] protocol: text/syndicate }> ? <service-object <daemon uri_runner> ?cap> [ $cap [ <listen-on $root_ds> <action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" "\\1"]> <action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/firefox" "\\1"]> <action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" "\\1"]> <action-handler ".*\\.avi|.*\\.mp4|.*mkv", ["/run/current-system/sw/bin/mpv" "\\1"]> ] ] ``` or even ``` ? <service-object <daemon uri_runner> ?cap> [ $cap <listen-on $root_ds> $config ? <action-handler ?pat ?cmd> [ $cap <action-handler $pat $cmd> ] ] <action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" "\\1"]> <action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/firefox" "\\1"]> <action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" "\\1"]> <action-handler ".*\\.avi|.*\\.mp4|.*mkv", ["/run/current-system/sw/bin/mpv" "\\1"]> ``` in order to allow dynamic adding/removal of handlers from the surrounding dataspace. Another small change that might be worthwhile is to use something like ``` ActionHandler = <action-handler @pat string @cmd [TemplatePiece ...]> . TemplatePiece = @constant string / @filename =filename / @submatch int . ``` allowing e.g. ``` <action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" filename]> ``` but I'm not sure if this particular little template language pays for itself properly...
Owner

The idea is that you'd assert each ActionHandler separately to uri_runner

This answers a question that I hadn't thought to ask yet, in some other experiments I have asserted lists of items when I should assert each item seperately. I suppose that a rule of thumb would be not to assert lists unless the list items form some context with each other.

Originally I had a dictionary of pattern keys to action values, but that would be inconsistent because there is nothing to stop multiple instances of the uri_runner to match multipe actions to a single pattern.

> The idea is that you'd assert each ActionHandler separately to uri_runner This answers a question that I hadn't thought to ask yet, in some other experiments I have asserted lists of items when I should assert each item seperately. I suppose that a rule of thumb would be not to assert lists unless the list items form some context with each other. Originally I had a dictionary of pattern keys to action values, but that would be inconsistent because there is nothing to stop multiple instances of the uri_runner to match multipe actions to a single pattern.
ehmry referenced this issue from a commit 2022-03-19 00:15:24 +00:00
Owner

? <service-object ?cap> [
$cap [
<listen-on $root_ds>
]
]

I was assuming there was an implicitly exposed dataspace over stdio, but with this is what I missing. Now I understand relays better.

> ? <service-object <daemon uri_runner> ?cap> [ > $cap [ > <listen-on $root_ds> > ] > ] I was assuming there was an implicitly exposed dataspace over stdio, but with this is what I missing. Now I understand relays better.
ehmry closed this issue 2022-03-19 00:36:31 +00:00
Owner

TemplatePiece = @constant string / @filename =filename / @submatch int .

This would work but I think the Nim type system would make it complicated to handle. The submatch index is a good idea, I may do that for #4.

> TemplatePiece = @constant string / @filename =filename / @submatch int . This would work but I think the Nim type system would make it complicated to handle. The submatch index is a good idea, I may do that for #4.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ehmry/syndicated-open#3
No description provided.