-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// 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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 beblackstork
.The namespace only affects installation of the plugins, but not parsing / execution of the templates
There was a problem hiding this comment.
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 ingolang
and also there are already a lot of different "types" floating around I started referring to thecontent
ordata
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!