forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (47 loc) · 1.5 KB
/
config.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
50
51
52
53
54
55
package stream
import (
"github.com/dafanshu/benthos/v3/internal/docs"
"github.com/dafanshu/benthos/v3/lib/buffer"
"github.com/dafanshu/benthos/v3/lib/input"
"github.com/dafanshu/benthos/v3/lib/output"
"github.com/dafanshu/benthos/v3/lib/pipeline"
"gopkg.in/yaml.v3"
)
//------------------------------------------------------------------------------
// Config is a configuration struct representing all four layers of a Benthos
// stream.
type Config struct {
Input input.Config `json:"input" yaml:"input"`
Buffer buffer.Config `json:"buffer" yaml:"buffer"`
Pipeline pipeline.Config `json:"pipeline" yaml:"pipeline"`
Output output.Config `json:"output" yaml:"output"`
}
// NewConfig returns a new configuration with default values.
func NewConfig() Config {
return Config{
Input: input.NewConfig(),
Buffer: buffer.NewConfig(),
Pipeline: pipeline.NewConfig(),
Output: output.NewConfig(),
}
}
// Sanitised returns a sanitised copy of the Benthos configuration, meaning
// fields of no consequence (unused inputs, outputs, processors etc) are
// excluded.
func (c Config) Sanitised() (interface{}, error) {
var node yaml.Node
if err := node.Encode(c); err != nil {
return nil, err
}
if err := Spec().SanitiseYAML(&node, docs.SanitiseConfig{
RemoveTypeField: true,
}); err != nil {
return nil, err
}
var g interface{}
if err := node.Decode(&g); err != nil {
return nil, err
}
return g, nil
}
//------------------------------------------------------------------------------