/
vaultConnector.go
49 lines (40 loc) · 1.98 KB
/
vaultConnector.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
/*
Copyright Idea LCC. All Rights Reserved.
SPDX-License-Identifier: [Default license](LICENSE)
*/
package cartridge
import (
"github.com/atomyze-foundation/cartridge/connector/vaultconnector"
"github.com/atomyze-foundation/cartridge/cryptocache"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
)
// VaultConnector - VaultConnector is a struct that implements the core.ConfigProvider interface
type VaultConnector struct {
coreBackend []core.ConfigBackend
ChannelConfigProvider func(name string) *fab.ChannelEndpointConfig
ChannelPeersProvider func(channel string) []fab.ChannelPeer
}
// NewVaultConnectProvider - NewVaultConnectProvider returns a new instance of VaultConnector
func NewVaultConnectProvider(coreBackend ...core.ConfigBackend) *VaultConnector {
return &VaultConnector{
coreBackend: coreBackend,
}
}
// WithChannelConfigProvider - WithChannelConfigProvider sets the channel config provider
func (c *VaultConnector) WithChannelConfigProvider(channelConfigProvider func(name string) *fab.ChannelEndpointConfig) {
c.ChannelConfigProvider = channelConfigProvider
}
// WithChannelPeersProvider - WithChannelPeersProvider sets the channel peers provider
func (c *VaultConnector) WithChannelPeersProvider(channelPeersProvider func(channel string) []fab.ChannelPeer) {
c.ChannelPeersProvider = channelPeersProvider
}
// IdentityConfig - IdentityConfig returns the identity config
func (c *VaultConnector) IdentityConfig(cache cryptocache.CryptoCache) (msp.IdentityConfig, error) {
return vaultconnector.IdentityConfigFromBackend(cache, c.coreBackend...)
}
// EndpointConfig - EndpointConfig returns the endpoint config
func (c *VaultConnector) EndpointConfig(cache cryptocache.CryptoCache) (fab.EndpointConfig, error) {
return vaultconnector.EndpointConfigFromBackend(cache, c.ChannelConfigProvider, c.ChannelPeersProvider, c.coreBackend...)
}