-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Extism plugin system next to native binary exec option (#156)
* feat: support Extism plugins * chore: update go modules * ci: use go 1.16 in build, supports embed. new minimum version supported * chore: update go.mod required versions * ci: update to go 1.20 * ci: remove test case, narrowing * ci: add test case, expand * ci: add test case, expand * ci: rearrange shell commands * ci: more arrangement * ci: more test debugging * ci: try without pipefail, as this is supposed to fail * ci: try with go run * ci: try with file output * ci: never fail the status check before testing grep * ci: remove combined test
- Loading branch information
Showing
8 changed files
with
159 additions
and
25 deletions.
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
module github.com/nilslice/protolock | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/proto v1.9.1 | ||
github.com/extism/go-sdk v1.0.0 | ||
github.com/stretchr/testify v1.8.4 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gobwas/glob v0.2.3 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/testify v1.2.2 | ||
github.com/tetratelabs/wazero v1.3.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,9 @@ | ||
module github.com/nilslice/protolock/plugin-samples/plugin-sample-wasm | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/emicklei/proto v1.9.1 // indirect | ||
github.com/extism/go-pdk v1.0.0 // indirect | ||
github.com/nilslice/protolock v0.17.0 // indirect | ||
) |
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,9 @@ | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/emicklei/proto v1.9.1 h1:MUgjFo5xlMwYv72TnF5xmmdKZ04u+dVbv6wdARv16D8= | ||
github.com/emicklei/proto v1.9.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= | ||
github.com/extism/go-pdk v1.0.0 h1:/VlFLDnpYfooMl+VW94VHrbdruDyKkpa47yYJ7YcCAE= | ||
github.com/extism/go-pdk v1.0.0/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4= | ||
github.com/nilslice/protolock v0.17.0 h1:sYvcukABl62tZX77H6NuV+jtlwTIfQbn0ln0ixTqr4A= | ||
github.com/nilslice/protolock v0.17.0/go.mod h1:DYFqop7QlHjmBCaJKfcVO1Mw5b8JejJZgMvmFng/N9Y= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
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,56 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
pdk "github.com/extism/go-pdk" | ||
"github.com/nilslice/protolock" | ||
"github.com/nilslice/protolock/extend" | ||
) | ||
|
||
// an Extism plugin uses a 'PDK' to communicate data input and output from its host system, in | ||
// this case, the `protolock` command. | ||
|
||
// see https://extism.org and https://github.com/extism/extism for more information. | ||
|
||
// In order to satisfy the current usage, an Extism Protolock plugin must export a single function | ||
// "status" with the following signature: | ||
|
||
//export status | ||
func status() int32 { | ||
// rather than taking input from stdin, like native Protolock plugins, Extism plugins take data | ||
// from their host, using the `pdk.Input()` function, returning bytes from protolock. | ||
var data extend.Data | ||
err := json.Unmarshal(pdk.Input(), &data.Current) | ||
if err != nil { | ||
pdk.SetError(err) | ||
return 1 | ||
} | ||
|
||
// with the `extend.Data` available, you would do some checks on the current and updated set of | ||
// `proto.lock` representations. Here we are adding a warning to demonstrate that the plugin | ||
// works with some known data output to verify. | ||
warning := protolock.Warning{ | ||
Filepath: "fake.proto", | ||
Message: "An Extism plugin ran and checked the status of the proto.lock files", | ||
RuleName: "RuleNameXYZ", | ||
} | ||
data.PluginWarnings = append(data.PluginWarnings, warning) | ||
|
||
b, err := json.Marshal(data) | ||
if err != nil { | ||
pdk.SetError(err) | ||
return 1 | ||
} | ||
|
||
// tather than writing data to stdout, like native Protolock plugins, Extism plugins provide | ||
// data back to their host, using the `pdk.Output()` function, returning bytes to protolock. | ||
pdk.Output(b) | ||
|
||
// non-zero return code here will result in Extism detecting an error. | ||
return 0 | ||
} | ||
|
||
// this Go code is compiled to WebAssembly, and current compilers expect some entrypoint, even if | ||
// this function isn't called. | ||
func main() {} |
Binary file not shown.