Skip to content

Commit

Permalink
[FAB-8583] Move IdentityManager interface
Browse files Browse the repository at this point in the history
The IdentityManager interface is not Fabric specific. It has been
moved to pkg/context/api. It is now created by the SDK Core
Provider instead of the Fabric Provider.

The default implementation is Fabric CA specific, so it stays
under fab.

Change-Id: I024f71a6c94e21f61799ed92c97b053711d99304
Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
  • Loading branch information
Aleksandar Likic committed Mar 1, 2018
1 parent e81d3ed commit 82e18d8
Show file tree
Hide file tree
Showing 39 changed files with 309 additions and 255 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -323,8 +323,9 @@ dockerenv-latest-up: clean

.PHONY: mock-gen
mock-gen:
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api IdentityManager | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/mocks/mockidmgr.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/core Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/core/mocks/mockconfig.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab ProposalProcessor,IdentityManager | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/fab/mocks/mockcontextapi.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/context/api/fab/mocks/mockcontextapi.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api CoreProviders,SvcProviders,Providers,CoreProviderFactory,ServiceProviderFactory,SessionClientFactory | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/fabsdk/mocks/mockfabsdkapi.gen.go


Expand Down
17 changes: 0 additions & 17 deletions pkg/context/api/credentialmgr.go

This file was deleted.

106 changes: 1 addition & 105 deletions pkg/context/api/fab/mocks/mockcontextapi.gen.go

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

Expand Up @@ -4,12 +4,11 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fab
package api

import (
"errors"

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

Expand All @@ -18,11 +17,19 @@ var (
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 {
MspID string
EnrollmentCert []byte
PrivateKey core.Key
}

// IdentityManager provides management of identities in a Fabric network
type IdentityManager interface {
GetSigningIdentity(name string) (*contextApi.SigningIdentity, error)
GetSigningIdentity(name string) (*SigningIdentity, error)
Enroll(enrollmentID string, enrollmentSecret string) (core.Key, []byte, error)
Reenroll(user contextApi.User) (core.Key, []byte, error)
Reenroll(user User) (core.Key, []byte, error)
Register(request *RegistrationRequest) (string, error)
Revoke(request *RevocationRequest) (*RevocationResponse, error)
CAName() string
Expand Down
115 changes: 115 additions & 0 deletions pkg/context/api/mocks/mockidmgr.gen.go

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

Expand Up @@ -12,7 +12,6 @@ import (
calib "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib"
contextApi "github.com/hyperledger/fabric-sdk-go/pkg/context/api"
config "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/core/config/urlutil"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
Expand Down Expand Up @@ -46,7 +45,7 @@ func (im *IdentityManager) initCAClient() error {
func (im *IdentityManager) getRegistrarSI(enrollID string, enrollSecret string) (*calib.Identity, error) {

if enrollID == "" {
return nil, fab.ErrCARegistrarNotFound
return nil, contextApi.ErrCARegistrarNotFound
}

si, err := im.GetSigningIdentity(enrollID)
Expand All @@ -55,7 +54,7 @@ func (im *IdentityManager) getRegistrarSI(enrollID string, enrollSecret string)
return nil, err
}
if enrollSecret == "" {
return nil, fab.ErrCARegistrarNotFound
return nil, contextApi.ErrCARegistrarNotFound
}

// Attempt to enroll the registrar
Expand Down
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
camocks "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab/mocks"
apimocks "github.com/hyperledger/fabric-sdk-go/pkg/context/api/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/identity"

"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestGetSigningIdentityWithEnrollment(t *testing.T) {

cs, err := sw.GetSuiteByConfig(config)

credentialMgr, err := New(orgName, config, cs)
credentialMgr, err := New(orgName, cs, config)
if err != nil {
t.Fatalf("Failed to setup credential manager: %s", err)
}
Expand All @@ -74,7 +74,7 @@ func TestGetSigningIdentityWithEnrollment(t *testing.T) {

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

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

// Simulate caClient.Enroll()
func prepareForEnroll(t *testing.T, mc *camocks.MockIdentityManager, cs core.CryptoSuite) {
func prepareForEnroll(t *testing.T, mc *apimocks.MockIdentityManager, 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
Expand Up @@ -17,7 +17,7 @@ import (
fabricCaUtil "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/identitymgr/persistence"
"github.com/hyperledger/fabric-sdk-go/pkg/core/identitymgr/persistence"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -73,7 +73,6 @@ func (mgr *IdentityManager) GetSigningIdentity(userName string) (*api.SigningIde
}
signingIdentity = &api.SigningIdentity{MspID: mspID, PrivateKey: privateKey, EnrollmentCert: certBytes}
}

return signingIdentity, nil
}

Expand Down

0 comments on commit 82e18d8

Please sign in to comment.