Skip to content

Commit

Permalink
[FAB-8778] Move Identity interface to msp
Browse files Browse the repository at this point in the history
Change-Id: I3ff3468f6df5b15612f1d283406cc65efb2d404b
Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
  • Loading branch information
Aleksandar Likic committed Mar 11, 2018
1 parent 06ee6d7 commit e73e227
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider"
Expand Down Expand Up @@ -82,7 +83,7 @@ type ccPolicyProvider struct {
config core.Config
providers context.Providers
channelID string
identity context.Identity
identity msp.Identity
targetPeers []core.ChannelPeer
ccDataMap map[string]*ccprovider.ChaincodeData // TODO: Add expiry and configurable timeout for map entries
mutex sync.RWMutex
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/chconfig"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -88,7 +89,7 @@ type SaveChannelRequest struct {
// Path to channel configuration file
ChannelConfig string
// Users that sign channel configuration
SigningIdentities []fab.IdentityContext
SigningIdentities []msp.Identity
}

//RequestOption func for each Opts argument
Expand Down Expand Up @@ -592,7 +593,7 @@ func (rc *Client) SaveChannel(req SaveChannelRequest, options ...RequestOption)

// Signing user has to belong to one of configured channel organisations
// In case that order org is one of channel orgs we can use context user
var signers []context.Identity
var signers []msp.Identity

if len(req.SigningIdentities) > 0 {
for _, id := range req.SigningIdentities {
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
Expand Down Expand Up @@ -1489,15 +1490,15 @@ func TestSaveChannelWithMultipleSigningIdenities(t *testing.T) {
cc := setupResMgmtClient(ctx, nil, t)

// empty list of signing identities (defaults to context user)
req := SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []fab.IdentityContext{}}
req := SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []msp.Identity{}}
err := cc.SaveChannel(req, WithOrdererID(""))
if err != nil {
t.Fatalf("Failed to save channel with default signing identity: %s", err)
}

// multiple signing identities
secondCtx := fcmocks.NewMockContext(fcmocks.NewMockUser("second"))
req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []fab.IdentityContext{cc.ctx, secondCtx}}
req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []msp.Identity{cc.ctx, secondCtx}}
err = cc.SaveChannel(req, WithOrdererID(""))
if err != nil {
t.Fatalf("Failed to save channel with multiple signing identities: %s", err)
Expand Down
9 changes: 1 addition & 8 deletions pkg/common/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
)

// Identity supplies the serialized identity and key reference.
type Identity interface {
MspID() string
SerializedIdentity() ([]byte, error)
PrivateKey() core.Key
}

// Client supplies the configuration and signing identity to client objects.
type Client interface {
Providers
Identity
msp.Identity
}

// Providers represents the SDK configured providers context.
Expand Down
13 changes: 0 additions & 13 deletions pkg/context/api/fab/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ SPDX-License-Identifier: Apache-2.0

package fab

import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
)

// IdentityContext supplies the serialized identity and key reference.
//
// TODO - refactor SigningIdentity and this interface.
type IdentityContext interface {
MspID() string
SerializedIdentity() ([]byte, error)
PrivateKey() core.Key
}

