Skip to content

Commit

Permalink
[FAB-7625] Make core fabric generic in fabapi
Browse files Browse the repository at this point in the history
This patch changes the core fabric methods to use a provider interface.
Additionally the provider factory is split into core
and services and moved out of fabapi. Missing unit tests of the
default factories are also added.

Change-Id: Ie5c04f14fbc03cfc8eefa93878a7f2f7582e160f
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Jan 10, 2018
1 parent 2c40482 commit f5d61a3
Show file tree
Hide file tree
Showing 29 changed files with 1,345 additions and 484 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ mock-gen:
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apitxn ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apitxn/mocks/mockapitxn.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apiconfig Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apiconfig/mocks/mockconfig.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apifabca FabricCAClient | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apifabca/mocks/mockfabriccaclient.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/def/fabapi/context SDK | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > def/fabapi/mocks/mocksdk.gen.go

# TODO - Add cryptogen
.PHONY: channel-config-gen
Expand Down
293 changes: 146 additions & 147 deletions api/apiconfig/mocks/mockconfig.gen.go

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions api/apicore/fabric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package apicore

import (
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
)

// FabricProvider allows overriding of fabric objects such as peer and user
type FabricProvider interface {
NewClient(user apifabclient.User) (apifabclient.FabricClient, error)
NewPeer(url string, certificate string, serverHostOverride string) (apifabclient.Peer, error)
NewPeerFromConfig(peerCfg *apiconfig.NetworkPeer) (apifabclient.Peer, error)
// EnrollUser(orgID, name, pwd string) (apifabca.User, error)
NewUser(name string, signingIdentity *apifabclient.SigningIdentity) (apifabclient.User, error)
}
45 changes: 22 additions & 23 deletions api/apifabca/mocks/mockfabriccaclient.gen.go

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

13 changes: 6 additions & 7 deletions api/apitxn/mocks/mockapitxn.gen.go

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

2 changes: 2 additions & 0 deletions def/fabapi/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package context

import (
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/api/apicore"
"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
)
Expand All @@ -20,6 +21,7 @@ type SDK interface {
DiscoveryProvider() fab.DiscoveryProvider
SelectionProvider() fab.SelectionProvider
SigningManager() fab.SigningManager
FabricProvider() apicore.FabricProvider
}

// Org represents the organization context
Expand Down
15 changes: 10 additions & 5 deletions def/fabapi/context/provider.go → def/fabapi/context/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,40 @@ package context

import (
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/api/apicore"
"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"
fabca "github.com/hyperledger/fabric-sdk-go/api/apifabca"
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
chmgmt "github.com/hyperledger/fabric-sdk-go/api/apitxn/chmgmtclient"
resmgmt "github.com/hyperledger/fabric-sdk-go/api/apitxn/resmgmtclient"
"github.com/hyperledger/fabric-sdk-go/def/fabapi/opt"
)

// SDKProviderFactory allows overriding default providers of an SDK
type SDKProviderFactory interface {
// CoreProviderFactory allows overriding of primitives and the fabric core object provider
type CoreProviderFactory interface {
NewConfigProvider(o opt.ConfigOpts, a opt.SDKOpts) (apiconfig.Config, error)
NewStateStoreProvider(o opt.StateStoreOpts, config apiconfig.Config) (fab.KeyValueStore, error)
NewCryptoSuiteProvider(config apiconfig.Config) (apicryptosuite.CryptoSuite, error)
NewSigningManager(cryptoProvider apicryptosuite.CryptoSuite, config apiconfig.Config) (fab.SigningManager, error)
NewFabricProvider(config apiconfig.Config, stateStore fab.KeyValueStore, cryptoSuite apicryptosuite.CryptoSuite, signer fab.SigningManager) (apicore.FabricProvider, error)
}

// ServiceProviderFactory allows overriding default service providers (such as peer discovery)
type ServiceProviderFactory interface {
NewDiscoveryProvider(config apiconfig.Config) (fab.DiscoveryProvider, error)
NewSelectionProvider(config apiconfig.Config) (fab.SelectionProvider, error)
}

// OrgClientFactory allows overriding default clients and providers of an organization
// Currently, a context is created for each organization that the client app needs.
type OrgClientFactory interface {
NewMSPClient(orgName string, config apiconfig.Config, cryptoProvider apicryptosuite.CryptoSuite) (fabca.FabricCAClient, error)
//NewMSPClient(orgName string, config apiconfig.Config, cryptoProvider apicryptosuite.CryptoSuite) (fabca.FabricCAClient, error)
NewCredentialManager(orgName string, config apiconfig.Config, cryptoProvider apicryptosuite.CryptoSuite) (fab.CredentialManager, error)
}

// SessionClientFactory allows overriding default clients and providers of a session
type SessionClientFactory interface {
NewSystemClient(context SDK, session Session, config apiconfig.Config) (fab.FabricClient, error)
//NewSystemClient(context SDK, session Session, config apiconfig.Config) (fab.FabricClient, error)
NewChannelMgmtClient(context SDK, session Session, config apiconfig.Config) (chmgmt.ChannelMgmtClient, error)
NewResourceMgmtClient(context SDK, session Session, config apiconfig.Config, filter resmgmt.TargetFilter) (resmgmt.ResourceMgmtClient, error)
NewChannelClient(context SDK, session Session, config apiconfig.Config, channelID string) (txn.ChannelClient, error)
Expand Down
Loading

0 comments on commit f5d61a3

Please sign in to comment.