Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed plugin RPC spec #24

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
Expand Down
55 changes: 55 additions & 0 deletions pluginInterface/v1/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package plugin

import (
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
)

// The interface exposed and used by the go-plugin (versioned as 1)
type PluginRPC interface {
GetPlugins() []Plugin
Call(args Args) Result
}

// One go-plugin binary can provide multiple plugins and/or one plugin with multiple versions
// Deciding if we actually will do bundling in that way or stick with one plugin - one binary
// is a different question, but the interface wouldn't limit us either way.
type Plugin struct {
// The namespace used during installation of the plugins
Namespace string
// "content" or "data" for now
Kind string
// "text", "plugin_a", etc.
Name string
Copy link
Member

@traut traut Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be good to add another string field here -- a namespace field. Using namespaced plugin names will allow users to use plugins from various providers. So the fully qualified plugin name would be <namespace>/<type>.<name> (see an example in #5). For our plugins the namespace can be blackstork.

The namespace only affects installation of the plugins, but not parsing / execution of the templates

Copy link
Contributor Author

@Andrew-Morozko Andrew-Morozko Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! This comment reminded me of an unspoken terminology choice I made. Since type is a reserved name in golang and also there are already a lot of different "types" floating around I started referring to the content or data as "block/plugin kinds" to separate them a bit from every other meaning of "type" I have to work with. It's pretty easy to find-and-replace "Kind" to "Type" if it's objectionable, but I kinda like the term "plugin kind" here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

// version of the plugin `Kind Name` that is provided by the current binary
Version semver.Version
// Specification of the `config` block for this plugin
// If nil - providing a `config Kind Name` is an error
ConfigSpec hcldec.Spec
// Specification of the invocation block's body, i.e. `content text {<spec of what's here>}`
InvocationSpec hcldec.Spec
}

type Args struct {
// Specifies which kind, name and version of plugin to execute
Kind string
Name string
Version semver.Version

// Result of decoding a config block with ConfigSpec
Config cty.Value
// Result of decoding an invocation block with InvocationSpec
Args cty.Value
// Passed to content plugins, nil for data plugins
Context map[string]any
Andrew-Morozko marked this conversation as resolved.
Show resolved Hide resolved
}

type Result struct {
// `content` plugins return a markdown string
// `data` plugins return a map[string]any that would be put into the global config
// TODO: hard-code typecast based on the plugin kind while handling the result
result any
Andrew-Morozko marked this conversation as resolved.
Show resolved Hide resolved
diags hcl.Diagnostics
}