From 79f2f4ee02f1aa46890b4f64b993e771c6c8967f Mon Sep 17 00:00:00 2001 From: Aleksandar Likic Date: Fri, 16 Mar 2018 16:43:27 -0400 Subject: [PATCH] [FAB-8940] Refactor pkg.common.msp.Providers interface Now it follows the same pattern as other providers' interfaces. Change-Id: I75edec2abf407eaf65ddc9d8e7f49b57bca64e64 Signed-off-by: Aleksandar Likic --- pkg/common/providers/msp/provider.go | 12 +++++------- pkg/context/context.go | 12 ++++++------ pkg/fabsdk/api/factory.go | 2 +- pkg/fabsdk/fabsdk.go | 8 ++++---- pkg/fabsdk/fabsdk_test.go | 2 +- pkg/fabsdk/factory/defmsp/mspfactory.go | 4 ++-- pkg/fabsdk/factory/defmsp/mspfactory_test.go | 2 +- pkg/fabsdk/mocks/mockfabsdkapi.gen.go | 14 +++++++------- test/integration/msp/custom_core_factory.go | 2 +- test/integration/msp/custom_msp_factory.go | 6 +++--- 10 files changed, 31 insertions(+), 33 deletions(-) diff --git a/pkg/common/providers/msp/provider.go b/pkg/common/providers/msp/provider.go index da1d80cf67..a773c704dc 100644 --- a/pkg/common/providers/msp/provider.go +++ b/pkg/common/providers/msp/provider.go @@ -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 } diff --git a/pkg/context/context.go b/pkg/context/context.go index 893f30f892..046632fed4 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -59,7 +59,7 @@ 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 @@ -67,7 +67,7 @@ type Provider struct { discoveryProvider fab.DiscoveryProvider selectionProvider fab.SelectionProvider signingManager core.SigningManager - mspProvider msp.Provider + idMgmtProvider msp.IdentityManagerProvider infraProvider fab.InfraProvider channelProvider fab.ChannelProvider } @@ -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 @@ -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 } } diff --git a/pkg/fabsdk/api/factory.go b/pkg/fabsdk/api/factory.go index 14351adb31..c7328ad965 100644 --- a/pkg/fabsdk/api/factory.go +++ b/pkg/fabsdk/api/factory.go @@ -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) diff --git a/pkg/fabsdk/fabsdk.go b/pkg/fabsdk/fabsdk.go index f15dc0233c..86da08432f 100644 --- a/pkg/fabsdk/fabsdk.go +++ b/pkg/fabsdk/fabsdk.go @@ -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") @@ -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)) diff --git a/pkg/fabsdk/fabsdk_test.go b/pkg/fabsdk/fabsdk_test.go index 2b66571116..281a12c0a9 100644 --- a/pkg/fabsdk/fabsdk_test.go +++ b/pkg/fabsdk/fabsdk_test.go @@ -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 { diff --git a/pkg/fabsdk/factory/defmsp/mspfactory.go b/pkg/fabsdk/factory/defmsp/mspfactory.go index f2f952943b..1e15c7041c 100644 --- a/pkg/fabsdk/factory/defmsp/mspfactory.go +++ b/pkg/fabsdk/factory/defmsp/mspfactory.go @@ -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) } diff --git a/pkg/fabsdk/factory/defmsp/mspfactory_test.go b/pkg/fabsdk/factory/defmsp/mspfactory_test.go index 2e0d42432d..74881e1f0f 100644 --- a/pkg/fabsdk/factory/defmsp/mspfactory_test.go +++ b/pkg/fabsdk/factory/defmsp/mspfactory_test.go @@ -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) } diff --git a/pkg/fabsdk/mocks/mockfabsdkapi.gen.go b/pkg/fabsdk/mocks/mockfabsdkapi.gen.go index a2f4d27b6c..dbe9a5dff6 100644 --- a/pkg/fabsdk/mocks/mockfabsdkapi.gen.go +++ b/pkg/fabsdk/mocks/mockfabsdkapi.gen.go @@ -98,17 +98,17 @@ func (m *MockMSPProviderFactory) EXPECT() *MockMSPProviderFactoryMockRecorder { return m.recorder } -// CreateProvider mocks base method -func (m *MockMSPProviderFactory) CreateProvider(arg0 core.Config, arg1 core.CryptoSuite, arg2 msp.UserStore) (msp.Provider, error) { - ret := m.ctrl.Call(m, "CreateProvider", arg0, arg1, arg2) - ret0, _ := ret[0].(msp.Provider) +// CreateIdentityManagerProvider mocks base method +func (m *MockMSPProviderFactory) CreateIdentityManagerProvider(arg0 core.Config, arg1 core.CryptoSuite, arg2 msp.UserStore) (msp.IdentityManagerProvider, error) { + ret := m.ctrl.Call(m, "CreateIdentityManagerProvider", arg0, arg1, arg2) + ret0, _ := ret[0].(msp.IdentityManagerProvider) ret1, _ := ret[1].(error) return ret0, ret1 } -// CreateProvider indicates an expected call of CreateProvider -func (mr *MockMSPProviderFactoryMockRecorder) CreateProvider(arg0, arg1, arg2 interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateProvider", reflect.TypeOf((*MockMSPProviderFactory)(nil).CreateProvider), arg0, arg1, arg2) +// CreateIdentityManagerProvider indicates an expected call of CreateIdentityManagerProvider +func (mr *MockMSPProviderFactoryMockRecorder) CreateIdentityManagerProvider(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateIdentityManagerProvider", reflect.TypeOf((*MockMSPProviderFactory)(nil).CreateIdentityManagerProvider), arg0, arg1, arg2) } // CreateUserStore mocks base method diff --git a/test/integration/msp/custom_core_factory.go b/test/integration/msp/custom_core_factory.go index d12ce4e986..6cd70cb757 100644 --- a/test/integration/msp/custom_core_factory.go +++ b/test/integration/msp/custom_core_factory.go @@ -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 { diff --git a/test/integration/msp/custom_msp_factory.go b/test/integration/msp/custom_msp_factory.go index f4d832b8d6..546f87d313 100644 --- a/test/integration/msp/custom_msp_factory.go +++ b/test/integration/msp/custom_msp_factory.go @@ -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) }