Skip to content

Commit

Permalink
[FAB-8684] Split IdentityManager and CA Client impl
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Aleksandar Likic committed Mar 10, 2018
1 parent c9bd65a commit 0c30596
Show file tree
Hide file tree
Showing 23 changed files with 1,061 additions and 755 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ dockerenv-latest-up: clean
.PHONY: mock-gen
mock-gen:
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
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
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
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
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
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
Expand Down
9 changes: 0 additions & 9 deletions pkg/context/api/core/identitymgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ SPDX-License-Identifier: Apache-2.0

package core

import (
"errors"
)

var (
// ErrCARegistrarNotFound indicates the CA registrar was not found
ErrCARegistrarNotFound = errors.New("CA registrar not found")
)

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ SPDX-License-Identifier: Apache-2.0
package msp

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

// Client provides management of identities in a Fabric network
type Client interface {
var (
// ErrCARegistrarNotFound indicates the CA registrar was not found
ErrCARegistrarNotFound = errors.New("CA registrar not found")
)

// CAClient provides management of identities in a Fabric network
type CAClient interface {
CAName() string
Enroll(enrollmentID string, enrollmentSecret string) error
Reenroll(user core.User) error
Reenroll(enrollmentID string) error
Register(request *RegistrationRequest) (string, error)
Revoke(request *RevocationRequest) (*RevocationResponse, error)
}
Expand Down
55 changes: 27 additions & 28 deletions pkg/context/api/msp/mocks/mockmspapi.gen.go

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

132 changes: 0 additions & 132 deletions pkg/core/identitymgr/caclient.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/core/identitymgr/enrollment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestGetSigningIdentityWithEnrollment(t *testing.T) {

ctrl := gomock.NewController(t)
defer ctrl.Finish()
caClient := camocks.NewMockClient(ctrl)
caClient := camocks.NewMockCAClient(ctrl)
prepareForEnroll(t, caClient, cs)

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

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

Expand Down
11 changes: 6 additions & 5 deletions pkg/core/identitymgr/getsigid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/pkg/errors"
)

func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*User, error) {
pubKey, err := cryptoutil.GetPublicKeyFromCert(userData.EnrollmentCertificate, cryptoSuite)
if err != nil {
return nil, errors.WithMessage(err, "fetching public key from cert failed")
Expand All @@ -28,7 +28,7 @@ func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
if err != nil {
return nil, errors.WithMessage(err, "cryptoSuite GetKey failed")
}
u := &user{
u := &User{
mspID: userData.MspID,
name: userData.Name,
enrollmentCertificate: userData.EnrollmentCertificate,
Expand All @@ -37,7 +37,8 @@ func newUser(userData UserData, cryptoSuite core.CryptoSuite) (*user, error) {
return u, nil
}

func (mgr *IdentityManager) newUser(userData UserData) (*user, error) {
// NewUser creates a User instance
func (mgr *IdentityManager) NewUser(userData UserData) (*User, error) {
return newUser(userData, mgr.cryptoSuite)
}

Expand All @@ -50,7 +51,7 @@ func (mgr *IdentityManager) loadUserFromStore(userName string) (core.User, error
if err != nil {
return nil, err
}
user, err = mgr.newUser(userData)
user, err = mgr.NewUser(userData)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -109,7 +110,7 @@ func (mgr *IdentityManager) GetUser(userName string) (core.User, error) {
if err != nil {
return nil, errors.WithMessage(err, "MSP ID config read failed")
}
u = &user{
u = &User{
mspID: mspID,
name: userName,
enrollmentCertificate: certBytes,
Expand Down
Loading

0 comments on commit 0c30596

Please sign in to comment.