Skip to content

Commit

Permalink
[FAB-9238] refactoring config implementations
Browse files Browse the repository at this point in the history
- Removed config.FromBackend() and replaced it
with ConfigFromBackend() in pkg/core/cryptosuite,
pkg/fab and pkg/msp
- Moved config implementations to respective packages
from pkg/core/config
- Removed CryptoSuiteConfig() from core providers
- Removed RandomOrdererConfig() from EndpointConfig
- sdk.Config() to return core.ConfigBackend

Change-Id: Iba4333a0676c642350e43c4cdb735ede388715b5
Signed-off-by: Sudesh Shetty <[email protected]>
  • Loading branch information
sudeshrshetty committed Apr 4, 2018
1 parent 3ddebb2 commit 449a24d
Show file tree
Hide file tree
Showing 44 changed files with 2,251 additions and 1,676 deletions.
3 changes: 2 additions & 1 deletion pkg/client/common/discovery/discoveryfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/staticdiscovery"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
)

Expand All @@ -32,7 +33,7 @@ func TestDiscoveryFilter(t *testing.T) {
t.Fatalf(err.Error())
}

_, config1, _, err := config.FromBackend(configBackend)()
config1, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
)

Expand All @@ -21,7 +22,7 @@ func TestStaticDiscovery(t *testing.T) {
t.Fatalf(err.Error())
}

_, config1, _, err := config.FromBackend(configBackend)()
config1, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestStaticDiscoveryWhenChannelIsEmpty(t *testing.T) {
t.Fatalf(err.Error())
}

_, config1, _, err := config.FromBackend(configBackend)()
config1, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
fabmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
)
Expand All @@ -29,9 +30,7 @@ func TestStaticSelection(t *testing.T) {
t.Fatalf(err.Error())
}

configProv := config.FromBackend(configBackend)

_, config, _, err := configProv()
config, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/client/msp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
mspctx "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
mspImpl "github.com/hyperledger/fabric-sdk-go/pkg/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
)

Expand Down Expand Up @@ -177,11 +179,17 @@ func (f *textFixture) setup() *fabsdk.FabricSDK {
panic(fmt.Sprintf("SDK init failed: %v", err))
}

f.cryptoSuiteConfig, _, f.identityConfig, err = sdk.Config()()
configBackend, err := sdk.Config()
if err != nil {
panic(fmt.Sprintf("Failed to get config: %v", err))
}

f.cryptoSuiteConfig = cryptosuite.ConfigFromBackend(configBackend)
f.identityConfig, err = mspImpl.ConfigFromBackend(configBackend)
if err != nil {
panic(fmt.Sprintf("Failed to get identity config: %v", err))
}

// Delete all private keys from the crypto suite store
// and users from the user store
cleanup(f.cryptoSuiteConfig.KeyStorePath())
Expand Down
18 changes: 10 additions & 8 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
configImpl "github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api"
Expand Down Expand Up @@ -282,7 +283,7 @@ func TestOrdererConfigFail(t *testing.T) {
configBackend, err := configImpl.FromFile("./testdata/noorderer_test.yaml")()
assert.Nil(t, err)

_, noOrdererConfig, _, err := configImpl.FromBackend(configBackend)()
noOrdererConfig, err := fabImpl.ConfigFromBackend(configBackend)
assert.Nil(t, err)

ctx.SetEndpointConfig(noOrdererConfig)
Expand Down Expand Up @@ -319,7 +320,7 @@ func TestJoinChannelNoOrdererConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, noOrdererConfig, _, err := configImpl.FromBackend(configBackend)()
noOrdererConfig, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand All @@ -334,7 +335,7 @@ func TestJoinChannelNoOrdererConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, invalidChOrdererConfig, _, err := configImpl.FromBackend(configBackend)()
invalidChOrdererConfig, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand All @@ -352,7 +353,7 @@ func TestJoinChannelNoOrdererConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, invalidOrdererConfig, _, err := configImpl.FromBackend(configBackend)()
invalidOrdererConfig, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1177,7 +1178,7 @@ func TestCCProposal(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, cfg, _, err := configImpl.FromBackend(configBackend)()
cfg, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1235,7 +1236,7 @@ func TestCCProposal(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, cfg, _, err = configImpl.FromBackend(configBackend)()
cfg, err = fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1262,7 +1263,8 @@ func TestCCProposalFailed(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, cfg, _, err := configImpl.FromBackend(configBackend)()

cfg, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1373,7 +1375,7 @@ func getNetworkConfig(t *testing.T) fab.EndpointConfig {
t.Fatal(err)
}

_, config, _, err := configImpl.FromBackend(configBackend)()
config, err := fabImpl.ConfigFromBackend(configBackend)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/common/providers/core/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ type CryptoSuiteConfig interface {
type Providers interface {
CryptoSuite() CryptoSuite
SigningManager() SigningManager
//TODO to be removed
CryptoSuiteConfig() CryptoSuiteConfig
}

//ConfigProvider provides config backend for SDK
Expand Down
2 changes: 0 additions & 2 deletions pkg/common/providers/fab/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ type EndpointConfig interface {
MSPID(org string) (string, error)
PeerMSPID(name string) (string, error)
OrderersConfig() ([]OrdererConfig, error)
//TODO to be removed, not a config item
RandomOrdererConfig() (*OrdererConfig, error)
OrdererConfig(name string) (*OrdererConfig, error)
PeersConfig(org string) ([]PeerConfig, error)
PeerConfig(org string, name string) (*PeerConfig, error)
Expand Down
24 changes: 0 additions & 24 deletions pkg/common/providers/test/mockcontext/mockcontext.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions pkg/common/providers/test/mockcore/mockcore.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions pkg/common/providers/test/mockfab/mockfab.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ func (c *Provider) CryptoSuite() core.CryptoSuite {
return c.cryptoSuite
}

// CryptoSuiteConfig returns cryptosuite config.
func (c *Provider) CryptoSuiteConfig() core.CryptoSuiteConfig {
return c.cryptoSuiteConfig
}

// IdentityManager returns identity manager for organization
func (c *Provider) IdentityManager(orgName string) (msp.IdentityManager, bool) {
return c.idMgmtProvider.IdentityManager(orgName)
Expand Down
Loading

0 comments on commit 449a24d

Please sign in to comment.