Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit e73e227

Browse files
author
Aleksandar Likic
committed
[FAB-8778] Move Identity interface to msp
Change-Id: I3ff3468f6df5b15612f1d283406cc65efb2d404b Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent 06ee6d7 commit e73e227

File tree

20 files changed

+63
-67
lines changed

20 files changed

+63
-67
lines changed

pkg/client/common/selection/dynamicselection/ccpolicyprovider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
2121
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
2222
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
23+
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
2324
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
2425
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
2526
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider"
@@ -82,7 +83,7 @@ type ccPolicyProvider struct {
8283
config core.Config
8384
providers context.Providers
8485
channelID string
85-
identity context.Identity
86+
identity msp.Identity
8687
targetPeers []core.ChannelPeer
8788
ccDataMap map[string]*ccprovider.ChaincodeData // TODO: Add expiry and configurable timeout for map entries
8889
mutex sync.RWMutex

pkg/client/resmgmt/resmgmt.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1616
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
17+
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
1718
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
1819
"github.com/hyperledger/fabric-sdk-go/pkg/fab/chconfig"
1920
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
@@ -88,7 +89,7 @@ type SaveChannelRequest struct {
8889
// Path to channel configuration file
8990
ChannelConfig string
9091
// Users that sign channel configuration
91-
SigningIdentities []fab.IdentityContext
92+
SigningIdentities []msp.Identity
9293
}
9394

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

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

597598
if len(req.SigningIdentities) > 0 {
598599
for _, id := range req.SigningIdentities {

pkg/client/resmgmt/resmgmt_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context"
2525
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
2626
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
27+
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
2728
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
2829
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
2930
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
@@ -1489,15 +1490,15 @@ func TestSaveChannelWithMultipleSigningIdenities(t *testing.T) {
14891490
cc := setupResMgmtClient(ctx, nil, t)
14901491

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

14981499
// multiple signing identities
14991500
secondCtx := fcmocks.NewMockContext(fcmocks.NewMockUser("second"))
1500-
req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []fab.IdentityContext{cc.ctx, secondCtx}}
1501+
req = SaveChannelRequest{ChannelID: "mychannel", ChannelConfig: channelConfig, SigningIdentities: []msp.Identity{cc.ctx, secondCtx}}
15011502
err = cc.SaveChannel(req, WithOrdererID(""))
15021503
if err != nil {
15031504
t.Fatalf("Failed to save channel with multiple signing identities: %s", err)

pkg/common/context/context.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ import (
1212
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
1313
)
1414

15-
// Identity supplies the serialized identity and key reference.
16-
type Identity interface {
17-
MspID() string
18-
SerializedIdentity() ([]byte, error)
19-
PrivateKey() core.Key
20-
}
21-
2215
// Client supplies the configuration and signing identity to client objects.
2316
type Client interface {
2417
Providers
25-
Identity
18+
msp.Identity
2619
}
2720

2821
// Providers represents the SDK configured providers context.

pkg/context/api/fab/context.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ SPDX-License-Identifier: Apache-2.0
66

77
package fab
88

9-
import (
10-
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
11-
)
12-
13-
// IdentityContext supplies the serialized identity and key reference.
14-
//
15-
// TODO - refactor SigningIdentity and this interface.
16-
type IdentityContext interface {
17-
MspID() string
18-
SerializedIdentity() ([]byte, error)
19-
PrivateKey() core.Key
20-
}
21-
229
// ChannelService supplies services related to a channel.
2310
type ChannelService interface {
2411
Config() (ChannelConfig, error)

pkg/context/api/fab/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ type ClientContext interface {
2828

2929
// InfraProvider enables access to fabric objects such as peer and user based on config or
3030
type InfraProvider interface {
31-
CreateChannelLedger(ic IdentityContext, name string) (ChannelLedger, error)
32-
CreateChannelConfig(user IdentityContext, name string) (ChannelConfig, error)
33-
CreateChannelTransactor(ic IdentityContext, cfg ChannelCfg) (Transactor, error)
31+
CreateChannelLedger(ic msp.Identity, name string) (ChannelLedger, error)
32+
CreateChannelConfig(user msp.Identity, name string) (ChannelConfig, error)
33+
CreateChannelTransactor(ic msp.Identity, cfg ChannelCfg) (Transactor, error)
3434
CreateChannelMembership(cfg ChannelCfg) (ChannelMembership, error)
3535
CreateEventService(ctx ClientContext, chConfig ChannelCfg) (EventService, error)
3636
CreatePeerFromConfig(peerCfg *core.NetworkPeer) (Peer, error)

pkg/context/api/msp/identitymgr.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import (
1010
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1111
)
1212

13+
// Identity supplies the serialized identity and key reference.
14+
type Identity interface {
15+
MspID() string
16+
SerializedIdentity() ([]byte, error)
17+
PrivateKey() core.Key
18+
}
19+
1320
// SigningIdentity is the identity object that encapsulates the user's private key for signing
1421
// and the user's enrollment certificate (identity)
1522
type SigningIdentity struct {

pkg/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// Client supplies the configuration and signing identity to client objects.
2222
type Client struct {
2323
context.Providers
24-
context.Identity
24+
msp.Identity
2525
}
2626

2727
//Channel supplies the configuration for channel context client

pkg/fab/chconfig/chconfig.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
"github.com/golang/protobuf/proto"
1111

1212
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
13+
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
1314
"github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
1415
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
1516
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
1617
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
1718
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
18-
msp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
19+
mb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
1920
ab "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/orderer"
2021
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
2122
"github.com/pkg/errors"
@@ -45,7 +46,7 @@ type Option func(opts *Opts) error
4546
// Context holds the providers and identity
4647
type Context struct {
4748
context.Providers
48-
context.Identity
49+
msp.Identity
4950
}
5051

5152
// ChannelConfig implements query channel configuration
@@ -58,7 +59,7 @@ type ChannelConfig struct {
5859
// ChannelCfg contains channel configuration
5960
type ChannelCfg struct {
6061
id string
61-
msps []*msp.MSPConfig
62+
msps []*mb.MSPConfig
6263
anchorPeers []*fab.OrgAnchorPeer
6364
orderers []string
6465
versions *fab.Versions
@@ -76,7 +77,7 @@ func (cfg *ChannelCfg) ID() string {
7677
}
7778

7879
// MSPs returns msps
79-
func (cfg *ChannelCfg) MSPs() []*msp.MSPConfig {
80+
func (cfg *ChannelCfg) MSPs() []*mb.MSPConfig {
8081
return cfg.msps
8182
}
8283

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

214215
config := &ChannelCfg{
215216
id: channelID,
216-
msps: []*msp.MSPConfig{},
217+
msps: []*mb.MSPConfig{},
217218
anchorPeers: []*fab.OrgAnchorPeer{},
218219
orderers: []string{},
219220
versions: versions,
@@ -355,7 +356,7 @@ func loadConfigValue(configItems *ChannelCfg, key string, versionsValue *common.
355356
break
356357

357358
case channelConfig.MSPKey:
358-
mspConfig := &msp.MSPConfig{}
359+
mspConfig := &mb.MSPConfig{}
359360
err := proto.Unmarshal(configValue.Value, mspConfig)
360361
if err != nil {
361362
return errors.Wrap(err, "unmarshal MSPConfig from config failed")

pkg/fab/mocks/mockcontext.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import (
1818
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp"
1919

2020
"strings"
21-
22-
"github.com/hyperledger/fabric-sdk-go/pkg/common/context"
2321
)
2422

2523
// MockProviderContext holds core providers to enable mocking.
@@ -129,11 +127,11 @@ func (pc *MockProviderContext) SetCustomInfraProvider(customInfraProvider fab.In
129127
// MockContext holds core providers and identity to enable mocking.
130128
type MockContext struct {
131129
*MockProviderContext
132-
context.Identity
130+
msp.Identity
133131
}
134132

135133
// NewMockContext creates a MockContext consisting of defaults and an identity
136-
func NewMockContext(ic context.Identity) *MockContext {
134+
func NewMockContext(ic msp.Identity) *MockContext {
137135
ctx := MockContext{
138136
MockProviderContext: NewMockProviderContext(),
139137
Identity: ic,
@@ -142,7 +140,7 @@ func NewMockContext(ic context.Identity) *MockContext {
142140
}
143141

144142
// NewMockContextWithCustomDiscovery creates a MockContext consisting of defaults and an identity
145-
func NewMockContextWithCustomDiscovery(ic context.Identity, discPvdr fab.DiscoveryProvider) *MockContext {
143+
func NewMockContextWithCustomDiscovery(ic msp.Identity, discPvdr fab.DiscoveryProvider) *MockContext {
146144
mockCtx := NewMockProviderContext()
147145
mockCtx.discoveryProvider = discPvdr
148146
ctx := MockContext{

0 commit comments

Comments
 (0)