github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/endorser/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 endorser 18 19 import ( 20 "flag" 21 "fmt" 22 "strings" 23 24 "github.com/op/go-logging" 25 "github.com/spf13/viper" 26 27 "github.com/hyperledger/fabric/bccsp/factory" 28 "github.com/hyperledger/fabric/msp" 29 ) 30 31 // Config the config wrapper structure 32 type Config struct { 33 } 34 35 func init() { 36 37 } 38 39 // SetupTestLogging setup the logging during test execution 40 func SetupTestLogging() { 41 level, err := logging.LogLevel(viper.GetString("logging.peer")) 42 if err == nil { 43 // No error, use the setting 44 logging.SetLevel(level, "main") 45 logging.SetLevel(level, "server") 46 logging.SetLevel(level, "peer") 47 } else { 48 logging.SetLevel(logging.ERROR, "main") 49 logging.SetLevel(logging.ERROR, "server") 50 logging.SetLevel(logging.ERROR, "peer") 51 } 52 } 53 54 // SetupTestConfig setup the config during test execution 55 func SetupTestConfig() { 56 flag.Parse() 57 58 // Now set the configuration file 59 viper.SetEnvPrefix("CORE") 60 viper.AutomaticEnv() 61 replacer := strings.NewReplacer(".", "_") 62 viper.SetEnvKeyReplacer(replacer) 63 viper.SetConfigName("endorser_test") // name of config file (without extension) 64 viper.AddConfigPath("./") // path to look for the config file in 65 err := viper.ReadInConfig() // Find and read the config file 66 if err != nil { // Handle errors reading the config file 67 panic(fmt.Errorf("Fatal error config file: %s \n", err)) 68 } 69 70 SetupTestLogging() 71 72 // Set the number of maxprocs 73 viper.GetInt("peer.gomaxprocs") 74 75 // Init the BCCSP 76 var bccspConfig *factory.FactoryOpts 77 err = viper.UnmarshalKey("peer.BCCSP", &bccspConfig) 78 if err != nil { 79 bccspConfig = nil 80 } 81 82 msp.SetupBCCSPKeystoreConfig(bccspConfig, viper.GetString("peer.mspConfigPath")+"/keystore") 83 84 err = factory.InitFactories(bccspConfig) 85 if err != nil { 86 panic(fmt.Errorf("Could not initialize BCCSP Factories [%s]", err)) 87 } 88 }