MCPcopy Create free account
hub / github.com/AdRoll/baker / NewConfigFromToml

Function NewConfigFromToml

config.go:281–422  ·  view source on GitHub ↗

NewConfigFromToml creates a Config from a reader reading from a TOML configuration. comp describes all the existing components.

(f io.Reader, comp Components)

Source from the content-addressed store, hash-verified

279// NewConfigFromToml creates a Config from a reader reading from a TOML
280// configuration. comp describes all the existing components.
281func NewConfigFromToml(f io.Reader, comp Components) (*Config, error) {
282 f, err := replaceEnvVars(f, os.Getenv)
283 if err != nil {
284 return nil, fmt.Errorf("can't replace config with env vars: %v", err)
285 }
286
287 // Parse che configuration. Part of the configuration will be
288 // captured as toml.Primitive for deferred parsing (see comment
289 // at top of the file)
290 cfg := Config{}
291 md, err := toml.DecodeReader(f, &cfg)
292 if err != nil {
293 return nil, fmt.Errorf("error parsing topology: %v", err)
294 }
295
296 // We now go through inputs, filters and outputs, and match the names
297 // to the actual object descriptions provided by each respective package.
298 // Through the description, we also acquire an instance to the actual
299 // custom configuration structure, that will be filled later.
300 for _, inp := range comp.Inputs {
301 if strings.EqualFold(inp.Name, cfg.Input.Name) {
302 cfg.Input.desc = &inp
303 break
304 }
305 }
306 if cfg.Input.desc == nil {
307 return nil, fmt.Errorf("input does not exist: %q", cfg.Input.Name)
308 }
309
310 for idx := range cfg.Filter {
311 cfgfil := &cfg.Filter[idx]
312 for _, fil := range comp.Filters {
313 if strings.EqualFold(fil.Name, cfgfil.Name) {
314 cfgfil.desc = &fil
315 break
316 }
317 }
318 if cfgfil.desc == nil {
319 return nil, fmt.Errorf("filter does not exist: %q", cfgfil.Name)
320 }
321 }
322
323 for _, out := range comp.Outputs {
324 if strings.EqualFold(out.Name, cfg.Output.Name) {
325 cfg.Output.desc = &out
326 break
327 }
328 }
329 if cfg.Output.desc == nil {
330 return nil, fmt.Errorf("output does not exist: %q", cfg.Output.Name)
331 }
332
333 // Upload can be empty
334 for _, upl := range comp.Uploads {
335 if strings.EqualFold(upl.Name, cfg.Upload.Name) {
336 cfg.Upload.desc = &upl
337 break
338 }

Callers 15

TestCompDescEmptyConfigFunction · 0.92
TestStatsDumperFunction · 0.92
benchmarkTopologyFunction · 0.92
TestRawOutputFieldsFunction · 0.92
TestFileWriterRotateSizeFunction · 0.92
BenchmarkFilesOutputFunction · 0.92
testIntegrationS3Function · 0.92

Calls 6

fillDefaultsMethod · 0.95
replaceEnvVarsFunction · 0.85
cloneConfigFunction · 0.85
decodeAndCheckConfigFunction · 0.85
assignFieldMappingFunction · 0.85
assignValidationMappingFunction · 0.85

Tested by 15

TestCompDescEmptyConfigFunction · 0.74
TestStatsDumperFunction · 0.74
benchmarkTopologyFunction · 0.74
TestRawOutputFieldsFunction · 0.74
TestFileWriterRotateSizeFunction · 0.74
BenchmarkFilesOutputFunction · 0.74
testIntegrationS3Function · 0.74