Skip to content

Commit

Permalink
[FAB-8940] Refactor pkg.common.msp.Providers interface
Browse files Browse the repository at this point in the history
Now it follows the same pattern as other providers' interfaces.

Change-Id: I75edec2abf407eaf65ddc9d8e7f49b57bca64e64
Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
  • Loading branch information
Aleksandar Likic committed Mar 16, 2018
1 parent cc16a4a commit 79f2f4e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 33 deletions.
12 changes: 5 additions & 7 deletions pkg/common/providers/msp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ type Context interface {
Providers
}

// TODO - the Providers/Provider interfaces need to be refactored to be similar to other Providers

// Provider provides MSP services
type Provider interface {
UserStore() UserStore
// IdentityManagerProvider provides identity management services
type IdentityManagerProvider interface {
IdentityManager(orgName string) (IdentityManager, bool)
}

// Providers represents the MSP service providers context.
// Providers represents a provider of MSP service.
type Providers interface {
Provider
UserStore() UserStore
IdentityManagerProvider
}
12 changes: 6 additions & 6 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func (c *Channel) ChannelID() string {
return c.channelID
}

//Provider implementation for Providers interface
//Provider implementation of Providers interface
type Provider struct {
config core.Config
userStore msp.UserStore
cryptoSuite core.CryptoSuite
discoveryProvider fab.DiscoveryProvider
selectionProvider fab.SelectionProvider
signingManager core.SigningManager
mspProvider msp.Provider
idMgmtProvider msp.IdentityManagerProvider
infraProvider fab.InfraProvider
channelProvider fab.ChannelProvider
}
Expand All @@ -84,7 +84,7 @@ func (c *Provider) CryptoSuite() core.CryptoSuite {

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

// SigningManager returns signing manager
Expand Down Expand Up @@ -162,10 +162,10 @@ func WithSigningManager(signingManager core.SigningManager) SDKContextParams {
}
}

//WithMSPProvider sets MSPProvider maps to context
func WithMSPProvider(provider msp.Provider) SDKContextParams {
//WithIdentityManagerProvider sets IdentityManagerProvider maps to context
func WithIdentityManagerProvider(provider msp.IdentityManagerProvider) SDKContextParams {
return func(ctx *Provider) {
ctx.mspProvider = provider
ctx.idMgmtProvider = provider
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/fabsdk/api/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type CoreProviderFactory interface {
// MSPProviderFactory allows overriding providers of MSP services
type MSPProviderFactory interface {
CreateUserStore(config core.Config) (msp.UserStore, error)
CreateProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.Provider, error)
CreateIdentityManagerProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.IdentityManagerProvider, error)
}

// ServiceProviderFactory allows overriding default service providers (such as peer discovery)
Expand Down
8 changes: 4 additions & 4 deletions pkg/fabsdk/fabsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ func initSDK(sdk *FabricSDK, config core.Config, opts []Option) error {
return errors.WithMessage(err, "failed to initialize signing manager")
}

// Initialize MSP Provider
mspProvider, err := sdk.opts.MSP.CreateProvider(config, cryptoSuite, userStore)
// Initialize IdentityManagerProvider
identityManagerProvider, err := sdk.opts.MSP.CreateIdentityManagerProvider(config, cryptoSuite, userStore)
if err != nil {
return errors.WithMessage(err, "failed to initialize identity manager provider")
}

// Initialize Fabric Provider
// Initialize Fabric provider
infraProvider, err := sdk.opts.Core.CreateInfraProvider(config)
if err != nil {
return errors.WithMessage(err, "failed to initialize infra provider")
Expand Down Expand Up @@ -211,7 +211,7 @@ func initSDK(sdk *FabricSDK, config core.Config, opts []Option) error {
context.WithUserStore(userStore),
context.WithDiscoveryProvider(discoveryProvider),
context.WithSelectionProvider(selectionProvider),
context.WithMSPProvider(mspProvider),
context.WithIdentityManagerProvider(identityManagerProvider),
context.WithInfraProvider(infraProvider),
context.WithChannelProvider(channelProvider))

Expand Down
2 changes: 1 addition & 1 deletion pkg/fabsdk/fabsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestWithMSPPkg(t *testing.T) {
factory := mockapisdk.NewMockMSPProviderFactory(mockCtrl)

factory.EXPECT().CreateUserStore(c).Return(nil, nil)
factory.EXPECT().CreateProvider(c, gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()
factory.EXPECT().CreateIdentityManagerProvider(c, gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()

_, err = New(WithConfig(c), WithMSPPkg(factory))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/fabsdk/factory/defmsp/mspfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (f *ProviderFactory) CreateUserStore(config core.Config) (msp.UserStore, er
return userStore, nil
}

// CreateProvider returns a new default implementation of MSP provider
func (f *ProviderFactory) CreateProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.Provider, error) {
// CreateIdentityManagerProvider returns a new default implementation of MSP provider
func (f *ProviderFactory) CreateIdentityManagerProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.IdentityManagerProvider, error) {
return msppvdr.New(config, cryptoProvider, userStore)
}
2 changes: 1 addition & 1 deletion pkg/fabsdk/factory/defmsp/mspfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestCreateIdentityManager(t *testing.T) {
t.Fatalf("Unexpected error creating user store %v", err)
}

provider, err := factory.CreateProvider(config, cryptosuite, userStore)
provider, err := factory.CreateIdentityManagerProvider(config, cryptosuite, userStore)
if err != nil {
t.Fatalf("Unexpected error creating provider %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/fabsdk/mocks/mockfabsdkapi.gen.go

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

2 changes: 1 addition & 1 deletion test/integration/msp/custom_core_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
)

// ========== MSP Provider Factory with custom crypto provider ============= //
// ========== Core Provider Factory with custom crypto provider ============= //

// CustomCoreFactory is a custom factory for tests.
type CustomCoreFactory struct {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/msp/custom_msp_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *CustomMSPFactory) CreateUserStore(config core.Config) (msp.UserStore, e
return f.customUserStore, nil
}

// CreateProvider creates an MSP provider
func (f *CustomMSPFactory) CreateProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.Provider, error) {
return f.defaultFactory.CreateProvider(config, cryptoProvider, f.customUserStore)
// CreateIdentityManagerProvider creates an IdentityManager provider
func (f *CustomMSPFactory) CreateIdentityManagerProvider(config core.Config, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.IdentityManagerProvider, error) {
return f.defaultFactory.CreateIdentityManagerProvider(config, cryptoProvider, f.customUserStore)
}

0 comments on commit 79f2f4e

Please sign in to comment.