Example #1
0
func load(yamlStr string) (*TLSConfig, error) {
	var cfg TLSConfig
	config, err := yaml.NewConfig([]byte(yamlStr))
	if err != nil {
		return nil, err
	}

	if err = config.Unpack(&cfg); err != nil {
		return nil, err
	}
	return &cfg, nil
}
Example #2
0
func load(t *testing.T, in string) cfg.FilebeatConfig {
	yaml, err := yaml.NewConfig([]byte(in))
	if err != nil {
		t.Fatalf("Failed to parse config input: %v", err)
	}

	var config cfg.FilebeatConfig
	err = yaml.Unpack(&config)
	if err != nil {
		t.Fatalf("Failed to unpack config: %v", err)
	}

	return config
}
Example #3
0
// Read reads the configuration from a yaml file into the given interface structure.
// In case path is not set this method reads from the default configuration file for the beat.
func Read(out interface{}, path string) error {

	if path == "" {
		path = *configfile
	}

	filecontent, err := ioutil.ReadFile(path)
	if err != nil {
		return fmt.Errorf("Failed to read %s: %v. Exiting.", path, err)
	}
	filecontent = expandEnv(filecontent)

	config, err := yaml.NewConfig(filecontent, ucfg.PathSep("."))
	if err != nil {
		return fmt.Errorf("YAML config parsing failed on %s: %v. Exiting.", path, err)
	}

	err = config.Unpack(out, ucfg.PathSep("."))
	if err != nil {
		return fmt.Errorf("Failed to apply config %s: %v. Exiting. ", path, err)
	}
	return nil
}
Example #4
0
func NewConfigWithYAML(in []byte, source string) (*Config, error) {
	c, err := yaml.NewConfig(in, ucfg.PathSep("."), ucfg.MetaData(ucfg.Meta{source}))
	return fromConfig(c), err
}