-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
53 lines (43 loc) · 1.23 KB
/
resources.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 IBM Corp. 2017 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package resourcesconfig
import (
cb "github.com/hyperledger/fabric/protos/common"
"github.com/pkg/errors"
)
const (
PeerPoliciesGroupKey = "PeerPolicies"
APIsGroupKey = "APIs"
)
// resourceGroup represents the ConfigGroup at the base of the resource configuration.
type resourceGroup struct {
apisGroup *apisGroup
peerPoliciesGroup *peerPoliciesGroup
}
func newResourceGroup(root *cb.ConfigGroup) (*resourceGroup, error) {
if len(root.Values) > 0 {
return nil, errors.New("/Resources group does not support any values")
}
// initialize the elements with empty implementations, override if actually set
rg := &resourceGroup{
apisGroup: &apisGroup{},
peerPoliciesGroup: &peerPoliciesGroup{},
}
for subGroupName, subGroup := range root.Groups {
var err error
switch subGroupName {
case APIsGroupKey:
rg.apisGroup, err = newAPIsGroup(subGroup)
case PeerPoliciesGroupKey:
rg.peerPoliciesGroup, err = newPeerPoliciesGroup(subGroup)
default:
err = errors.New("unknown sub-group")
}
if err != nil {
return nil, errors.Wrapf(err, "error processing group %s", subGroupName)
}
}
return rg, nil
}