Context plugins
A context plugin provides data to other apps when their templates are rendered. For example, a database app can create an account for each app that requests it and pass the credentials to that app's app.yml.jinja.
Usage
An app gets data from a context plugin if it requests a permission of the plugin's app:
# metadata.yml of the consuming app
version: 2
metadata:
has_permissions:
- my-db/databaseWhen the app's templates are rendered, n5i calls GetContext of every context plugin of my-db and adds the result to the template context as plugins.<plugin app>.<plugin id>:
# app.yml.jinja of the consuming app
environment:
DB_USER: "{{ plugins['my-db'].accounts.username }}"
DB_PASSWORD: "{{ plugins['my-db'].accounts.password }}"Passing data to the plugin
Apps can send data to a plugin with exported_data in their metadata:
exported_data:
my-db: # plugin app
accounts: # plugin id
database_name: linkstackThe plugin receives it JSON-encoded in additional_data.
RPC interface
syntax = "proto3";
package n5i_plugin;
import "common.proto";
message GetContextRequest {
// The id of the app we're rendering the template for.
string app_id = 1;
// These permissions already have the <plugin-name>/ prefix removed.
repeated string permissions = 2;
// JSON-encoded data the app wants to share with the plugin.
string additional_data = 3;
UserState user_state = 4;
}
message AppContext {
// JSON-encoded data
// The built-in app.yml parser adds this to the Jinja context, but other plugins may handle it differently
string context = 1;
// Permissions this app adds
repeated Permission added_permissions = 2;
}
message RegisterAppRequest {
// The id of the app we're registering.
string app_id = 1;
// These permissions already have the <plugin-name>/ prefix removed.
repeated string permissions = 2;
// JSON-encoded data the app wants to share with the plugin.
string additional_data = 3;
UserState user_state = 4;
}
message UnregisterAppRequest {
// The id of the app we're unregistering.
string app_id = 1;
UserState user_state = 2;
}
message RegisterAppResponse {}
message UnregisterAppResponse {}
// A context plugin enhances the "context" of apps with data
service ContextPlugin {
// This method gets invoked whenever we install or change an app that has a permission this plugin cares about.
rpc RegisterApp(RegisterAppRequest) returns (RegisterAppResponse) {}
rpc UnregisterApp(UnregisterAppRequest) returns (UnregisterAppResponse) {}
// This method gets invoked whenever we need to render a template that uses this plugin.
rpc GetContext(GetContextRequest) returns (AppContext) {}
}RegisterApp
Called whenever an app that requests a permission of this plugin's app is installed, updated or otherwise changed. Use it to create accounts or other resources for the app.
UnregisterApp
Called when such an app is uninstalled, or changes so that it no longer requests a permission of this plugin's app. Clean up what RegisterApp created.
GetContext
Called whenever a template of such an app is rendered. Return a JSON-encoded object in context. It must be fast and must return the same data for the same input, because templates are rendered often.
added_permissions lets the plugin add permissions to the app, for example a permission with a custom name and description that the user has to grant. The Permission type is defined in common.proto.