// ChannelService supplies services related to a channel.
type ChannelService interface {
Config() (ChannelConfig, error)
Expand Down
6 changes: 3 additions & 3 deletions pkg/context/api/fab/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type ClientContext interface {

// InfraProvider enables access to fabric objects such as peer and user based on config or
type InfraProvider interface {
CreateChannelLedger(ic IdentityContext, name string) (ChannelLedger, error)
CreateChannelConfig(user IdentityContext, name string) (ChannelConfig, error)
CreateChannelTransactor(ic IdentityContext, cfg ChannelCfg) (Transactor, error)
CreateChannelLedger(ic msp.Identity, name string) (ChannelLedger, error)
CreateChannelConfig(user msp.Identity, name string) (ChannelConfig, error)
CreateChannelTransactor(ic msp.Identity, cfg ChannelCfg) (Transactor, error)
CreateChannelMembership(cfg ChannelCfg) (ChannelMembership, error)
CreateEventService(ctx ClientContext, chConfig ChannelCfg) (EventService, error)
CreatePeerFromConfig(peerCfg *core.NetworkPeer) (Peer, error)
Expand Down
7 changes: 7 additions & 0 deletions pkg/context/api/msp/identitymgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
)

// Identity supplies the serialized identity and key reference.
type Identity interface {
MspID() string
SerializedIdentity() ([]byte, error)
PrivateKey() core.Key
}

// SigningIdentity is the identity object that encapsulates the user's private key for signing
// and the user's enrollment certificate (identity)
type SigningIdentity struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// Client supplies the configuration and signing identity to client objects.
type Client struct {
context.Providers
context.Identity
msp.Identity
}

//Channel supplies the configuration for channel context client
Expand Down
13 changes: 7 additions & 6 deletions pkg/fab/chconfig/chconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"github.com/golang/protobuf/proto"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
msp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
mb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
ab "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/orderer"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
Expand Down Expand Up @@ -45,7 +46,7 @@ type Option func(opts *Opts) error
// Context holds the providers and identity
type Context struct {
context.Providers
context.Identity
msp.Identity
}

// ChannelConfig implements query channel configuration
Expand All @@ -58,7 +59,7 @@ type ChannelConfig struct {
// ChannelCfg contains channel configuration
type ChannelCfg struct {
id string
msps []*msp.MSPConfig
msps []*mb.MSPConfig
anchorPeers []*fab.OrgAnchorPeer
orderers []string
versions *fab.Versions
Expand All @@ -76,7 +77,7 @@ func (cfg *ChannelCfg) ID() string {
}

// MSPs returns msps
func (cfg *ChannelCfg) MSPs() []*msp.MSPConfig {
func (cfg *ChannelCfg) MSPs() []*mb.MSPConfig {
return cfg.msps
}

Expand Down Expand Up @@ -213,7 +214,7 @@ func extractConfig(channelID string, configEnvelope *common.ConfigEnvelope) (*Ch

config := &ChannelCfg{
id: channelID,
msps: []*msp.MSPConfig{},
msps: []*mb.MSPConfig{},
anchorPeers: []*fab.OrgAnchorPeer{},
orderers: []string{},
versions: versions,
Expand Down Expand Up @@ -355,7 +356,7 @@ func loadConfigValue(configItems *ChannelCfg, key string, versionsValue *common.
break

case channelConfig.MSPKey:
mspConfig := &msp.MSPConfig{}
mspConfig := &mb.MSPConfig{}
err := proto.Unmarshal(configValue.Value, mspConfig)
if err != nil {
return errors.Wrap(err, "unmarshal MSPConfig from config failed")
Expand Down
8 changes: 3 additions & 5 deletions pkg/fab/mocks/mockcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"

"strings"

"github.com/hyperledger/fabric-sdk-go/pkg/common/context"
)

// MockProviderContext holds core providers to enable mocking.
Expand Down Expand Up @@ -129,11 +127,11 @@ func (pc *MockProviderContext) SetCustomInfraProvider(customInfraProvider fab.In
// MockContext holds core providers and identity to enable mocking.
type MockContext struct {
*MockProviderContext
context.Identity
msp.Identity
}

// NewMockContext creates a MockContext consisting of defaults and an identity
func NewMockContext(ic context.Identity) *MockContext {
func NewMockContext(ic msp.Identity) *MockContext {
ctx := MockContext{
MockProviderContext: NewMockProviderContext(),
Identity: ic,
Expand All @@ -142,7 +140,7 @@ func NewMockContext(ic context.Identity) *MockContext {
}

// NewMockContextWithCustomDiscovery creates a MockContext consisting of defaults and an identity
func NewMockContextWithCustomDiscovery(ic context.Identity, discPvdr fab.DiscoveryProvider) *MockContext {
func NewMockContextWithCustomDiscovery(ic msp.Identity, discPvdr fab.DiscoveryProvider) *MockContext {
mockCtx := NewMockProviderContext()
mockCtx.discoveryProvider = discPvdr
ctx := MockContext{
Expand Down
7 changes: 4 additions & 3 deletions pkg/fab/mocks/mockfabricprovider.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/common/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
)

// MockInfraProvider represents the default implementation of Fabric objects.
Expand All @@ -21,7 +22,7 @@ type MockInfraProvider struct {
}

// CreateChannelLedger returns a new client initialized for the current instance of the SDK.
func (f *MockInfraProvider) CreateChannelLedger(ic fab.IdentityContext, channelName string) (fab.ChannelLedger, error) {
func (f *MockInfraProvider) CreateChannelLedger(ic msp.Identity, channelName string) (fab.ChannelLedger, error) {
return nil, nil
}

Expand All @@ -31,7 +32,7 @@ func (f *MockInfraProvider) CreateEventService(ic fab.ClientContext, chConfig fa
}

// CreateChannelConfig initializes the channel config
func (f *MockInfraProvider) CreateChannelConfig(ic fab.IdentityContext, channelID string) (fab.ChannelConfig, error) {
func (f *MockInfraProvider) CreateChannelConfig(ic msp.Identity, channelID string) (fab.ChannelConfig, error) {
if ic == nil {
return &MockChannelConfig{channelID: channelID}, nil
}
Expand All @@ -44,7 +45,7 @@ func (f *MockInfraProvider) CreateChannelMembership(cfg fab.ChannelCfg) (fab.Cha
}

// CreateChannelTransactor initializes the transactor
func (f *MockInfraProvider) CreateChannelTransactor(ic fab.IdentityContext, cfg fab.ChannelCfg) (fab.Transactor, error) {
func (f *MockInfraProvider) CreateChannelTransactor(ic msp.Identity, cfg fab.ChannelCfg) (fab.Transactor, error) {
if cfg == nil {
return &MockTransactor{}, nil
} else if ic == nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/fab/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
ccomm "github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api"
Expand All @@ -31,11 +32,11 @@ var logger = logging.NewLogger("fabsdk/fab")

type fabCtx struct {
context.Providers
context.Identity
msp.Identity
}

// SignChannelConfig signs a configuration.
func SignChannelConfig(ctx context.Client, config []byte, signer context.Identity) (*common.ConfigSignature, error) {
func SignChannelConfig(ctx context.Client, config []byte, signer msp.Identity) (*common.ConfigSignature, error) {
logger.Debug("SignChannelConfig - start")

if config == nil {
Expand Down
13 changes: 6 additions & 7 deletions pkg/fabsdk/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ SPDX-License-Identifier: Apache-2.0
package fabsdk

import (
contextApi "github.com/hyperledger/fabric-sdk-go/pkg/common/context"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/pkg/errors"
)

type identityOptions struct {
identity contextApi.Identity
identity msp.Identity
orgName string
userName string
}
Expand All @@ -31,7 +30,7 @@ func WithUser(userName string) ContextOption {
}

// WithIdentity uses a pre-constructed identity object as the credential for the session
func WithIdentity(identity contextApi.Identity) ContextOption {
func WithIdentity(identity msp.Identity) ContextOption {
return func(o *identityOptions) error {
o.identity = identity
return nil
Expand All @@ -46,7 +45,7 @@ func WithOrg(org string) ContextOption {
}
}

func (sdk *FabricSDK) newIdentity(options ...ContextOption) (contextApi.Identity, error) {
func (sdk *FabricSDK) newIdentity(options ...ContextOption) (msp.Identity, error) {
clientConfig, err := sdk.Config().Client()
if err != nil {
return nil, errors.WithMessage(err, "retrieving client configuration failed")
Expand Down Expand Up @@ -87,11 +86,11 @@ func (sdk *FabricSDK) newIdentity(options ...ContextOption) (contextApi.Identity
// session represents an identity being used with clients along with services
// that associate with that identity (particularly the channel service).
type session struct {
contextApi.Identity
msp.Identity
}

// newSession creates a session from a context and a user (TODO)
func newSession(ic contextApi.Identity, cp fab.ChannelProvider) *session {
func newSession(ic msp.Identity, cp fab.ChannelProvider) *session {
s := session{
Identity: ic,
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/fabsdk/provider/chpvdr/chprovider_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/common/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/chconfig"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
Expand All @@ -21,7 +22,7 @@ import (

type mockClientContext struct {
context.Providers
context.Identity
msp.Identity
}

func TestBasicValidChannel(t *testing.T) {
Expand Down Expand Up @@ -74,7 +75,7 @@ type MockInfraProvider struct {
}

// CreateChannelConfig initializes the channel config
func (f *MockInfraProvider) CreateChannelConfig(ic fab.IdentityContext, channelID string) (fab.ChannelConfig, error) {
func (f *MockInfraProvider) CreateChannelConfig(ic msp.Identity, channelID string) (fab.ChannelConfig, error) {

ctx := chconfig.Context{
Providers: f.providerContext,
Expand Down
Loading

0 comments on commit e73e227

Please sign in to comment.