Skip to content

Commit

Permalink
Add multi-platform build steps and plugin registration
Browse files Browse the repository at this point in the history
- Updated GitHub Actions workflow to build for Linux, Windows, and macOS.
- Added new dependencies to go.sum for better plugin support.
- Introduced `RegisterPlugin` function to dynamically register plugins.
- Modified `NewTrail` function to load all registered plugins dynamically.
- Added build tags to posix_plugin_unix.go for selective build on Linux and Darwin.
- Registered PosixPlugin during initialization.

Signed-off-by: Frederick F. Kautz IV <frederick@testifysec.com>
  • Loading branch information
fkautz committed Jun 13, 2024
1 parent 999f2e7 commit 477d3aa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ jobs:
with:
go-version: 1.19

- name: Build
run: go build -v ./...
- name: Build linux
run: GOOS=linux go build -v ./...

- name: Build windows
run: GOOS=windows go build -v ./...

- name: Build macos
run: GOOS=darwin go build -v ./...

- name: Test
run: go test -v ./...
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d h1:4l+Uq5zFWSagXgGFaKRRVWJrnlzeathyagWgYUltCgY=
github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d/go.mod h1:WxWwA3EYuCQjlR5EBUX3uaTS8bh9BOa7BcqVREHQ0uQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/omnibor/omnibor-go v0.0.0-20230521145532-a77de61a16cd h1:25EpGVgctk6V3DUa1gqFHvjVbmdWqM+jBZAed7p/krQ=
github.com/omnibor/omnibor-go v0.0.0-20230521145532-a77de61a16cd/go.mod h1:ArlQivzDQvZnFe8itjlA3ndPTXd9iWOgqzF31OyIEFQ=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand All @@ -18,7 +28,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17 changes: 16 additions & 1 deletion omnitrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import (
"sort"
)

type PluginInit func() Plugin

var pluginMap = make(map[string]PluginInit)

func RegisterPlugin(name string, initFn PluginInit) {
pluginMap[name] = initFn
}

func NewTrail(option ...Option) Factory {
o := &Options{}
for _, opt := range option {
Expand All @@ -15,9 +23,16 @@ func NewTrail(option ...Option) Factory {
}
allowList := []string{}
plugins := make([]Plugin, 0)
// Directory plugin depends on the File plugin
// We assume all other plugins depend on both the File and Directory plugins
plugins = append(plugins, NewFilePlugin())
plugins = append(plugins, NewDirectoryPlugin())
plugins = append(plugins, NewPosixPlugin())
// We load all other plugins here
for _, pluginInitFunc := range pluginMap {
plugins = append(plugins, pluginInitFunc())
}

fmt.Println(plugins)

factory := &factoryImpl{
Options: o,
Expand Down
8 changes: 8 additions & 0 deletions omnitrail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func testAdd(t *testing.T, name string) error {
return err
}

a, _ := json.MarshalIndent(mapping.Envelope(), "", " ")
fmt.Println(string(a))

// WARNING: these are only for generating new test cases easily
// file, err := json.MarshalIndent(mapping.Envelope(), "", " ")
// os.WriteFile("./test/"+name+".json", file, 0644)
Expand All @@ -106,8 +109,13 @@ func testAdd(t *testing.T, name string) error {
shortestExpectedKey := getShortestKey(&expectedEnvelope)
shortestActualKey := getShortestKey(mapping.Envelope())

fmt.Println(shortestExpectedKey)
fmt.Println(shortestActualKey)

for oldKey, val := range expectedEnvelope.Mapping {
fmt.Println("old key: ", oldKey)
newKey := strings.Replace(oldKey, shortestExpectedKey, shortestActualKey, 1)
fmt.Println("new key: ", oldKey)
delete(expectedEnvelope.Mapping, oldKey)
expectedEnvelope.Mapping[newKey] = val
}
Expand Down
6 changes: 6 additions & 0 deletions posix_plugin_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package omnitrail

import (
Expand All @@ -9,6 +11,10 @@ import (
"syscall"
)

func init() {
RegisterPlugin("posix", NewPosixPlugin)
}

type PosixPlugin struct {
params map[string]*posixInfo
AllowList []string
Expand Down

0 comments on commit 477d3aa

Please sign in to comment.