Exemple #1
0
func getConfig(flagset *flag.FlagSet, file string) (*config.Config, error) {
	if _, err := os.Stat(file); err != nil {
		glog.Infof("Config file %s does not appear to exist - ignoring")
		file = ""
	}

	opts := globalconf.Options{
		EnvPrefix:  "FLEET_",
		ConfigFile: file,
	}
	gconf, err := globalconf.NewWithOptions(opts)
	if err != nil {
		return nil, err
	}

	gconf.ParseSet("", flagset)

	cfg := config.NewConfig()
	cfg.Verbosity = (*flagset.Lookup("verbosity")).Value.(flag.Getter).Get().(int)
	cfg.EtcdServers = (*flagset.Lookup("etcd_servers")).Value.(flag.Getter).Get().(stringSlice)
	cfg.BootId = (*flagset.Lookup("boot_id")).Value.(flag.Getter).Get().(string)
	cfg.PublicIP = (*flagset.Lookup("public_ip")).Value.(flag.Getter).Get().(string)
	cfg.RawMetadata = (*flagset.Lookup("metadata")).Value.(flag.Getter).Get().(string)
	cfg.UnitPrefix = (*flagset.Lookup("unit_prefix")).Value.(flag.Getter).Get().(string)
	cfg.AgentTTL = (*flagset.Lookup("agent_ttl")).Value.(flag.Getter).Get().(string)

	return cfg, nil
}
Exemple #2
0
func loadConfigFromPath(cp string) (*config.Config, error) {
	cfg := config.NewConfig()

	if cp != "" {
		cfgFile, err := os.Open(cp)
		if err != nil {
			msg := fmt.Sprintf("Unable to open config file at %s: %s", cp, err)
			return nil, errors.New(msg)
		}

		err = config.UpdateConfigFromFile(cfg, cfgFile)
		if err != nil {
			msg := fmt.Sprintf("Failed to parse config file at %s: %s", cp, err)
			return nil, errors.New(msg)
		}
	}

	config.UpdateFlagsFromConfig(cfg)
	return cfg, nil
}