-
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.
- Loading branch information
Showing
8 changed files
with
153 additions
and
21 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,16 @@ | ||
module github.com/nilslice/protolock | ||
|
||
go 1.21.1 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/proto v1.9.1 | ||
github.com/stretchr/testify v1.8.4 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/extism/go-sdk v1.0.0 // 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 | ||
) |
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.1 | ||
|
||
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.