Skip to content

Commit

Permalink
[FAB-3112] Do not include configtx helper.go at runtime
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Apr 14, 2017
1 parent fe8c71d commit bd14ee7
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions common/configtx/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,20 @@ const (
AcceptAllPolicyKey = "AcceptAllPolicy"
)

var sampleMSPPath string

func dirExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}

func init() {
func getConfigDir() string {
mspSampleConfig := "/msp/sampleconfig"
peerPath := filepath.Join(os.Getenv("PEER_CFG_PATH"), mspSampleConfig)
ordererPath := filepath.Join(os.Getenv("ORDERER_CFG_PATH"), mspSampleConfig)
switch {
case dirExists(peerPath):
sampleMSPPath = peerPath
return
return peerPath
case dirExists(ordererPath):
sampleMSPPath = ordererPath
return
return ordererPath
}

gopath := os.Getenv("GOPATH")
Expand All @@ -66,12 +62,11 @@ func init() {
if !dirExists(samplePath) {
continue
}
sampleMSPPath = samplePath
return samplePath
}

if sampleMSPPath == "" {
logger.Panicf("Could not find genesis.yaml, try setting PEER_CFG_PATH, ORDERER_CFG_PATH, or GOPATH correctly")
}
logger.Panicf("Could not find genesis.yaml, try setting PEER_CFG_PATH, ORDERER_CFG_PATH, or GOPATH correctly")
return ""
}

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

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

// OrdererOrgTemplate returns the SAMPLE org with MSP template
func OrdererOrgTemplate() configtx.Template {
mspConf, err := msp.GetLocalMspConfig(sampleMSPPath, nil, sampleOrgID)
mspConf, err := msp.GetLocalMspConfig(getConfigDir(), nil, sampleOrgID)
if err != nil {
logger.Panicf("Could not load sample MSP config: %s", err)
}
Expand Down

0 comments on commit bd14ee7

Please sign in to comment.