A Plugin that uses another
Some Plugins are written to use another unit's contract. The pool's calendar reads Microsoft and Google
calendars with an access token, and holds no sign-in of its own: it asks the pool's online-accounts,
which signs a person in, keeps the refresh token and answers an access token to whoever is given it. In the
application the first declares a need, unit:accounts; the application says which unit meets it; an
operator grants the use. Nothing else is written: the order the units start in, the channel between them and
who asked are the Core's.
This page composes the two, and reads a Google calendar through them. Taking any Plugin that declares a
unit need goes the same way.
| Plugin | Declares | Uses |
|---|---|---|
com.yoke.online-accounts | secret:clients, secret:tokens; answers oauth.token, oauth.accounts | nothing |
com.yoke.calendar | secret:credentials, storage:cache, unit:accounts; answers calendar.sources, calendar.events, calendar.days | of accounts, the question oauth.token |
Take the two, and bind the need
The unit used is taken first, so that the need has a unit to be bound to:
yoke-compose init com.example.desk
yoke-compose add plugin https://github.com/yoke-project/yoke-plugin-online-accounts@v0.1.0 --as online-accounts
yoke-compose add plugin https://github.com/yoke-project/yoke-plugin-calendar@v0.1.0 --as calendar --bind accounts=online-accounts
calendar uses, of the unit its need accounts is bound to, the question oauth.token; an operator grants query.oauth.token.ask
took https://github.com/yoke-project/yoke-plugin-calendar@v0.1.0 as the unit calendar, recorded in plugins.yaml
--bind accounts=online-accounts names the unit, not the Plugin: an application with two copies of
online-accounts binds each calendar to the one it means. The composer says what the need uses, and the
capability an operator grants for it.
Then the arguments, each naming its needs as ${bind.<name>}:
yoke-compose set units.online-accounts.args '["--clients", "${bind.clients}", "--tokens", "${bind.tokens}"]'
yoke-compose set units.calendar.args '["--credentials", "${bind.credentials}", "--cache", "${bind.cache}", "--accounts", "${bind.accounts}", "--source", "home=google:ada@example.org"]'
yoke-compose check
units:
online-accounts:
kind: plugin
plugin: com.yoke.online-accounts
exec: components/plugins/online-accounts
args: ["--clients", "${bind.clients}", "--tokens", "${bind.tokens}"]
calendar:
kind: plugin
plugin: com.yoke.calendar
exec: components/plugins/calendar
args: ["--credentials", "${bind.credentials}", "--cache", "${bind.cache}", "--accounts", "${bind.accounts}", "--source", "home=google:ada@example.org"]
bind:
accounts: online-accounts
${bind.accounts} becomes the path of the channel the Core binds for the need, as ${bind.cache}
becomes a directory and ${bind.clients} a file. calendar is told nothing else of the unit behind it.
No order is written. The Core starts online-accounts before calendar, because the binding says the one
uses the other; a unit used that is not ready within the startup window delays the other and is reported,
and is never fatal.
| The gate refuses | When |
|---|---|
unit.needs.unbound | a unit need has no binding |
bind.unit.unknown | it is bound to a name no unit bears |
bind.unit.kind | it is bound to a unit that is not a Plugin unit |
bind.unit.undeclared | the unit bound does not declare a question or a stream the need uses; the finding names the need, the object and the unit |
bind.unit.cycle | the bindings close a cycle, at any length; the finding names every unit on it |
Run it as an instance
Both Plugins need secrets, so the application runs as an installed instance (running it):
yoke-compose build --out out
yoke app install out/com.example.desk-0.1.0.yoke
yoke instance create com.example.desk --name desk
yoke instance set-secret desk clients < clients.json
echo '{}' | yoke instance set-secret desk tokens
echo '{}' | yoke instance set-secret desk credentials
yoke instance start desk
clients is the deployment's own registration with Microsoft and Google — the project registers none —
and tokens starts empty: online-accounts rewrites it itself at every sign-in and every rotation, and is
not restarted for its own write. credentials holds what a CalDAV or private iCalendar source needs, and
nothing here.
Grant the use
A declaration grants nothing. Each Plugin is granted what it declares, and the use is granted on its own:
for c in $(sed -n 's/^ - name: //p' manifests/com.yoke.online-accounts.yaml); do yoke plugin grant com.yoke.online-accounts "$c" --instance desk; done
for c in $(sed -n 's/^ - name: //p' manifests/com.yoke.calendar.yaml); do yoke plugin grant com.yoke.calendar "$c" --instance desk; done
yoke unit restart online-accounts --instance desk
yoke unit restart calendar --instance desk
| Grant | On | For |
|---|---|---|
query.oauth.token.ask | com.yoke.calendar | asking the question through the need |
query.oauth.token.answer | com.yoke.online-accounts | answering it, as to anyone |
Both are checked at every question. Without the first the need's channel refuses the question itself,
scope.withheld, online-accounts is never asked, and the Core reports unit.use.refused on calendar.
Sign in, and read
The person signs in once, in online-accounts, asking for the calendar:
yoke unit command online-accounts oauth.login --input - --instance desk <<< '{"provider":"google","scopes":["https://www.googleapis.com/auth/calendar.readonly"]}'
Open the page it names in a browser on this machine and consent. Then:
yoke unit command calendar calendar.refresh --instance desk
yoke unit ask calendar calendar.days --input - --instance desk <<< '{"days":3}'
calendar asks online-accounts for a token as unit:calendar: the Core says who asked, from the
channel it came on. online-accounts gives what its --give rules give that asker; with none, every asker is given every
account. Before the sign-in the source says why it cannot be read:
online-accounts refused the token, not_found: there is no account google:ada@example.org for unit:calendar
Further along the chain
A Plugin that uses calendar is bound the same way, and a chain may be as long as the application makes
it: agenda, of using another unit, bound to calendar, asks
it while answering its own asker, and calendar asks online-accounts in turn. Each question carries the
chain's identity and a deadline 500 ms shorter than the one before; authority is not passed along:
each link is granted on its own.
yoke-compose add plugin ../agenda --as agenda --bind calendar=calendar
yoke-compose set units.agenda.args '["--calendar", "${bind.calendar}"]'
Next: Running it.