Ejemplo n.º 1
0
func NewConfig(cfgfile string) *Config {
	var cfg Config
	gcfg.ReadStringInto(&cfg, defaultConfig)
	content, err := ioutil.ReadFile(cfgfile)
	if err != nil {
		log.Fatal(err)
	}
	err = gcfg.ReadStringInto(&cfg, string(content))
	if err != nil {
		log.Fatal("Failed to parse "+cfgfile+":", err)
	}
	return &cfg
}
Ejemplo n.º 2
0
func readConfig() *FactomdConfig {
	cfg := new(FactomdConfig)
	filename := getHomeDir() + "/.factom/factomd.conf"
	log.Println("read factom config file: ", filename)

	// This makes factom config file located at
	//   POSIX (Linux/BSD): ~/.factom/factom.conf
	//   Mac OS: $HOME/Library/Application Support/Factom/factom.conf
	//   Windows: %LOCALAPPDATA%\Factom\factom.conf
	//   Plan 9: $home/factom/factom.conf
	//factomHomeDir := btcutil.AppDataDir("factom", false)
	//defaultConfigFile := filepath.Join(factomHomeDir, "factomd.conf")
	//
	// eventually we need to make data dir as following
	//defaultDataDir   = filepath.Join(factomHomeDir, "data")
	//LdbPath					 = filepath.Join(defaultDataDir, "ldb9")
	//DataStorePath		 = filepath.Join(defaultDataDir, "store/seed/")

	err := gcfg.ReadFileInto(cfg, filename)
	if err != nil {
		log.Println("Server starting with default settings...")
		gcfg.ReadStringInto(cfg, defaultConfig)
	}
	return cfg
}
Ejemplo n.º 3
0
//initConfigurationTo prepara um arquivo de configuração inicial para o diretório informado,
//retornando sua representação em memória
func initConfigurationTo(dir string) localStorageConfig {

	file, err := os.Create(filepath.Join(dir, DIR_CONFIG_FILENAME))

	defer func() {
		file.Close()
	}()

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

	configSample := `
[Global]
locked=false

[Filters]
allow="text/plain"
allow="application/xml"
allow="text/xml"
allow="image/jpeg"
allow="image/png"
allow="image/bmp"
`

	file.WriteString(configSample)

	var config localStorageConfig

	gcfg.ReadStringInto(&config, configSample)

	return config
}
Ejemplo n.º 4
0
Archivo: cfg.go Proyecto: jdk2588/gottp
func ReadConfig(configString string, cfg Configurer) error {
	err := gcfg.ReadStringInto(cfg, configString)
	if err != nil {
		log.Println("Error Loading configuration", err)
	}
	return err
}
Ejemplo n.º 5
0
func ReadConfig() *CliConf {
	cfg := new(CliConf)
	filename := os.Getenv("HOME") + "/.factom/factom-cli.conf"
	if err := gcfg.ReadFileInto(cfg, filename); err != nil {
		gcfg.ReadStringInto(cfg, defaultConf)
	}
	return cfg
}
Ejemplo n.º 6
0
func TryMe(data string) error {
	cfg := struct {
		Section struct {
			Name string
		}
	}{}
	return gcfg.ReadStringInto(&cfg, data)
}
Ejemplo n.º 7
0
// ReadConfig reads the default factomexplorer.conf file and returns the
// ExplorerConfig object corresponding to the state of the conf file.
func ReadConfig() *ExplorerConfig {
	cfg := new(ExplorerConfig)
	filename := os.Getenv("HOME") + "/.factom/factomexplorer.conf"
	err := gcfg.ReadFileInto(cfg, filename)
	if err != nil {
		gcfg.ReadStringInto(cfg, defaultConfig)
	}
	return cfg
}
Ejemplo n.º 8
0
/**
 * ReadConfig reads config from a string
 * @param string The configuration definition
 * @return Config A Config struct, or nil if something went wrong
 * @return error Returns error if something went wrong. Config will be nil in this case.
 */
