Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/base_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (p *BasePlugin) Info() Info {

// Validate checks if the given options is valid for the plugin.
func (p *BasePlugin) Validate(config Config) error {
if p.configRef == nil {
return nil
}

return buildConfig(config.RawConfig, p.configRef)
}

Expand Down
10 changes: 10 additions & 0 deletions plugins/base_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func TestBasePluginInfo(t *testing.T) {
}

func TestBasePluginValidate(t *testing.T) {
t.Run("should not return error if config is nil", func(t *testing.T) {
basePlugin := plugins.NewBasePlugin(plugins.Info{}, nil)
err := basePlugin.Validate(plugins.Config{
URNScope: "test-scope",
RawConfig: map[string]interface{}{},
})

assert.NoError(t, err)
})

t.Run("should return InvalidConfigError if config is invalid", func(t *testing.T) {
invalidConfig := struct {
FieldA string `validate:"required"`
Expand Down
13 changes: 9 additions & 4 deletions plugins/processors/enrich/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ import (
//go:embed README.md
var summary string

type Config struct {
Attributes map[string]interface{} `mapstructure:"attributes" validate:"required"`
}

// Processor work in a list of data
type Processor struct {
plugins.BasePlugin
config map[string]interface{}
config Config
logger log.Logger
}

var sampleConfig = `
# Enrichment configuration
# fieldA: valueA
# fieldB: valueB`
# attributes:
# fieldA: valueA
# fieldB: valueB`

var info = plugins.Info{
Description: "Append custom fields to records",
Expand Down Expand Up @@ -68,7 +73,7 @@ func (p *Processor) process(record models.Record) (models.Metadata, error) {
customProps := utils.GetCustomProperties(data)

// update custom properties using value from config
for key, value := range p.config {
for key, value := range p.config.Attributes {
stringVal, ok := value.(string)
if ok {
customProps[key] = stringVal
Expand Down