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

Commit 7582442

Browse files
troyrondaAleksandar Likic
authored andcommitted
[FAB-8874] Refactor Identity interface
SDK now exposes only SigningIdentity interface, modelled after the MSP identity interfaces in Fabric. Change-Id: I01afb5109323e4d9d25fd8c8c6be5ac870c57714 Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent 6cd78cf commit 7582442

File tree

76 files changed

+669
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+669
-694
lines changed

pkg/client/channel/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1515
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
16+
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
1617
"github.com/stretchr/testify/assert"
1718
)
1819

@@ -72,7 +73,7 @@ func TestWithTargetURLsValid(t *testing.T) {
7273
}
7374

7475
func setupMockTestContext(username string, mspID string) *fcmocks.MockContext {
75-
user := fcmocks.NewMockUserWithMSPID(username, mspID)
76+
user := mspmocks.NewMockSigningIdentity(username, mspID)
7677
ctx := fcmocks.NewMockContext(user)
7778
return ctx
7879
}

pkg/client/channel/chclient_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
2626
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
2727
"github.com/hyperledger/fabric-sdk-go/pkg/fab/txn"
28+
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
2829
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
2930
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
3031
)
@@ -507,13 +508,13 @@ func setupTestChannelService(ctx context.Client, orderers []fab.Orderer) (fab.Ch
507508
}
508509

509510
func setupTestContext() context.Client {
510-
user := fcmocks.NewMockUser("test")
511+
user := mspmocks.NewMockSigningIdentity("test", "test")
511512
ctx := fcmocks.NewMockContext(user)
512513
return ctx
513514
}
514515