func ReadConfig(configDef string) (*Config, error) {
	cfg := Config{}
	if err := gcfg.ReadStringInto(&cfg, configDef); err != nil {
		return nil, err
	}

	if cfg.Threads.Hash < 1 {
		return nil, fmt.Errorf("Need at least one hash thread")
	}

	if cfg.Threads.Upload < 1 {
		return nil, fmt.Errorf("Need at least one upload thread")
	}

	if len(cfg.Backup) == 0 {
		return nil, errors.New("No configurations given")
	}

	for key, backup := range cfg.Backup {
		if backup.Region.Region == nil {
			return nil, fmt.Errorf("No region supplied for config `%s`", key)
		}

		if backup.Path == "" {
			return nil, fmt.Errorf("No path supplied for config `%s`", key)
		}

		if backup.Db == "" {
			return nil, fmt.Errorf("No db supplied for config `%s`", key)
		}

		if backup.Vault == "" {
			return nil, fmt.Errorf("No vault supplied for config `%s`", key)
		}

		if backup.AwsAccess != "" && backup.AwsSecret == "" {
			return nil, fmt.Errorf("AWS Access code suplied, but no AWS Secret for config `%s`", key)
		}

		if backup.AwsAccess == "" && backup.AwsSecret != "" {
			return nil, fmt.Errorf("AWS Secret suplied, but no AWS Access code for config `%s`", key)
		}

		if backup.AwsAccess == "" && backup.AwsSecret == "" {
			if cfg.Aws.Access != "" && cfg.Aws.Secret != "" {
				backup.AwsAccess = cfg.Aws.Access
				backup.AwsSecret = cfg.Aws.Secret
			} else {
				return nil, fmt.Errorf("No AWS credentials supplied for backup `%s`", key)
			}
		}
	}

	return &cfg, nil
}
Ejemplo n.º 9
0
//Loads the configurations passed either by flags or by the configuration file
func LoadConfiguration() Config {
	flag.Parse()
	var cfg Config
	if *flConfig != "" {
		_ = gcfg.ReadFileInto(&cfg, *flConfig)
	} else {
		_ = gcfg.ReadStringInto(&cfg, defaultConfig)
	}

	var env = os.Getenv("EGI_AR_REST_API_ENV")
	switch env {
	default:
		os.Setenv("EGI_AR_REST_API_ENV", "development")
	case "test":
	case "production":
	}

	if *flServerIp != "" {
		cfg.Server.Bindip = *flServerIp
	}
	if *flServerPort != 0 {
		cfg.Server.Port = *flServerPort
	}
	if *flServerMaxProcs != 0 {
		cfg.Server.Maxprocs = *flServerMaxProcs
	}
	if *flMongoHost != "" {
		cfg.MongoDB.Host = *flMongoHost
	}
	if *flMongoPort != 0 {
		cfg.MongoDB.Port = *flMongoPort
	}
	if *flMongoDatabase != "" {
		cfg.MongoDB.Db = *flMongoDatabase
	}
	if *flCache == "yes" {
		cfg.Server.Cache = true
	}
	if *flGzip == "no" {
		cfg.Server.Gzip = false
	}
	if *flProfile != "" {
		cfg.Profile = *flProfile
	}

	if *flCert != "" {
		cfg.Server.Cert = *flCert
	}

	if *flPrivKey != "" {
		cfg.Server.Privkey = *flPrivKey
	}

	return cfg
}
Ejemplo n.º 10
0
func defaultConfig() (Config, error) {
	var def Config

	err := gcfg.ReadStringInto(&def, cfg)

	if err != nil {
		return Config{}, err
	}

	def.API.Version = apiversion
	return def, nil
}
Ejemplo n.º 11
0
func LoadConfiguration(cfgFile string) Config {
	var err error
	var cfg configFile
	if cfgFile != "" {
		err = gcfg.ReadFileInto(&cfg, cfgFile)
	} else {
		err = gcfg.ReadStringInto(&cfg, defaultConfig)
	}
	if err != nil {
		log.Panic(err)
	}
	return cfg.Mongo
}
Ejemplo n.º 12
0
func loadConfigFromString(bytes []byte, user string) (config Configuration, err error) {
	inicfg := struct {
		Dockersh Configuration
		User     map[string]*Configuration
	}{}
	err = gcfg.ReadStringInto(&inicfg, string(bytes))
	if err != nil {
		return config, err
	}
	if inicfg.User[user] == nil {
		return inicfg.Dockersh, nil
	}
	return mergeConfigs(inicfg.Dockersh, *inicfg.User[user], false), nil
}
func ExampleReadStringInto() {
	cfgStr := `; Comment line
[section]
name=value # comment`
	cfg := struct {
		Section struct {
			Name string
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Println(cfg.Section.Name)
	// Output: value
}
func ExampleReadStringInto_hyphens() {
	cfgStr := `; Comment line
[section-name]
variable-name=value # comment`
	cfg := struct {
		Section_Name struct {
			Variable_Name string
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Println(cfg.Section_Name.Variable_Name)
	// Output: value
}
func ExampleReadStringInto_bool() {
	cfgStr := `; Comment line
[section]
switch=on`
	cfg := struct {
		Section struct {
			Switch bool
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Println(cfg.Section.Switch)
	// Output: true
}
func ExampleReadStringInto_unicode() {
	cfgStr := `; Comment line
[甲]
乙=丙 # comment`
	cfg := struct {
		X甲 struct {
			X乙 string
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Println(cfg.X甲.X乙)
	// Output: 丙
}
func ExampleReadStringInto_multivalue() {
	cfgStr := `; Comment line
[section]
multi=value1
multi=value2`
	cfg := struct {
		Section struct {
			Multi []string
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Println(cfg.Section.Multi)
	// Output: [value1 value2]
}
Ejemplo n.º 18
0
func Load(cfgFile string) Config {
	var err error
	var cfg configFile

	if cfgFile != "" {
		err = gcfg.ReadFileInto(&cfg, cfgFile)
	} else {
		err = gcfg.ReadStringInto(&cfg, defaultConfig)
	}
	if err != nil {
		fmt.Printf("Failed to init config, %v\n", err)
		os.Exit(1)
	}

	cfg.Main.Storages = parseStorages(cfg.Main.Storage)
	return cfg.Main
}
Ejemplo n.º 19
0
func LoadConfig(configFile string) *Config {

	var cfg Config
	var err error

	if configFile != "" {
		err = gcfg.ReadFileInto(&cfg, configFile)
	} else {
		err = gcfg.ReadStringInto(&cfg, defaultConfig)
	}

	if err != nil {
		fmt.Printf("Reading config error: %s\n", err)
	}

	return &cfg
}
Ejemplo n.º 20
0
//LoadConfiguration loads the configuration file
func LoadConfiguration(cfgFile string) models.AppConfig {
	var err error
	var cfg configFile

	if cfgFile != "" {
		err = gcfg.ReadFileInto(&cfg, cfgFile)
	} else {
		err = gcfg.ReadStringInto(&cfg, defaultConfig)
	}

	if err != nil {
		panic(err)
	}

	setupLog(cfg.Server.LogFile)

	return cfg.Server
}
func ExampleReadStringInto_subsections() {
	cfgStr := `; Comment line
[profile "A"]
color = white

[profile "B"]
color = black
`
	cfg := struct {
		Profile map[string]*struct {
			Color string
		}
	}{}
	err := gcfg.ReadStringInto(&cfg, cfgStr)
	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
	}
	fmt.Printf("%s %s\n", cfg.Profile["A"].Color, cfg.Profile["B"].Color)
	// Output: white black
}
Ejemplo n.º 22
0
func ReadConfig(filename string) *FactomdConfig {
	if filename == "" {
		filename = ConfigFilename()
	}
	cfg := new(FactomdConfig)

	// This makes factom config file located at
	//   POSIX (Linux/BSD): ~/.factom/factom.conf
	//   Mac OS: $HOME/Library/Application Support/Factom/factom.conf
	//   Windows: %LOCALAPPDATA%\Factom\factom.conf
	//   Plan 9: $home/factom/factom.conf
	//factomHomeDir := btcutil.AppDataDir("factom", false)
	//defaultConfigFile := filepath.Join(factomHomeDir, "factomd.conf")
	//
	// eventually we need to make data dir as following
	//defaultDataDir   = filepath.Join(factomHomeDir, "data")
	//LdbPath                     = filepath.Join(defaultDataDir, "ldb9")
	//DataStorePath         = filepath.Join(defaultDataDir, "store/seed/")

	err := gcfg.ReadFileInto(cfg, filename)
	if err != nil {
		log.Printfln("Reading from '%s'", filename)
		log.Printfln("ERROR Reading config file!\nServer starting with default settings...\n%v\n", err)
		gcfg.ReadStringInto(cfg, defaultConfig)
	}

	// Default to home directory if not set
	if len(cfg.App.HomeDir) < 1 {
		cfg.App.HomeDir = GetHomeDir() + "/.factom/m2/"
	}

	// TODO: improve the paths after milestone 1
	cfg.App.LdbPath = cfg.App.HomeDir + cfg.App.LdbPath
	cfg.App.BoltDBPath = cfg.App.HomeDir + cfg.App.BoltDBPath
	cfg.App.DataStorePath = cfg.App.HomeDir + cfg.App.DataStorePath
	cfg.Log.LogPath = cfg.App.HomeDir + cfg.Log.LogPath
	cfg.Wallet.BoltDBPath = cfg.App.HomeDir + cfg.Wallet.BoltDBPath
	cfg.App.ExportDataSubpath = cfg.App.HomeDir + cfg.App.ExportDataSubpath

	return cfg
}
// Setup the Test Environment
// This function runs before any test and setups the environment
// A test configuration object is instantiated using a reference
// to testdb: AR_test. Also here is are instantiated some expected
// xml response validation messages (authorization,crud responses).
// Also the testdb is seeded with two av.profiles ("ap1","ap2")
// and with an authorization token:"S3CR3T"
func (suite *AvProfileTestSuite) SetupTest() {

	const testConfig = `
    [server]
    bindip = ""
    port = 8080
    maxprocs = 4
    cache = false
    lrucache = 700000000
    gzip = true
    [mongodb]
    host = "127.0.0.1"
    port = 27017
    db = "AR_test"
`

	_ = gcfg.ReadStringInto(&suite.cfg, testConfig)

	suite.resp_profileCreated = " <root>\n" +
		"   <Message>Availability Profile record successfully created</Message>\n </root>"

	suite.resp_profileUpdated = " <root>\n" +
		"   <Message>Availability Profile was successfully updated</Message>\n </root>"

	suite.resp_profileDeleted = " <root>\n" +
		"   <Message>Availability Profile was successfully deleted</Message>\n </root>"

	suite.resp_unauthorized = "Unauthorized"

	suite.resp_no_id = " <root>\n" +
		"   <Message>No profile matching the requested id</Message>\n </root>"

	suite.resp_bad_json = " <root>\n" +
		"   <Message>Malformated json input data</Message>\n </root>"

	// Connect to mongo testdb
	session, _ := mongo.OpenSession(suite.cfg)

	// Add authentication token to mongo testdb
	seed_auth := bson.M{"apiKey": "S3CR3T"}
	_ = mongo.Insert(session, suite.cfg.MongoDB.Db, "authentication", seed_auth)

	// seed mongo
	session, err := mgo.Dial(suite.cfg.MongoDB.Host)
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Insert first seed profile
	c := session.DB(suite.cfg.MongoDB.Db).C("aps")
	c.Insert(bson.M{"name": "ap1", "namespace": "namespace1", "poems": []string{"poem01"},
		"groups": [][]string{
			[]string{"ap1-service1", "ap1-service2", "ap1-service3"},
			[]string{"ap1-service4", "ap1-service5", "ap1-service6"}}})
	// Insert first seed profile
	c.Insert(bson.M{"name": "ap2", "namespace": "namespace2", "poems": []string{"poem02"},
		"groups": [][]string{
			[]string{"ap2-service1", "ap2-service2", "ap2-service3"},
			[]string{"ap2-service4", "ap2-service5", "ap2-service6"}}})

}
Ejemplo n.º 24
0
func (c *Config) Load(ini string) {
	err := gcfg.ReadStringInto(c, ini)
	if err != nil {
		logger.Critical("error parsing config:", err)
	}
}
Ejemplo n.º 25
0
func (self *Config) Load(ini string) {
	err := gcfg.ReadStringInto(self, ini)
	if err != nil {
		Critical("error: cannot parse config", err)
	}
}