The vendor's own setup¶
vendor.fields are the values an operator gives once per deployment for the
vendor's client. When the vendor can create that client itself, vendor.setup
says how, and Initiative runs it from the operator's browser and writes what
the vendor answers into those fields. One kind exists, github_app_manifest
(GitHub's app manifest flow):
vendor: {
fields: [
{ key: "app_id", type: "string", required: true, label: { en: "App id" } },
{ key: "private_key", type: "secret", required: true, label: { en: "Private key" } },
// …
],
setup: {
kind: "github_app_manifest",
app: {
name: "Acme Tracker",
url: "https://tracker.acme.example",
default_permissions: { issues: "write", metadata: "read" },
default_events: ["issues"],
},
values: { app_id: "id", private_key: "pem" /* , … */ },
},
},
appis what GitHub is asked to create: its name, its homepage (https), whether any account may install it (public, default false), and its permissions and events by GitHub's names. Initiative fills in the callback, setup, webhook and redirect URLs itself, soappnames none.valuesmaps each of your vendor field keys to one field of GitHub's answer:id,slug,client_id,client_secret,pemorwebhook_secret. Each key must be a vendor field, each answer is written at most once, andclient_secret,pemandwebhook_secretgo tosecretfields.
Checking the vendor values¶
An operator who types the values by hand can mix two clients' values, or
mistype a name the vendor builds addresses from, and nothing says so until a
community's connection fails. vendor.check is a call Initiative makes to the
vendor when the values are saved, before they are written, and the rows that
say what its answer must show:
check: {
sign: { iss: "{vendor.app_id}", key: "{vendor.private_key}" },
request: { method: "GET", url: "'https://api.tracker.example/app'" },
expect: [
{
status: "4xx",
holds: "false",
fields: ["app_id", "private_key"],
message: { en: "The vendor knows no client by this id and key." },
},
{
holds: "response.body.name = vendor.app_name",
fields: ["app_name"],
message: { en: "The id and key belong to a client with another name." },
shows: "response.body.name",
},
],
},
requestis the call, written as a declarative plug-in's requests are: https, and on one of yourhostswhen you name them. Its expressions readvendor, the non-secret values being saved, by key, andnow; secrets are never readable.signhas Initiative sign a JWT with one secret vendor value (key), issued by vendor values (iss), and put it on the request asauthsays (defaultAuthorization: Bearer <jwt>). Withoutsignthe request carries no credential.expectis tried in order. A row applies to the answers itsstatusmatches (default2xx) and refuses one whenholdsdoes not answer true;holdsalso reads the answer asresponse. The first row that refuses keeps the values from being written, and the form marks itsfields, shows itsmessage, and shows whatshowsanswers beside it. An answer no row refuses is accepted.- When the vendor cannot be reached, an expression fails, or a non-2xx answer has no row, the values are written and the form says the check could not run. A check never keeps an operator from saving because the vendor is down.
The check runs when a save sets a vendor value it reads, typed on the form or
written by the vendor's setup. validateManifest refuses rows naming fields
the vendor block does not declare, a key that is not one secret vendor value,
an issuer naming anything but vendor values, a header that would replace the
signed JWT's, and expressions that do not parse.
A token minted on demand¶
A static connection's token has Initiative mint its access token rather than
store one: it signs a JWT with a vendor key, posts it to the vendor's
exchange_url, and caches the answer until shortly before it expires.
exchange_body is a JSON body posted with it, such as the narrower
permissions a token is asked for:
token: {
type: "jwt_bearer",
exchange_url: "https://api.tracker.example/installations/{installation_id}/tokens",
exchange_body: { permissions: { issues: "write", contents: "read" } },
iss: "{vendor.app_id}",
key: "{vendor.private_key}",
},
exchange_url, iss and every string in exchange_body may name a vendor
value as {vendor.<key>} and one of the connection's own fields as {<key>};
validateManifest refuses a name that neither declares.
exchange_body may instead be an expression answering the body from
connection alone, the connection's own non-secret fields, managed ones
included, so the body can differ by connection: a vendor may refuse a token
request naming a permission the installation does not hold. A body that names a
vendor value stays an object. An answer that is not an object fails the token
request, so the connection cannot be used until the expression answers one.
runExchangeBody from initiative-plugin-sdk/testing answers the body
Initiative posts for a connection's fields and vendor values.