github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/msp/mgmt/testtools/config.go (about) 1 /* 2 Copyright IBM Corp. 2017 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 msptesttools 18 19 import ( 20 "os" 21 "path/filepath" 22 23 "github.com/hyperledger/fabric/common/util" 24 "github.com/hyperledger/fabric/msp" 25 "github.com/hyperledger/fabric/msp/mgmt" 26 ) 27 28 func getConfigPath(dir string) (string, error) { 29 // Try to read the dir 30 if _, err := os.Stat(dir); err != nil { 31 cfg := os.Getenv("PEER_CFG_PATH") 32 if cfg != "" { 33 dir = filepath.Join(cfg, dir) 34 } else { 35 dir = filepath.Join(os.Getenv("GOPATH"), "/src/github.com/hyperledger/fabric/msp/sampleconfig/") 36 } 37 if _, err := os.Stat(dir); err != nil { 38 return "", err 39 } 40 } 41 return dir, nil 42 } 43 44 // LoadTestMSPSetup sets up the local MSP 45 // and a chain MSP for the default chain 46 func LoadMSPSetupForTesting(dir string) error { 47 var err error 48 if dir, err = getConfigPath(dir); err != nil { 49 return err 50 } 51 conf, err := msp.GetLocalMspConfig(dir, nil, "DEFAULT") 52 if err != nil { 53 return err 54 } 55 56 err = mgmt.GetLocalMSP().Setup(conf) 57 if err != nil { 58 return err 59 } 60 61 err = mgmt.GetManagerForChain(util.GetTestChainID()).Setup([]msp.MSP{mgmt.GetLocalMSP()}) 62 if err != nil { 63 return err 64 } 65 66 return nil 67 }