forked from BigDataAnalyticsGroup/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-9466] separate dev/test config from prod code
Remove fallback to fabric sample configuration on the GOPATH from the core viper initialization and separate dev/test related config functions from production code packages. Change-Id: I053d0a3fb2d479aa57223cfe6ebcbadaa2f8f290 Signed-off-by: Matthew Sykes <[email protected]>
- Loading branch information
Showing
29 changed files
with
244 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
/* | ||
Copyright Greg Haskins <[email protected]> 2017, All Rights Reserved. | ||
Copyright IBM Corp. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package config | ||
|
@@ -25,8 +16,11 @@ import ( | |
) | ||
|
||
func dirExists(path string) bool { | ||
_, err := os.Stat(path) | ||
return err == nil | ||
fi, err := os.Stat(path) | ||
if err != nil { | ||
return false | ||
} | ||
return fi.IsDir() | ||
} | ||
|
||
func addConfigPath(v *viper.Viper, p string) { | ||
|
@@ -37,48 +31,6 @@ func addConfigPath(v *viper.Viper, p string) { | |
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------- | ||
// GetDevConfigDir() | ||
//---------------------------------------------------------------------------------- | ||
// Returns the path to the default configuration that is maintained with the source | ||
// tree. Only valid to call from a test/development context. | ||
//---------------------------------------------------------------------------------- | ||
func GetDevConfigDir() (string, error) { | ||
gopath := os.Getenv("GOPATH") | ||
if gopath == "" { | ||
return "", fmt.Errorf("GOPATH not set") | ||
} | ||
|
||
for _, p := range filepath.SplitList(gopath) { | ||
devPath := filepath.Join(p, "src/github.com/hyperledger/fabric/sampleconfig") | ||
if !dirExists(devPath) { | ||
continue | ||
} | ||
|
||
return devPath, nil | ||
} | ||
|
||
return "", fmt.Errorf("DevConfigDir not found in %s", gopath) | ||
} | ||
|
||
//---------------------------------------------------------------------------------- | ||
// GetDevMspDir() | ||
//---------------------------------------------------------------------------------- | ||
// Builds upon GetDevConfigDir to return the path to our sampleconfig/msp that is | ||
// maintained with the source tree. Only valid to call from a test/development | ||
// context. Runtime environment should use configuration elements such as | ||
// | ||
// GetPath("peer.mspConfigDir") | ||
//---------------------------------------------------------------------------------- | ||
func GetDevMspDir() (string, error) { | ||
devDir, err := GetDevConfigDir() | ||
if err != nil { | ||
return "", fmt.Errorf("Error obtaining DevConfigDir: %s", devDir) | ||
} | ||
|
||
return filepath.Join(devDir, "msp"), nil | ||
} | ||
|
||
//---------------------------------------------------------------------------------- | ||
// TranslatePath() | ||
//---------------------------------------------------------------------------------- | ||
|
@@ -150,16 +102,11 @@ func InitViper(v *viper.Viper, configName string) error { | |
// If we get here, we should use the default paths in priority order: | ||
// | ||
// *) CWD | ||
// *) The $GOPATH based development tree | ||
// *) /etc/hyperledger/fabric | ||
// | ||
|
||
// CWD | ||
addConfigPath(v, "./") | ||
|
||
// DevConfigPath | ||
AddDevConfigPath(v) | ||
|
||
// And finally, the official path | ||
if dirExists(OfficialPath) { | ||
addConfigPath(v, OfficialPath) | ||
|
@@ -175,19 +122,3 @@ func InitViper(v *viper.Viper, configName string) error { | |
|
||
return nil | ||
} | ||
|
||
//---------------------------------------------------------------------------------- | ||
// AddDevConfigPath() | ||
//---------------------------------------------------------------------------------- | ||
// Helper utility that automatically adds our DevConfigDir to the viper path | ||
//---------------------------------------------------------------------------------- | ||
func AddDevConfigPath(v *viper.Viper) error { | ||
devPath, err := GetDevConfigDir() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
addConfigPath(v, devPath) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.