Beispiel #1
1
func loadConfig() {
	stormpath.InitLog()

	viper.SetConfigType("yaml")
	viper.AutomaticEnv()

	//Load bundled default config
	defaultConfig, err := Asset("config/web.stormpath.yaml")
	if err != nil {
		stormpath.Logger.Panicf("[ERROR] Couldn't load default bundle configuration: %s", err)
	}

	viper.ReadConfig(bytes.NewBuffer(defaultConfig))

	//Merge users custom configuration
	viper.SetConfigFile("stormpath.yaml")
	viper.AddConfigPath("~/.stormpath/")
	viper.AddConfigPath(".")
	err = viper.MergeInConfig()
	if err != nil {
		stormpath.Logger.Println("[WARN] User didn't provide custom configuration")
	}

	Config.Produces = viper.GetStringSlice("stormpath.web.produces")
	Config.BasePath = viper.GetString("stormpath.web.basePath")

	loadSocialConfig()
	loadCookiesConfig()
	loadEndpointsConfig()
	loadOAuth2Config()
}
func TestDiscoveryFactory(t *testing.T) {
	viper.SetConfigType("yaml")
	yaml := []byte(`
nuvem.discovery.testdsl.static.servers:
- localhost:8080
- 127.0.0.1:9080
`)
	err := viper.ReadConfig(bytes.NewBuffer(yaml))
	viper.SetDefault("nuvem.discovery.testdsl.factory", discovery.StaticFactoryKey)
	viper.SetDefault("nuvem.loadbalancer.serverlist.testdsl.factory", DisoveryFactoryKey)

	if err != nil { // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
	//	servers := viper.GetStringSlice("nuvem.loadbalancer.test.static.servers")
	//	fmt.Printf("%+v\n", servers)
	//	factory := viper.GetString("nuvem.loadbalancer.test.factory")
	//	fmt.Printf("%+v\n", factory)

	serverList := Create("testdsl")
	servers := assertServerList(t, serverList, 2)

	assertServer(t, servers[0], "localhost", 8080)
	assertServer(t, servers[1], "127.0.0.1", 9080)
}
Beispiel #3
0
func InitConf(configFile string) {
	cfgData, err := ioutil.ReadFile(configFile)
	if err != nil {
		fmt.Println(err)
	}
	viper.SetConfigType("yaml")
	viper.ReadConfig(bytes.NewBuffer(cfgData))
}
Beispiel #4
0
func persistentPreRun(cmd *cobra.Command, args []string) {
	// Viper requires a configuration "file" so we provide an empty one here.
	viper.SetConfigType("yaml")
	var yamlConfig = []byte("")
	viper.ReadConfig(bytes.NewBuffer(yamlConfig))

	loadDefaultSettings()
}
Beispiel #5
0
// Loads the given yaml file as a Value.
func LoadYaml(file string) *Source {
	y, err := ioutil.ReadFile(file)
	maybePanic(err)
	viper.SetConfigType("yaml")
	viper.ReadConfig(bytes.NewBuffer(y))
	conf := viper.AllSettings()

	return NewSource(vals.New(conf))
}
Beispiel #6
0
Datei: load.go Projekt: slok/monf
// LoadFromFileSettings loads the settings from an specified path
func LoadFromFileSettings(path string) {
	data, err := ioutil.ReadFile(path)

	if err != nil {
		log.Warningf("Error loading '%s' settings file", path)
	} else {
		viper.ReadConfig(bytes.NewBuffer(data))
		SpecificConfigPath = path
	}

}
func TestFactory(t *testing.T) {
	viper.SetConfigType("yaml")
	yaml := []byte(``)
	err := viper.ReadConfig(bytes.NewBuffer(yaml))
	viper.SetDefault("nuvem.loadbalancer.test.factory", "NoopLoadBalancer")

	if err != nil { // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	lb := Create("test")
	assertLoadBalancer(t, lb)
}
Beispiel #8
0
// LoadConfig loads out configuration.
func LoadConfig() error {
	fp, err := configFilePath()
	if err != nil {
		return fmt.Errorf("can't find home directory: %v", err)
	}
	if _, err := os.Stat(fp); err == nil {
		file, err := os.Open(fp)
		if err != nil {
			return fmt.Errorf("can't open configuration file %q: %v", fp, err)
		}
		viper.ReadConfig(file)
	}

	return nil
}
Beispiel #9
0
/**
 * Called by PreFlight()
 */
func InitializeConfig() {
	// Viper requires a configuration "file" so we provide an empty one here.
	viper.SetConfigName("grush")
	viper.AddConfigPath("$HOME/.drush")
	viper.SetConfigType("yaml")
	var yamlConfig = []byte("")
	viper.ReadConfig(bytes.NewBuffer(yamlConfig))

	// @todo: Expand to load grush.yml from standard drush locations, plus

	// Load Drush and Grush Config Files
	InitializeGlobalConfig()
	InitializeSiteConfig()

	loadDefaultSettings()
}
func TestFactory(t *testing.T) {
	viper.SetConfigType("yaml")
	yaml := []byte(`
nuvem.loadbalancer.test.serverlist.static.servers:
- localhost:8080
- 127.0.0.1:9080
`)
	err := viper.ReadConfig(bytes.NewBuffer(yaml))
	viper.SetDefault("nuvem.loadbalancer.test.factory", FactoryKey)

	if err != nil { // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	lb := loadbalancer.Create("test")
	assertLoadBalancer(t, lb)
}
Beispiel #11
0
//ParseConfig parses a YAML config  file
func ParseConfig(rawConfig []byte) CCPAlertConfig {
	parsedConfig := new(CCPAlertConfig)

	viper.SetConfigType("yaml")
	viper.ReadConfig(bytes.NewBuffer(rawConfig))

	parsedConfig.AlertEngineConfig.PagerDutyAPIKey = viper.GetString("PagerDutyAPIKey")

	parsedConfig.AlertEngineConfig.EmailServer = viper.GetString("email.server")
	parsedConfig.AlertEngineConfig.EmailUsername = viper.GetString("email.username")
	parsedConfig.AlertEngineConfig.EmailPassword = viper.GetString("email.password")
	parsedConfig.AlertEngineConfig.EmailPort = viper.GetInt("email.port")
	parsedConfig.AlertEngineConfig.EmailRecipient = viper.GetString("email.recipient")

	parsedConfig.InfluxDBConfig = *new(db.InfluxDBConfig)
	parsedConfig.InfluxDBConfig.InfluxDBHost = viper.GetString("influx.host")
	parsedConfig.InfluxDBConfig.InfluxDBPort = viper.GetInt("influx.port")
	parsedConfig.InfluxDBConfig.InfluxDBUsername = viper.GetString("influx.username")
	parsedConfig.InfluxDBConfig.InfluxDBPassword = viper.GetString("influx.password")
	parsedConfig.InfluxDBConfig.InfluxDBDB = viper.GetString("influx.password")

	if (len(parsedConfig.InfluxDBConfig.InfluxDBHost)) == 0 {
		panic("InfluxDB host undefined")
	}

	if parsedConfig.InfluxDBConfig.InfluxDBPort == 0 {
		panic("InfluxDB port undefined")
	}

	if (len(parsedConfig.InfluxDBConfig.InfluxDBUsername)) == 0 {
		panic("InfluxDB username undefined")
	}

	if (len(parsedConfig.InfluxDBConfig.InfluxDBPassword)) == 0 {
		panic("InfluxDB password undefined")
	}

	if (len(parsedConfig.InfluxDBConfig.InfluxDBDB)) == 0 {
		panic("InfluxDB db undefined")
	}

	return *parsedConfig
}
func TestFactory(t *testing.T) {
	viper.SetConfigType("yaml")
	yaml := []byte(``)
	err := viper.ReadConfig(bytes.NewBuffer(yaml))
	viper.SetDefault("nuvem.registry.factory", StaticFactoryKey)

	if err != nil { // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
	//	servers := viper.GetStringSlice("nuvem.loadbalancer.test.static.servers")
	//	fmt.Printf("%+v\n", servers)
	//	factory := viper.GetString("nuvem.loadbalancer.test.factory")
	//	fmt.Printf("%+v\n", factory)

	registry := Create("testreg")

	servers := assertRegistry(t, registry)
	assertServers(t, servers)
}
Beispiel #13
0
// InitConfig initiliaze configuration file
func InitConfig(filename string) (*Config, *Error) {
	viper.SetConfigType("YAML")
	f, err := os.Open(filename)
	if err != nil {
		return nil, &Error{"could not read configuration files."}
	}
	err = viper.ReadConfig(f)
	if err != nil {
		return nil, &Error{"configuration format is not correct."}
	}

	var config Config
	err = viper.Unmarshal(&config)
	if err != nil {
		glog.Errorf("Cannot read configuration. Reason: %s", err)
		return nil, &Error{"cannot read configuration, something must be wrong."}
	}

	return &config, nil
}
Beispiel #14
0
func readConfig() error {

	viper.SetConfigType("yaml")
	viper.SetDefault("proxyList", "/etc/proxy.list")
	viper.SetDefault("check", map[string]interface{}{
		"url":      "http://ya.ru",
		"string":   "yandex",
		"interval": "60m",
		"timeout":  "5s",
	})
	viper.SetDefault("bind", "0.0.0.0:8080")
	viper.SetDefault("workersCount", 20)
	viper.SetDefault("maxTry", 3)
	viper.SetDefault("debug", false)

	var configFile = flag.StringP("config", "c", "/etc/"+appName+".yaml",
		"full path to config")
	var showVersion = flag.BoolP("version", "v", false, "version")
	flag.Parse()

	if *showVersion {
		log.Println(appVersion)
		os.Exit(0)
	}

	file, err := ioutil.ReadFile(*configFile)
	if err != nil {
		return err
	}

	err = viper.ReadConfig(bytes.NewReader(file))
	if err != nil {
		return err
	}

	err = viper.Unmarshal(&cfg)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #15
0
func init_config(path string) {
	viper.SetConfigType("json")

	viper.SetDefault("daemon", map[string]string{})
	viper.SetDefault("daemon.log_file", "/var/log/ng_backend.log")
	viper.SetDefault("daemon.rpc_port", 8800)
	viper.SetDefault("daemon.rpc_host", "locahost")

	viper.SetDefault("ng_state", map[string]string{})
	viper.SetDefault("ng_state.cache.ttl", 10000)
	viper.SetDefault("ng_state.icinga.port", 6558)
	viper.SetDefault("ng_state.icinga.host", "localhost")
	viper.SetDefault("ng_state.icinga.use_unix_socket", false)
	viper.SetDefault("ng_state.icinga.unix_socket", "")
	viper.SetDefault("ng_state.icinga.timeout_enabled", true)
	viper.SetDefault("ng_state.icinga.timeout", 5000)

	viper.SetDefault("ng_metric", map[string]string{})
	viper.SetDefault("ng_metric.mem_storage", map[string]string{})

	viper.SetDefault("ng_metric.collectd.host", "0.0.0.0")
	viper.SetDefault("ng_metric.collectd.port", 27015)
	viper.SetDefault("ng_metric.mem_storage.capacity", 10)
	viper.SetDefault("ng_metric.collectd.filter_enable", true)
	viper.SetDefault("ng_metric.collectd.filter_types", []string{""})
	viper.SetDefault("graph", map[string]string{})
	viper.SetDefault("graph.url", "http://*****:*****@localhost:7474/")

	f, err := os.Open(path)
	panic_config(err)

	defer f.Close()
	reader := bufio.NewReader(f)

	err = viper.ReadConfig(reader)
	if err != nil {
		panic(fmt.Errorf("Cannot read configuration file: %s", err))
	}
}
Beispiel #16
0
func initTestDB() *mgo.Database {
	var db *mgo.Database

	configByte, ferr := ioutil.ReadFile("../config.toml")
	if ferr != nil {
		fmt.Println(ferr.Error())
	}

	viper.SetConfigType("toml")

	verr := viper.ReadConfig(bytes.NewReader(configByte))
	if verr != nil {
		fmt.Println(verr.Error())
	}

	dialURL := "mongodb://" + viper.GetString("database.user") + ":" + viper.GetString("database.password") + "@" + viper.GetString("database.ip") + ":" + viper.GetString("database.port") + "/" + viper.GetString("database.name")
	session, err := mgo.Dial(dialURL)
	if err != nil {
		fmt.Println(err.Error())
	}

	db = session.DB(viper.GetString("dbname"))
	return db
}
Beispiel #17
0
func GetConfig() *Config {
	// Load custom config file if explicitly set.
	if path := viper.GetString("config"); path != "" {
		file, err := os.Open(path)

		if err != nil {
			log.Fatal(err)
		}

		defer file.Close()

		if err = viper.ReadConfig(file); err != nil {
			log.Fatal(err)
		}
	} else {
		viper.ReadInConfig()
	}

	// Parse schemas
	var schemas []*Schema
	for k, v := range viper.GetStringMap("schemas") {
		s := Schema{
			Name: k,
		}

		for xf, xd := range v.(map[interface{}]interface{}) {
			if xd == nil {
				continue
			}

			switch xf.(string) {
			case "scope":
				s.Scope = xd.(string)

			case "field":
				s.Field = xd.(string)

			case "pattern":
				s.Pattern = xd.(string)

			case "file":
				s.File = xd.(string)
			}
		}

		if err := s.Load(); err != nil {
			log.Fatalf("schema %s: %s", k, err)
		}

		schemas = append(schemas, &s)
	}

	return &Config{
		Debug:  viper.GetBool("debug"),
		Config: viper.GetString("config"),

		Mongo: MongoConfig{
			URI: viper.GetString("mongo.uri"),
		},

		HTTP: HTTPConfig{
			Host:    viper.GetString("http.host"),
			Port:    viper.GetInt("http.port"),
			CORS:    viper.GetBool("http.cors"),
			TLSCert: viper.GetString("http.tlscert"),
			TLSKey:  viper.GetString("http.tlskey"),
		},

		SMTP: SMTPConfig{
			Host:     viper.GetString("smtp.host"),
			Port:     viper.GetInt("smtp.port"),
			User:     viper.GetString("smtp.user"),
			Password: viper.GetString("smtp.password"),
			From:     viper.GetString("smtp.from"),
		},

		Schemas: schemas,
	}
}
Beispiel #18
0
func initTestConfig(config string) error {
	viper.SetConfigType("json")
	r := bytes.NewReader([]byte(config))
	return viper.ReadConfig(r)
}
Beispiel #19
0
func initTestConfig(config string) {
	viper.SetConfigType("yml")
	r := bytes.NewReader([]byte(config))
	viper.ReadConfig(r)
}