55package application
66
77import (
8- "io/ioutil"
9-
10- "github.com/elastic/go-ucfg"
11-
12- "gopkg.in/yaml.v2"
13-
14- "github.com/elastic/beats/v7/libbeat/common"
158 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
169 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
17- "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
1810 "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/kibana"
1911)
2012
@@ -34,53 +26,3 @@ func createFleetConfigFromEnroll(accessAPIKey string, kbn *kibana.Config) (*conf
3426 }
3527 return cfg , nil
3628}
37-
38- // LoadConfigFromFile loads the Agent configuration from a file.
39- //
40- // This must be used to load the Agent configuration, so that variables defined in the inputs are not
41- // parsed by go-ucfg. Variables from the inputs should be parsed by the transpiler.
42- func LoadConfigFromFile (path string ) (* config.Config , error ) {
43- in , err := ioutil .ReadFile (path )
44- if err != nil {
45- return nil , err
46- }
47- var m map [string ]interface {}
48- if err := yaml .Unmarshal (in , & m ); err != nil {
49- return nil , err
50- }
51- return LoadConfig (m )
52- }
53-
54- // LoadConfig loads the Agent configuration from a map.
55- //
56- // This must be used to load the Agent configuration, so that variables defined in the inputs are not
57- // parsed by go-ucfg. Variables from the inputs should be parsed by the transpiler.
58- func LoadConfig (in map [string ]interface {}) (* config.Config , error ) {
59- // make copy of a map so we dont affect a caller
60- m := common .MapStr (in ).Clone ()
61-
62- inputs , ok := m ["inputs" ]
63- if ok {
64- // remove the inputs
65- delete (m , "inputs" )
66- }
67- cfg , err := config .NewConfigFrom (m )
68- if err != nil {
69- return nil , err
70- }
71- if ok {
72- inputsOnly := map [string ]interface {}{
73- "inputs" : inputs ,
74- }
75- // convert to config without variable substitution
76- inputsCfg , err := config .NewConfigFrom (inputsOnly , ucfg .PathSep ("." ), ucfg .ResolveNOOP )
77- if err != nil {
78- return nil , err
79- }
80- err = cfg .Merge (inputsCfg , ucfg .PathSep ("." ), ucfg .ResolveNOOP )
81- if err != nil {
82- return nil , err
83- }
84- }
85- return cfg , err
86- }
0 commit comments