Skip to content

Commit bd14ee7

Browse files
committed
[FAB-3112] Do not include configtx helper.go at runtime
The current code assumes, by virtue of the init() routine in helper.go, that an MSP configuration that is compatible with "DEFAULT"/"sampleconfig" will exist in all contexts (test, development, and runtime). While this is true for test and dev, runtime is not likely to have the sampleconfig available (nor should it). Therefore, we fix the assumption by removing the implicit init() code and only use the logic on demand. It should be noted that any attempts to run "peer channel create" without any file as input will panic under a "runtime" environment (e.g. installed on a system, not built from source). This is true both before and after this patch. This should probably be fixed as a separate issue. Change-Id: I33bcd7d5be716a695c65fc09ae96807a2769f1d9 Signed-off-by: Greg Haskins <[email protected]>
1 parent fe8c71d commit bd14ee7

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

common/configtx/test/helper.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,20 @@ const (
4040
AcceptAllPolicyKey = "AcceptAllPolicy"
4141
)
4242

43-
var sampleMSPPath string
44-
4543
func dirExists(path string) bool {
4644
_, err := os.Stat(path)
4745
return err == nil
4846
}
4947

50-
func init() {
48+
func getConfigDir() string {
5149
mspSampleConfig := "/msp/sampleconfig"
5250
peerPath := filepath.Join(os.Getenv("PEER_CFG_PATH"), mspSampleConfig)
5351
ordererPath := filepath.Join(os.Getenv("ORDERER_CFG_PATH"), mspSampleConfig)
5452
switch {
5553
case dirExists(peerPath):
56-
sampleMSPPath = peerPath
57-
return
54+
return peerPath
5855
case dirExists(ordererPath):
59-
sampleMSPPath = ordererPath
60-
return
56+
return ordererPath
6157
}
6258

6359
gopath := os.Getenv("GOPATH")
@@ -66,12 +62,11 @@ func init() {
6662
if !dirExists(samplePath) {
6763
continue
6864
}
69-
sampleMSPPath = samplePath
65+
return samplePath
7066
}
7167

72-
if sampleMSPPath == "" {
73-
logger.Panicf("Could not find genesis.yaml, try setting PEER_CFG_PATH, ORDERER_CFG_PATH, or GOPATH correctly")
74-
}
68+
logger.Panicf("Could not find genesis.yaml, try setting PEER_CFG_PATH, ORDERER_CFG_PATH, or GOPATH correctly")
69+
return ""
7570
}
7671

7772
// MakeGenesisBlock creates a genesis block using the test templates for the given chainID
@@ -100,7 +95,7 @@ const sampleOrgID = "DEFAULT"
10095

10196
// ApplicationOrgTemplate returns the SAMPLE org with MSP template
10297
func ApplicationOrgTemplate() configtx.Template {
103-
mspConf, err := msp.GetLocalMspConfig(sampleMSPPath, nil, sampleOrgID)
98+
mspConf, err := msp.GetLocalMspConfig(getConfigDir(), nil, sampleOrgID)
10499
if err != nil {
105100
logger.Panicf("Could not load sample MSP config: %s", err)
106101
}
@@ -109,7 +104,7 @@ func ApplicationOrgTemplate() configtx.Template {
109104

110105
// OrdererOrgTemplate returns the SAMPLE org with MSP template
111106
func OrdererOrgTemplate() configtx.Template {
112-
mspConf, err := msp.GetLocalMspConfig(sampleMSPPath, nil, sampleOrgID)
107+
mspConf, err := msp.GetLocalMspConfig(getConfigDir(), nil, sampleOrgID)
113108
if err != nil {
114109
logger.Panicf("Could not load sample MSP config: %s", err)
115110
}

0 commit comments

Comments
 (0)