Exemple #1
2
// LoadConfig loads the config into the Config Struct and returns the // ConfigStruct object. Will load from environmental variables (all caps) if we
// set a flag to true.
func LoadConfig() ConfigStruct {
	viper.SetConfigName("config")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(".")
	viper.AddConfigPath("../")
	viper.AddConfigPath("/etc/")
	viper.AddConfigPath("$GOPATH/src/github.com/GrappigPanda/notorious/")

	err := viper.ReadInConfig()
	if err != nil {
		panic("Failed to open config file")
	}

	if viper.GetBool("UseEnvVariables") == true {
		viper.AutomaticEnv()
		viper.BindEnv("dbuser")
	}

	whitelist, err := strconv.ParseBool(viper.Get("whitelist").(string))
	if err != nil {
		whitelist = false
	}

	return loadSQLOptions(whitelist)
}
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()
}
Exemple #3
0
func init() {
	viper.SetConfigName("telebot")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(".")
	viper.AddConfigPath("$HOME/.telebot")

	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	dsn = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8",
		viper.GetString("mysql.telebot.user"),
		viper.GetString("mysql.telebot.password"),
		viper.GetString("mysql.telebot.host"),
		viper.GetString("mysql.telebot.port"),
		viper.GetString("mysql.telebot.dbname"))

	db, err = sql.Open("mysql", dsn)
	checkErr(err)

	err = db.Ping()
	checkErr(err)

	go func() {
		tick := time.Tick(rTime * time.Second)
		for range tick {
			if err := db.Ping(); err != nil {
				log.Println("Connection to DB lost (try reconnect after", rTime, "seconds)")
			}
		}
	}()
}
Exemple #4
0
func configInit() {
	viper.SetEnvPrefix("srb")

	var configPath string

	flag.StringVar(&configPath, "config", "", "Path of configuration file without name (name must be config.yml)")
	flag.Parse()

	if len(configPath) > 0 {
		viper.AddConfigPath(configPath)
	}

	configPath = os.Getenv("SRB_CONFIG")
	if len(configPath) > 0 {
		viper.AddConfigPath(configPath)
	}

	viper.AddConfigPath("/etc/slack-redmine-bot/")
	viper.AddConfigPath(".")

	viper.SetConfigName("config")
	viper.SetConfigType("yaml")

	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Error in config file. %s \n", err))
	}
}
Exemple #5
0
func init() {
	//Begin cobra configuration
	RootCommand.PersistentFlags().StringVarP(&server, "server", "s", "localhost", "Server to connect to, separate multiple servers with a \",\"")
	RootCommand.PersistentFlags().StringVarP(&keyspace, "keyspace", "k", "cassfs", "Keyspace to use for cassandra")
	RootCommand.PersistentFlags().StringVar(&statedir, "statedir", "/var/run/cassfs", "Directory to use for state")
	RootCommand.PersistentFlags().IntVarP(&owner, "owner", "o", 1, "Owner ID")
	RootCommand.PersistentFlags().StringVarP(&environment, "environment", "e", "production", "Environment to mount")
	RootCommand.PersistentFlags().Bool("debug", false, "Enable debugging")
	//Begin viper configuration
	viper.SetEnvPrefix("CASSFS")
	viper.AutomaticEnv()
	//End viper configuration
	//Read from a config file
	viper.SetConfigName("cassfs")
	viper.SetConfigType("yaml")
	viper.AddConfigPath("/etc/cassfs")
	viper.AddConfigPath("$HOME/.cassfs")
	viper.AddConfigPath(".")
	//Begin viper/cobra integration
	viper.BindPFlag("server", RootCommand.PersistentFlags().Lookup("server"))
	viper.BindPFlag("statedir", RootCommand.PersistentFlags().Lookup("statedir"))
	viper.BindPFlag("keyspace", RootCommand.PersistentFlags().Lookup("keyspace"))
	viper.BindPFlag("owner", RootCommand.PersistentFlags().Lookup("owner"))
	viper.BindPFlag("environment", RootCommand.PersistentFlags().Lookup("environment"))
	viper.BindPFlag("debug", RootCommand.PersistentFlags().Lookup("debug"))
}
Exemple #6
0
func main() {
	filter := &logutils.LevelFilter{
		Levels:   []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
		MinLevel: logutils.LogLevel("INFO"),
		Writer:   os.Stderr,
	}
	log.SetOutput(filter)

	viper.SetConfigName("Rigfile")
	viper.AddConfigPath("$HOME/.rigger/")
	viper.AddConfigPath(".")

	err := viper.ReadInConfig()
	if err != nil {
		if _, ok := err.(viper.UnsupportedConfigError); ok {
			log.Printf("[ERROR] No Rigfile exists.")
			os.Exit(1)
		} else {
			log.Printf("[ERROR] %s", err)
		}
	}

	var cmdUp = &cobra.Command{
		Use:   "up",
		Short: "Create my infrastructure",
		Long:  `Do lots of work`,
		Run: func(cmd *cobra.Command, args []string) {
			log.Printf("[INFO] Rigger lifting!")
		},
	}

	var rootCmd = &cobra.Command{Use: "rigger"}
	rootCmd.AddCommand(cmdUp)
	rootCmd.Execute()
}
Exemple #7
0
func init() {
	Root.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
	Root.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
	Root.Flags().IntVarP(&Port, "port", "p", 2714, "port number to run on")
	Root.Flags().StringVarP(&DBName, "dbname", "d", "kaiju", "name of the database")
	Root.Flags().StringVarP(&Host, "host", "h", "", "host to run on")
	Root.Flags().IntVar(&DBPort, "dbport", 27017, "port to access mongoDB")
	Root.Flags().StringVar(&DBHost, "dbhost", "localhost", "host where mongoDB is")

	viper.SetConfigName(CfgFile)
	viper.AddConfigPath("./")
	viper.AddConfigPath("/etc/kaiju/")
	err := viper.ReadInConfig()
	if err != nil {
		jww.ERROR.Println("Config not found... using only defaults, stuff may not work")
	}

	viper.Set("port", Port)
	viper.Set("host", Host)
	viper.Set("dbname", DBName)
	viper.Set("dbport", DBPort)
	viper.Set("dbhost", DBHost)
	viper.Set("verbose", Verbose)

	db_init()
}
Exemple #8
0
func InitConfig(configFile string) {
	SetDefaults()

	if configFile != "" {
		if _, err := os.Stat(configFile); os.IsNotExist(err) {
			log.WithFields(log.Fields{"file": configFile}).Fatal("Config file does not exist")
		}

		// Load the config file if supplied
		viper.SetConfigFile(configFile)
	} else {
		// Otherwise use the defaults
		viper.SetConfigName("agent")
		viper.AddConfigPath("/etc/reeve")
		viper.AddConfigPath("$HOME/.reeve")
	}

	err := viper.ReadInConfig()
	if err != nil {
		// Check if we got an unsupported config error
		// If so it means that no files were found, and we can just skip it using our defaults
		_, ok := err.(viper.UnsupportedConfigError)
		if !ok {
			log.WithError(err).Fatal("Could not read config")
		}

		log.Debug("No config file available, using all defaults")
	}
}
Exemple #9
0
// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
	viper.SetConfigName("grasshopper")          // name of config file (without extension)
	viper.AddConfigPath("/etc/grasshopper.d/")  // path to look for the config file
	viper.AddConfigPath("$HOME/.grasshopper.d") // call multiple times to add many search paths
	viper.AddConfigPath(".")                    // optionally look for config in the working directory

	// read config from storage
	err := viper.ReadInConfig() // FIXME
	if err != nil {
		jww.INFO.Println("Unable to locate Config file. I will fall back to my defaults...")
	}

	// default settings
	viper.SetDefault("Verbose", false)
	viper.SetDefault("DryRun", false)
	viper.SetDefault("DoLog", true)

	// bind config to command flags
	if grasshopperCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}
	if grasshopperCmdV.PersistentFlags().Lookup("log").Changed {
		viper.Set("DoLog", DoLog)
	}
}
func init() {
	jww.SetLogThreshold(jww.LevelTrace)
	jww.SetStdoutThreshold(jww.LevelInfo)

	log.Println("initing config ...")

	viper.SetConfigName("zookeeper-helper")
	viper.AddConfigPath("./")
	viper.AddConfigPath("$HOME/.omega/")
	viper.AddConfigPath("/etc/omega/")
	viper.SetConfigType("yaml")

	if err := viper.ReadInConfig(); err != nil {
		log.Panicln("can't read config file:", err)
	}

	initDefault()

	if err := viper.Unmarshal(&pairs); err != nil {
		log.Panicln("can't covert to config pairs: ", err)
	}

	if !pairs.Debugging {
		jww.SetLogThreshold(jww.LevelError)
		jww.SetStdoutThreshold(jww.LevelError)
	}

	log.Printf("initialized config pairs: %+v\n", pairs)
}
Exemple #11
0
func initConfig() {
	// defaults
	viper.SetDefault("adminroot", "/admin/") // front end location of admin
	viper.SetDefault("admindir", "./admin")  // location of admin assets (relative to site directory)
	viper.SetDefault("contentdir", "content")

	// config name and location
	viper.SetConfigName("config")

	viper.AddConfigPath("/etc/topiary")
	viper.AddConfigPath(".")

	// read config
	err := viper.ReadInConfig()

	if err != nil {
		fmt.Println("No topiary config found. Using defaults.")
	}

	// watch config ; TODO : config to turn this on/off
	viper.WatchConfig()
	viper.OnConfigChange(func(e fsnotify.Event) {
		fmt.Println("Config file changed:", e.Name)
	})
}
Exemple #12
0
// LoadGlobalConfig loads Hugo configuration into the global Viper.
func LoadGlobalConfig(relativeSourcePath, configFilename string) error {

	if relativeSourcePath == "" {
		relativeSourcePath = "."
	}

	viper.AutomaticEnv()
	viper.SetEnvPrefix("hugo")
	viper.SetConfigFile(configFilename)
	// See https://github.com/spf13/viper/issues/73#issuecomment-126970794
	if relativeSourcePath == "" {
		viper.AddConfigPath(".")
	} else {
		viper.AddConfigPath(relativeSourcePath)
	}
	err := viper.ReadInConfig()
	if err != nil {
		if _, ok := err.(viper.ConfigParseError); ok {
			return err
		}
		return fmt.Errorf("Unable to locate Config file. Perhaps you need to create a new site.\n       Run `hugo help new` for details. (%s)\n", err)
	}

	viper.RegisterAlias("indexes", "taxonomies")

	loadDefaultSettings()

	return nil
}
Exemple #13
0
func init() {
	viper.SetConfigName("dkron")        // name of config file (without extension)
	viper.AddConfigPath("/etc/dkron")   // call multiple times to add many search paths
	viper.AddConfigPath("$HOME/.dkron") // call multiple times to add many search paths
	viper.AddConfigPath("./config")     // call multiple times to add many search paths
	viper.SetEnvPrefix("dkron")         // will be uppercased automatically
	viper.AutomaticEnv()
}
Exemple #14
0
func main() {
	// For environment variables.
	viper.SetEnvPrefix(cmdRoot)
	viper.AutomaticEnv()
	replacer := strings.NewReplacer(".", "_")
	viper.SetEnvKeyReplacer(replacer)

	// Define command-line flags that are valid for all peer commands and
	// subcommands.
	mainFlags := mainCmd.PersistentFlags()
	mainFlags.BoolVarP(&versionFlag, "version", "v", false, "Display current version of fabric peer server")

	mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
	viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
	testCoverProfile := ""
	mainFlags.StringVarP(&testCoverProfile, "test.coverprofile", "", "coverage.cov", "Done")

	var alternativeCfgPath = os.Getenv("PEER_CFG_PATH")
	if alternativeCfgPath != "" {
		logger.Infof("User defined config file path: %s", alternativeCfgPath)
		viper.AddConfigPath(alternativeCfgPath) // Path to look for the config file in
	} else {
		viper.AddConfigPath("./") // Path to look for the config file in
		// Path to look for the config file in based on GOPATH
		gopath := os.Getenv("GOPATH")
		for _, p := range filepath.SplitList(gopath) {
			peerpath := filepath.Join(p, "src/github.com/hyperledger/fabric/peer")
			viper.AddConfigPath(peerpath)
		}
	}

	// Now set the configuration file.
	viper.SetConfigName(cmdRoot) // Name of config file (without extension)

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

	mainCmd.AddCommand(version.Cmd())
	mainCmd.AddCommand(node.Cmd())
	mainCmd.AddCommand(network.Cmd())
	mainCmd.AddCommand(chaincode.Cmd())

	runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))

	// Init the crypto layer
	if err := crypto.Init(); err != nil {
		panic(fmt.Errorf("Failed to initialize the crypto layer: %s", err))
	}

	// On failure Cobra prints the usage message and error string, so we only
	// need to exit with a non-0 status
	if mainCmd.Execute() != nil {
		os.Exit(1)
	}
	logger.Info("Exiting.....")
}
Exemple #15
0
func setupTestConfig() {
	viper.SetConfigName("openchain") // name of config file (without extension)
	viper.AddConfigPath("./")        // path to look for the config file in
	viper.AddConfigPath("./..")      // path to look for the config file in
	err := viper.ReadInConfig()      // Find and read the config file
	if err != nil {                  // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #16
0
func initConfig() {
	if CfgFile != "" {
		viper.SetConfigFile(CfgFile)
	}
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/dagobah/")
	viper.AddConfigPath("$HOME/.dagobah/")
	viper.ReadInConfig()
}
Exemple #17
0
func initConfig() {
	if CfgFile != "" {
		viper.SetConfigFile(CfgFile)
	}
	viper.SetConfigName("config")          // name of config file (without extension)
	viper.AddConfigPath("/etc/dagobah/")   // path to look for the config file in
	viper.AddConfigPath("$HOME/.dagobah/") // call multiple times to add many search paths
	viper.ReadInConfig()
}
Exemple #18
0
func readConfig() {
	path, _ := osext.ExecutableFolder()
	viper.AddConfigPath("/etc/eremetic")
	viper.AddConfigPath(path)
	viper.AutomaticEnv()
	viper.SetConfigName("eremetic")
	viper.SetDefault("loglevel", "debug")
	viper.SetDefault("database", "db/eremetic.db")
	viper.ReadInConfig()
}
Exemple #19
0
func ReadConfig() {
	viper.SetConfigType("json")
	viper.SetConfigName("config") // name of config file (without extension)
	viper.AddConfigPath("$HOME/whalee-core")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #20
0
func LoadConfig() {
	viper.SetConfigType("json")
	viper.SetConfigName("config")
	viper.AddConfigPath(".")
	viper.AddConfigPath("$GOPATH/src/github.com/cyarie/trump_tweets/config/")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Printf("Error reading config file: %s\n", err.Error())
	}
}
Exemple #21
0
func Config() {
	viper.SetConfigName("config")
	viper.AddConfigPath("$HOME/." + Name)
	viper.AddConfigPath(".")

	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #22
0
func init() {
	viper.SetConfigName("config")
	viper.AddConfigPath(".")
	viper.AddConfigPath("$HOME/.futfut")
	viper.AddConfigPath("/")
	err := viper.ReadInConfig()
	if err != nil {
		logger.Fatal("No configuration file loaded - exiting")
	}
}
Exemple #23
0
func init() {
	viper.SetConfigName(".fix-imports")
	viper.AddConfigPath(".")
	viper.AddConfigPath("$HOME")
	if err := viper.ReadInConfig(); err != nil {
		fmt.Println("Error reading config file: %s\n", err)
		os.Exit(-1)
	}

	viper.Unmarshal(&config)
}
Exemple #24
0
// Initialize Configuration
func InitializeConfig() {
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/cnmonitor2graphite/")
	viper.AddConfigPath("$HOME/.cnmonitor2graphite/")
	viper.Set("Verbose", true)
	viper.SetConfigType("toml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #25
0
func setupTestConfig() {
	primitives.SetSecurityLevel("SHA3", 256)
	viper.AutomaticEnv()
	viper.SetConfigName("ca_test") // name of config file (without extension)
	viper.AddConfigPath("./")      // path to look for the config file in
	viper.AddConfigPath("./..")    // path to look for the config file in
	err := viper.ReadInConfig()    // Find and read the config file
	if err != nil {                // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #26
0
// LoadConfigByName loads a config from a specific file
// Used for separating test from operational configuration
func LoadConfigByPathWOExtension(name string) {
	var isFatal bool
	var tmp *Config

	tmp = new(Config)

	cLock.RLock()
	isFatal = (config == nil)
	cLock.RUnlock()
	viper.SetConfigName(name)
	viper.SetConfigType("json")

	userConfigFolder := getUserConfigFolderPath()
	configFolder := getConfigFolderPath()

	if userConfigFolder != "" {
		viper.AddConfigPath(userConfigFolder) // user's own personal config file
	}
	if configFolder != "" {
		viper.AddConfigPath(configFolder) // General fallback config file
	}

	if err := viper.ReadInConfig(); err != nil {
		// No config to start up on
		if isFatal {
			log.Debugf("Failed to find config in: %s (user) or %s (fallback)",
				userConfigFolder, configFolder)
			panic(err)
		} else {
			log.Errorf("Failed to load configuration from %s\n", name)
			return
		}
	}

	viper.Unmarshal(tmp)
	sanitize(tmp)

	cLock.Lock()
	if config == nil {
		tmp.Version = 1
	} else {
		tmp.Version = config.Version + 1
	}

	config = tmp
	cLock.Unlock()

	log.WithFields(log.Fields{
		"path":        viper.ConfigFileUsed(),
		"confVersion": config.Version,
	}).Info("Success loading configuration")

}
Exemple #27
0
func initConfig() {
	if CfgFile != "" {
		viper.SetConfigFile(CfgFile)
	}
	viper.SetConfigName("config")
	viper.AddConfigPath("$HOME/.cyboard/")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #28
0
func init() {
	viper.SetEnvPrefix("snake")
	viper.BindEnv("target")
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/snake/")
	viper.AddConfigPath("$HOME/.snake")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig() // Find and read the config file
	if err != nil {             // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}
Exemple #29
0
func initConfig() {
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/localfm")
	viper.AddConfigPath("$HOME/.config/localfm")
	viper.AddConfigPath("$XDG_CONFIG_HOME/localfm")
	viper.SetConfigType("yml")

	err := viper.ReadInConfig()
	if err != nil {
		log.Printf("Fatal error config file %s\n", err)
	}
}
Exemple #30
0
// LoadConfig loads the configuration from a config file.
func LoadConfig() {
	Log("Loading viper config.", "info")
	viper.SetConfigName("config")
	viper.AddConfigPath("/etc/goshe/")
	viper.AddConfigPath(".")
	viper.SetConfigType("yaml")
	err := viper.ReadInConfig()
	if err != nil {
		Log(fmt.Sprintf("No config file found: %s \n", err), "info")
	}
	viper.SetEnvPrefix("GOSHE")
}