forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
59 lines (47 loc) · 1.45 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package testutil
import (
"flag"
"fmt"
"io/ioutil"
"strings"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/config/configtest"
"github.com/hyperledger/fabric/msp"
"github.com/spf13/viper"
)
var configLogger = flogging.MustGetLogger("config")
// SetupTestConfig setup the config during test execution
func SetupTestConfig() {
flag.Parse()
// Now set the configuration file
viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
viper.SetConfigName("core") // name of config file (without extension)
configtest.AddDevConfigPath(nil)
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))
}
// Init the BCCSP
var bccspConfig *factory.FactoryOpts
err = viper.UnmarshalKey("peer.BCCSP", &bccspConfig)
if err != nil {
bccspConfig = nil
}
tmpKeyStore, err := ioutil.TempDir("/tmp", "msp-keystore")
if err != nil {
panic(fmt.Errorf("Could not create temporary directory: %s\n", tmpKeyStore))
}
msp.SetupBCCSPKeystoreConfig(bccspConfig, tmpKeyStore)
err = factory.InitFactories(bccspConfig)
if err != nil {
panic(fmt.Errorf("Could not initialize BCCSP Factories [%s]", err))
}
}