Skip to content

Commit

Permalink
msp/mgmt: remove LoadLocalMsp
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm authored and Jason Yellick committed Mar 15, 2021
1 parent 50406fe commit c40cce0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
15 changes: 0 additions & 15 deletions msp/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,13 @@ import (
"sync"

"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/msp/cache"
"github.com/pkg/errors"
"github.com/spf13/viper"
)

// LoadLocalMsp loads the local MSP from the specified directory
func LoadLocalMsp(dir string, bccspConfig *factory.FactoryOpts, mspID string) error {
if mspID == "" {
return errors.New("the local MSP must have an ID")
}

conf, err := msp.GetLocalMspConfig(dir, bccspConfig, mspID)
if err != nil {
return err
}

return GetLocalMSP(factory.GetDefault()).Setup(conf)
}

// FIXME: AS SOON AS THE CHAIN MANAGEMENT CODE IS COMPLETE,
// THESE MAPS AND HELPER FUNCTIONS SHOULD DISAPPEAR BECAUSE
// OWNERSHIP OF PER-CHAIN MSP MANAGERS WILL BE HANDLED BY IT;
Expand Down
17 changes: 8 additions & 9 deletions msp/mgmt/mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,17 @@ func LoadMSPSetupForTesting() (bccsp.BCCSP, error) {
}

func TestLocalMSP(t *testing.T) {
mspDir := configtest.GetDevMspDir()
err := LoadLocalMsp(mspDir, nil, "SampleOrg")
if err != nil {
t.Fatalf("LoadLocalMsp failed, err %s", err)
}

cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
require.NoError(t, err)

mspDir := configtest.GetDevMspDir()
conf, err := msp.GetLocalMspConfig(mspDir, nil, "SampleOrg")
require.NoError(t, err, "failed to get local MSP config")
err = GetLocalMSP(cryptoProvider).Setup(conf)
require.NoError(t, err, "failed to setup local MSP")

_, err = GetLocalMSP(cryptoProvider).GetDefaultSigningIdentity()
if err != nil {
t.Fatalf("GetDefaultSigningIdentity failed, err %s", err)
}
require.NoError(t, err, "failed to get default signing identity")
}

func TestMain(m *testing.M) {
Expand Down
6 changes: 0 additions & 6 deletions msp/mgmt/testtools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,3 @@ func LoadMSPSetupForTesting() error {

return nil
}

// Loads the development local MSP for use in testing. Not valid for production/runtime context
func LoadDevMsp() error {
mspDir := configtest.GetDevMspDir()
return mgmt.LoadLocalMsp(mspDir, nil, "SampleOrg")
}
7 changes: 6 additions & 1 deletion orderer/sample_clients/broadcast_config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
cb "github.com/hyperledger/fabric-protos-go/common"
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/msp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"google.golang.org/grpc"
Expand Down Expand Up @@ -63,7 +64,11 @@ func init() {
}

// Load local MSP
err = mspmgmt.LoadLocalMsp(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
mspConfig, err := msp.GetLocalMspConfig(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
if err != nil {
panic(fmt.Errorf("Failed to load MSP config: %s", err))
}
err = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(mspConfig)
if err != nil {
panic(fmt.Errorf("failed to initialize local MSP: %s", err))
}
Expand Down
8 changes: 7 additions & 1 deletion orderer/sample_clients/broadcast_msg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/hyperledger/fabric/msp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/hyperledger/fabric/protoutil"
Expand Down Expand Up @@ -59,7 +60,12 @@ func main() {
}

// Load local MSP
err = mspmgmt.LoadLocalMsp(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
mspConfig, err := msp.GetLocalMspConfig(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
if err != nil {
fmt.Println("Failed to load MSP config:", err)
os.Exit(0)
}
err = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(mspConfig)
if err != nil { // Handle errors reading the config file
fmt.Println("Failed to initialize local MSP:", err)
os.Exit(0)
Expand Down
8 changes: 7 additions & 1 deletion orderer/sample_clients/deliver_stdout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/hyperledger/fabric/msp"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/hyperledger/fabric/protoutil"
Expand Down Expand Up @@ -97,7 +98,12 @@ func main() {
}

// Load local MSP
err = mspmgmt.LoadLocalMsp(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
mspConfig, err := msp.GetLocalMspConfig(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID)
if err != nil {
fmt.Println("Failed to load MSP config:", err)
os.Exit(0)
}
err = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(mspConfig)
if err != nil { // Handle errors reading the config file
fmt.Println("Failed to initialize local MSP:", err)
os.Exit(0)
Expand Down

0 comments on commit c40cce0

Please sign in to comment.