-
Notifications
You must be signed in to change notification settings - Fork 0
/
mspfactory.go
53 lines (43 loc) · 1.74 KB
/
mspfactory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package defmsp
import (
"github.com/jxu86/fabric-sdk-go-gm/pkg/common/providers/core"
"github.com/jxu86/fabric-sdk-go-gm/pkg/common/providers/fab"
"github.com/jxu86/fabric-sdk-go-gm/pkg/common/providers/msp"
kvs "github.com/jxu86/fabric-sdk-go-gm/pkg/fab/keyvaluestore"
"github.com/jxu86/fabric-sdk-go-gm/pkg/fabsdk/provider/msppvdr"
mspimpl "github.com/jxu86/fabric-sdk-go-gm/pkg/msp"
"github.com/pkg/errors"
)
// ProviderFactory represents the default MSP provider factory.
type ProviderFactory struct {
}
// NewProviderFactory returns the default MSP provider factory.
func NewProviderFactory() *ProviderFactory {
f := ProviderFactory{}
return &f
}
// CreateUserStore creates a UserStore using the SDK's default implementation
func (f *ProviderFactory) CreateUserStore(config msp.IdentityConfig) (msp.UserStore, error) {
stateStorePath := config.CredentialStorePath()
var userStore msp.UserStore
if stateStorePath == "" {
return mspimpl.NewMemoryUserStore(), nil
}
stateStore, err := kvs.New(&kvs.FileKeyValueStoreOptions{Path: stateStorePath})
if err != nil {
return nil, errors.WithMessage(err, "CreateNewFileKeyValueStore failed")
}
userStore, err = mspimpl.NewCertFileUserStore1(stateStore)
if err != nil {
return nil, errors.Wrapf(err, "creating a user store failed")
}
return userStore, nil
}
// CreateIdentityManagerProvider returns a new default implementation of MSP provider
func (f *ProviderFactory) CreateIdentityManagerProvider(endpointConfig fab.EndpointConfig, cryptoProvider core.CryptoSuite, userStore msp.UserStore) (msp.IdentityManagerProvider, error) {
return msppvdr.New(endpointConfig, cryptoProvider, userStore)
}