-
Notifications
You must be signed in to change notification settings - Fork 92
/
capabilities.go
55 lines (45 loc) · 1.59 KB
/
capabilities.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
54
55
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Please review third_party pinning scripts and patches for more details.
*/
package capabilities
import (
cb "github.com/hyperledger/fabric-protos-go/common"
flogging "github.com/kfsoftware/hlf-operator/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
"github.com/pkg/errors"
)
var logger = flogging.MustGetLogger("common.capabilities")
// provider is the 'plugin' parameter for registry.
type provider interface {
// HasCapability should report whether the binary supports this capability.
HasCapability(capability string) bool
// Type is used to make error messages more legible.
Type() string
}
// registry is a common structure intended to be used to support specific aspects of capabilities
// such as orderer, application, and channel.
type registry struct {
provider provider
capabilities map[string]*cb.Capability
}
func newRegistry(p provider, capabilities map[string]*cb.Capability) *registry {
return ®istry{
provider: p,
capabilities: capabilities,
}
}
// Supported checks that all of the required capabilities are supported by this binary.
func (r *registry) Supported() error {
for capabilityName := range r.capabilities {
if r.provider.HasCapability(capabilityName) {
logger.Debugf("%s capability %s is supported and is enabled", r.provider.Type(), capabilityName)
continue
}
return errors.Errorf("%s capability %s is required but not supported", r.provider.Type(), capabilityName)
}
return nil
}