-
Notifications
You must be signed in to change notification settings - Fork 11
/
dummy.go
49 lines (38 loc) · 1.18 KB
/
dummy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
// go build -o /usr/etc/trento/dummy ./plugin_examples/dummy.go
import (
"fmt"
"math/rand"
"github.com/hashicorp/go-plugin"
log "github.com/sirupsen/logrus"
"github.com/trento-project/agent/pkg/factsengine/entities"
"github.com/trento-project/agent/pkg/factsengine/plugininterface"
)
type dummyGatherer struct {
}
func (s dummyGatherer) Gather(factsRequests []entities.FactRequest) ([]entities.Fact, error) {
facts := []entities.Fact{}
log.Infof("Starting dummy plugin facts gathering process")
for _, factReq := range factsRequests {
value := rand.Int() // nolint
fact := entities.NewFactGatheredWithRequest(factReq, &entities.FactValueString{Value: fmt.Sprint(value)})
facts = append(facts, fact)
}
log.Infof("Requested dummy plugin facts gathered")
return facts, nil
}
func main() {
d := &dummyGatherer{}
handshakeConfig := plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "TRENTO_PLUGIN",
MagicCookieValue: "gatherer",
}
var pluginMap = map[string]plugin.Plugin{
"gatherer": &plugininterface.GathererPlugin{Impl: d},
}
plugin.Serve(&plugin.ServeConfig{ // nolint
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
})
}