github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/container/config.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package container 18 19 import ( 20 "flag" 21 "fmt" 22 "runtime" 23 "strings" 24 25 "github.com/op/go-logging" 26 "github.com/spf13/viper" 27 28 "github.com/hyperledger/fabric/bccsp/factory" 29 "github.com/hyperledger/fabric/msp" 30 ) 31 32 // Config the config wrapper structure 33 type Config struct { 34 } 35 36 func init() { 37 38 } 39 40 // SetupTestLogging setup the logging during test execution 41 func SetupTestLogging() { 42 level, err := logging.LogLevel(viper.GetString("peer.logging.level")) 43 if err == nil { 44 // No error, use the setting 45 logging.SetLevel(level, "main") 46 logging.SetLevel(level, "server") 47 logging.SetLevel(level, "peer") 48 } else { 49 vmLogger.Warningf("Log level not recognized '%s', defaulting to %s: %s", viper.GetString("peer.logging.level"), logging.ERROR, err) 50 logging.SetLevel(logging.ERROR, "main") 51 logging.SetLevel(logging.ERROR, "server") 52 logging.SetLevel(logging.ERROR, "peer") 53 } 54 } 55 56 // SetupTestConfig setup the config during test execution 57 func SetupTestConfig() { 58 flag.Parse() 59 60 // Now set the configuration file 61 viper.SetEnvPrefix("CORE") 62 viper.AutomaticEnv() 63 replacer := strings.NewReplacer(".", "_") 64 viper.SetEnvKeyReplacer(replacer) 65 viper.SetConfigName("core") // name of config file (without extension) 66 viper.AddConfigPath("./") // path to look for the config file in 67 viper.AddConfigPath("./../../peer/") // path to look for the config file in 68 err := viper.ReadInConfig() // Find and read the config file 69 if err != nil { // Handle errors reading the config file 70 panic(fmt.Errorf("Fatal error config file: %s \n", err)) 71 } 72 73 SetupTestLogging() 74 75 // Set the number of maxprocs 76 var numProcsDesired = viper.GetInt("peer.gomaxprocs") 77 vmLogger.Debugf("setting Number of procs to %d, was %d\n", numProcsDesired, runtime.GOMAXPROCS(2)) 78 79 // Init the BCCSP 80 var bccspConfig *factory.FactoryOpts 81 err = viper.UnmarshalKey("peer.BCCSP", &bccspConfig) 82 if err != nil { 83 bccspConfig = nil 84 } 85 86 msp.SetupBCCSPKeystoreConfig(bccspConfig, viper.GetString("peer.mspConfigPath")+"/keystore") 87 88 err = factory.InitFactories(bccspConfig) 89 if err != nil { 90 panic(fmt.Errorf("Could not initialize BCCSP Factories [%s]", err)) 91 } 92 }