Exemple #1
0
// Initialize its self by given data.
func (ie *InputEntry) BuildFromData(c *entity.Config, data map[interface{}]interface{}) (err error) {
	err = ie.InputEntryBase.BuildFromData(c, data)
	if err != nil {
		return
	}

	var ok bool
	ie.Host, ok = data["host"].(string)
	if !ok {
		err = errors.New(ie.Name + ": 'host' is not specified.")
		return
	}
	defaultCred := c.GetDefaultCredential(ie.Host)
	ie.Cred.User, ok = data["user"].(string)
	if !ok || ie.Cred.User == "" {
		ie.Cred.User = defaultCred.User
		if ie.Cred.User == "" {
			err = errors.New(ie.Name + ": 'user' is not specified.")
			return
		}
	}
	ie.Command, ok = data["command"].(string)
	if !ok {
		err = errors.New(ie.Name + ": 'command' is not specified.")
		return
	}

	//Optional fields
	port, ok := data["port"].(uint16)
	if ok {
		ie.Port = port
	}
	pass, ok := data["pass"].(string)
	if ok {
		ie.Cred.Pass = pass
	}
	identity, ok := data["identity"].(string)
	if ok {
		ie.Cred.Identity = identity
	}

	if ie.Cred.Pass == "" && ie.Cred.Identity == "" {
		ie.Cred.Pass = defaultCred.Pass
		ie.Cred.Identity = defaultCred.Identity
		if ie.Cred.Pass == "" && ie.Cred.Identity == "" {
			err = errors.New("password or identity must be specified.")
		}
	}
	return
}
Exemple #2
0
// Parse "log" section.
func (c *Config) parseLogSection(conf *entity.Config, section map[interface{}]interface{}) (err error) {
	logging, ok := section["logging"].(bool)
	if !ok || !logging {
		conf.Logging = false
		return
	}
	conf.Logging = true

	logPath, ok := section["path"].(string)
	if !ok || len(logPath) == 0 {
		err = errors.New("'path' must be specified.")
		return
	}
	conf.LogPath = logPath
	return
}
Exemple #3
0
// Internal function that parses "input" section entries.
func (c *Config) parseInputSectionEntry(conf *entity.Config, name string, entry map[interface{}]interface{}) (err error) {
	typeName, ok := entry["type"].(string)
	if !ok {
		err = errors.New(name + ": " + "'type' is not specified")
		return
	}

	extension, found := c.extensionManager.GetExtensionPoint(ext.POINT_INPUT_CONFIG_PARSER, typeName)
	if !found {
		err = errors.New(name + ": " + "invalid type '" + typeName + "' specified.")
		return
	}
	inputEntries, err := extension.(ext.InputEntryParser).CreateInputEntriesFromData(conf, name, entry)
	if err != nil {
		return
	}
	conf.InputEntries = append(conf.InputEntries, inputEntries...)
	return
}