515516
func setupCustomTestContext(t *testing.T, selectionService fab.SelectionService, discoveryService fab.DiscoveryService, orderers []fab.Orderer) context.ClientProvider {
516-
user := fcmocks.NewMockUser("test")
517+
user := mspmocks.NewMockSigningIdentity("test", "test")
517518
ctx := fcmocks.NewMockContext(user)
518519

519520
if orderers == nil {

pkg/client/channel/invoke/txnhandler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
2020
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
2121
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
22+
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
2223
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
2324
)
2425

@@ -250,7 +251,7 @@ func setupChannelClientContext(discErr error, selectionErr error, peers []fab.Pe
250251
}
251252

252253
func setupTestContext() context.Client {
253-
user := fcmocks.NewMockUser("test")
254+
user := mspmocks.NewMockSigningIdentity("test", "test")
254255
ctx := fcmocks.NewMockContext(user)
255256
return ctx
256257
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newCCPolicyProvider(providers api.Providers, channelID string, username str
6161
return nil, errors.New("invalid options to create identity, invalid org name")
6262
}
6363

64-
identity, err := mgr.GetUser(username)
64+
identity, err := mgr.GetSigningIdentity(username)
6565
if err != nil {
6666
return nil, errors.WithMessage(err, "unable to create identity for ccl policy provider")
6767
}
@@ -83,7 +83,7 @@ type ccPolicyProvider struct {
8383
config core.Config
8484
providers context.Providers
8585
channelID string
86-
identity msp.Identity
86+
identity msp.SigningIdentity
8787
targetPeers []core.ChannelPeer
8888
ccDataMap map[string]*ccprovider.ChaincodeData // TODO: Add expiry and configurable timeout for map entries
8989
mutex sync.RWMutex
@@ -214,7 +214,7 @@ func (dp *ccPolicyProvider) getChannelContext() context.ChannelProvider {
214214
return func() (context.Channel, error) {
215215
//Get Client Context
216216
clientProvider := func() (context.Client, error) {
217-
return &contextImpl.Client{Providers: dp.providers, Identity: dp.identity}, nil
217+
return &contextImpl.Client{Providers: dp.providers, SigningIdentity: dp.identity}, nil
218218
}
219219

220220
return contextImpl.NewChannel(clientProvider, dp.channelID)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1717
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
1818
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
19-
mocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
19+
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
2020
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
2121
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc"
2222
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
23+
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
2324
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider"
2425
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
2526
)
@@ -473,7 +474,7 @@ func (lbp *customLBP) Choose(peerGroups []pgresolver.PeerGroup) pgresolver.PeerG
473474
}
474475

475476
func setupMockContext(username, orgName string) context.Providers {
476-
user := mocks.NewMockUserWithMSPID(username, orgName)
477+
user := mspmocks.NewMockSigningIdentity(username, orgName)
477478
ctx := mocks.NewMockContext(user)
478479
return ctx
479480
}

pkg/client/ledger/ledger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func New(channelProvider context.ChannelProvider, opts ...ClientOption) (*Client
8181
// check if target filter was set - if not set the default
8282
if ledgerClient.filter == nil {
8383
// Default target filter is based on user msp
84-
if channelContext.MSPID() == "" {
84+
if channelContext.Identifier().MSPID == "" {
8585
return nil, errors.New("mspID not available in user context")
8686
}
87-
filter := &mspFilter{mspID: channelContext.MSPID()}
87+
filter := &mspFilter{mspID: channelContext.Identifier().MSPID}
8888
ledgerClient.filter = filter
8989
}
9090

pkg/client/ledger/opts_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
1414
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
15+
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
1516
"github.com/stretchr/testify/assert"
1617
)
1718

@@ -71,7 +72,7 @@ func TestWithTargetURLsValid(t *testing.T) {
7172
}
7273

7374
func setupTestContext(username string, mspID string) *fcmocks.MockContext {
74-
user := fcmocks.NewMockUserWithMSPID(username, mspID)
75+
user := mspmocks.NewMockSigningIdentity(username, mspID)
7576
ctx := fcmocks.NewMockContext(user)
7677
return ctx
7778
}
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,15 @@ func (c *Client) Revoke(request *RevocationRequest) (*RevocationResponse, error)
180180
}, nil
181181
}
182182

183-
// GetSigningIdentity returns a signing identity for the given user name
184-
func (c *Client) GetSigningIdentity(username string) (*SigningIdentity, error) {
185-
user, err := c.GetUser(username)
186-
if err != nil {
187-
if err == mspctx.ErrUserNotFound {
188-
return nil, ErrUserNotFound
189-
}
190-
return nil, err
191-
}
192-
signingIdentity := &SigningIdentity{MSPID: user.MSPID(), PrivateKey: user.PrivateKey(), EnrollmentCert: user.EnrollmentCertificate()}
193-
return signingIdentity, nil
194-
}
195-
196-
// GetUser returns a user for the given user name
197-
func (c *Client) GetUser(username string) (User, error) {
183+
// GetSigningIdentity returns signing identity for id
184+
func (c *Client) GetSigningIdentity(id string) (mspctx.SigningIdentity, error) {
198185
im, _ := c.ctx.IdentityManager(c.orgName)
199-
user, err := im.GetUser(username)
186+
si, err := im.GetSigningIdentity(id)
200187
if err != nil {
201188
if err == mspctx.ErrUserNotFound {
202189
return nil, ErrUserNotFound
203190
}
204191
return nil, err
205192
}
206-
return user, nil
193+
return si, nil
207194
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ func TestMSP(t *testing.T) {
7373
t.Fatalf("Expected to find user")
7474
}
7575

76-
enrolledUser, err := msp.GetUser(enrollUsername)
76+
enrolledUser, err := msp.GetSigningIdentity(enrollUsername)
7777
if err != nil {
7878
t.Fatalf("Expected to find user")
7979
}
8080

81-
if enrolledUser.Name() != enrollUsername {
81+
if enrolledUser.Identifier().ID != enrollUsername {
8282
t.Fatalf("Enrolled user name doesn't match")
8383
}
8484

85-
if enrolledUser.MSPID() != "Org1MSP" {
85+
if enrolledUser.Identifier().MSPID != "Org1MSP" {
8686
t.Fatalf("Enrolled user mspID doesn't match")
8787
}
8888

@@ -96,7 +96,7 @@ func TestMSP(t *testing.T) {
9696
}
9797

9898
// Reenroll with appropriate user
99-
err = msp.Reenroll(enrolledUser.Name())
99+
err = msp.Reenroll(enrolledUser.Identifier().ID)
100100
if err != nil {
101101
t.Fatalf("Reenroll return error %v", err)
102102
}
@@ -114,16 +114,16 @@ func TestMSP(t *testing.T) {
114114
t.Fatalf("Enroll return error %v", err)
115115
}
116116

117-
org2EnrolledUser, err := msp.GetUser(org2lUsername)
117+
org2EnrolledUser, err := msp.GetSigningIdentity(org2lUsername)
118118
if err != nil {
119119
t.Fatalf("Expected to find user")
120120
}
121121

122-
if org2EnrolledUser.Name() != org2lUsername {
122+
if org2EnrolledUser.Identifier().ID != org2lUsername {
123123
t.Fatalf("Enrolled user name doesn't match")
124124
}
125125

126-
if org2EnrolledUser.MSPID() != "Org2MSP" {
126+
if org2EnrolledUser.Identifier().MSPID != "Org2MSP" {
127127
t.Fatalf("Enrolled user mspID doesn't match")
128128
}
129129

0 commit comments

Comments
 (0)