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

Commit 0c30596

Browse files
author
Aleksandar Likic
committed
[FAB-8684] Split IdentityManager and CA Client impl
Interfaces have been split in a separate push, to reduce the size of the change. Now the implementations are split. Change-Id: I2c13946d59938e4c4bc6169105d4da3940b896a8 Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent c9bd65a commit 0c30596

23 files changed

+1061
-755
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ dockerenv-latest-up: clean
327327
.PHONY: mock-gen
328328
mock-gen:
329329
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/core Config,Providers,IdentityManager | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/core/mocks/mockcoreapi.gen.go
330-
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp Client | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/msp/mocks/mockmspapi.gen.go
330+
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/msp CAClient | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/msp/mocks/mockmspapi.gen.go
331331
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab ProposalProcessor,Providers | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/fab/mocks/mockfabapi.gen.go
332332
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/common/context Providers,Client | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/common/context/mocks/mockcontext.gen.go
333333
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api CoreProviderFactory,ServiceProviderFactory | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/fabsdk/mocks/mockfabsdkapi.gen.go

pkg/context/api/core/identitymgr.go

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

77
package core
88

9-
import (
10-
"errors"
11-
)
12-
13-
var (
14-
// ErrCARegistrarNotFound indicates the CA registrar was not found
15-
ErrCARegistrarNotFound = errors.New("CA registrar not found")
16-
)
17-
189
// SigningIdentity is the identity object that encapsulates the user's private key for signing
1910
// and the user's enrollment certificate (identity)
2011
type SigningIdentity struct {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ SPDX-License-Identifier: Apache-2.0
77
package msp
88

99
import (
10-
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
10+
"errors"
1111
)
1212

13-
// Client provides management of identities in a Fabric network
14-
type Client interface {
13+
var (
14+
// ErrCARegistrarNotFound indicates the CA registrar was not found
15+
ErrCARegistrarNotFound = errors.New("CA registrar not found")
16+
)
17+
18+
// CAClient provides management of identities in a Fabric network
19+
type CAClient interface {
1520
CAName() string
1621
Enroll(enrollmentID string, enrollmentSecret string) error
17-
Reenroll(user core.User) error
22+
Reenroll(enrollmentID string) error
1823
Register(request *RegistrationRequest) (string, error)
1924
Revoke(request *RevocationRequest) (*RevocationResponse, error)
2025
}

pkg/context/api/msp/mocks/mockmspapi.gen.go

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/core/identitymgr/caclient.go

Lines changed: 0 additions & 132 deletions
This file was deleted.

pkg/core/identitymgr/enrollment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestGetSigningIdentityWithEnrollment(t *testing.T) {
104104

105105
ctrl := gomock.NewController(t)
106106
defer ctrl.Finish()
107-
caClient := camocks.NewMockClient(ctrl)
107+
caClient := camocks.NewMockCAClient(ctrl)
108108
prepareForEnroll(t, caClient, cs)
109109

110110
err = caClient.Enroll(userToEnroll, "enrollmentSecret")
@@ -118,7 +118,7 @@ func TestGetSigningIdentityWithEnrollment(t *testing.T) {
118118
}
119119

120120
// Simulate caClient.Enroll()
121-
func prepareForEnroll(t *testing.T, mc *camocks.MockClient, cs core.CryptoSuite) {
121+
func prepareForEnroll(t *testing.T, mc *camocks.MockCAClient, cs core.CryptoSuite) {
122122
// A real caClient.Enroll() generates a CSR. In the process, a crypto suite generates
123123
// a new key pair, and the private key is stored into crypto suite private key storage.
124124

pkg/core/identitymgr/getsigid.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/pkg/errors"
2020
)
2121

22-
func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
22+
func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*User, error) {
2323
pubKey, err := cryptoutil.GetPublicKeyFromCert(userData.EnrollmentCertificate, cryptoSuite)
2424
if err != nil {
2525
return nil, errors.WithMessage(err, "fetching public key from cert failed")
@@ -28,7 +28,7 @@ func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
2828
if err != nil {
2929
return nil, errors.WithMessage(err, "cryptoSuite GetKey failed")
3030
}
31-
u := &user{
31+
u := &User{
3232
mspID: userData.MspID,
3333
name: userData.Name,
3434
enrollmentCertificate: userData.EnrollmentCertificate,
@@ -37,7 +37,8 @@ func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
3737
return u, nil
3838
}
3939

40-
func (mgr *IdentityManager) newUser(userData UserData) (*user, error) {
40+
// NewUser creates a User instance
41+
func (mgr *IdentityManager) NewUser(userData UserData) (*User, error) {
4142
return newUser(userData, mgr.cryptoSuite)
4243
}
4344

@@ -50,7 +51,7 @@ func (mgr *IdentityManager) loadUserFromStore(userName string) (core.User, error
5051
if err != nil {
5152
return nil, err
5253
}
53-
user, err = mgr.newUser(userData)
54+
user, err = mgr.NewUser(userData)
5455
if err != nil {
5556
return nil, err
5657
}
@@ -109,7 +110,7 @@ func (mgr *IdentityManager) GetUser(userName string) (core.User, error) {
109110
if err != nil {
110111
return nil, errors.WithMessage(err, "MSP ID config read failed")
111112
}
112-
u = &user{
113+
u = &User{
113114
mspID: mspID,
114115
name: userName,
115116
enrollmentCertificate: certBytes,

0 commit comments

Comments
 (0)