-
Notifications
You must be signed in to change notification settings - Fork 0
/
filecertstore.go
41 lines (35 loc) · 1.21 KB
/
filecertstore.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
"fmt"
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/vtbaas/vbaas-go-sdk/pkg/common/providers/core"
"github.com/vtbaas/vbaas-go-sdk/pkg/common/providers/msp"
"github.com/vtbaas/vbaas-go-sdk/pkg/fab/keyvaluestore"
)
// NewFileCertStore ...
func NewFileCertStore(cryptoConfigMSPPath string) (core.KVStore, error) {
_, orgName := filepath.Split(filepath.Dir(filepath.Dir(filepath.Dir(cryptoConfigMSPPath))))
opts := &keyvaluestore.FileKeyValueStoreOptions{
Path: cryptoConfigMSPPath,
KeySerializer: func(key interface{}) (string, error) {
ck, ok := key.(*msp.IdentityIdentifier)
if !ok {
return "", errors.New("converting key to CertKey failed")
}
if ck == nil || ck.MSPID == "" || ck.ID == "" {
return "", errors.New("invalid key")
}
// TODO: refactor to case insensitive or remove eventually.
r := strings.NewReplacer("{userName}", ck.ID, "{username}", ck.ID)
certDir := filepath.Join(r.Replace(cryptoConfigMSPPath), "signcerts")
return filepath.Join(certDir, fmt.Sprintf("%s@%s-cert.pem", ck.ID, orgName)), nil
},
}
return keyvaluestore.New(opts)
}