@@ -7,83 +7,60 @@ SPDX-License-Identifier: Apache-2.0
7
7
package resources
8
8
9
9
import (
10
- "github.com/hyperledger/fabric/common/config"
10
+ "fmt"
11
+
12
+ cb "github.com/hyperledger/fabric/protos/common"
11
13
pb "github.com/hyperledger/fabric/protos/peer"
12
14
13
15
"github.com/golang/protobuf/proto"
14
16
)
15
17
16
18
// ResourceGroup represents the ConfigGroup at the base of the resource configuration
17
19
type resourceGroup struct {
18
- pendingResourceToPolicyRef map [string ]string
19
- vpr * valueProposerRoot
20
- }
21
-
22
- func newResourceGroup (vpr * valueProposerRoot ) * resourceGroup {
23
- return & resourceGroup {
24
- vpr : vpr ,
25
- pendingResourceToPolicyRef : make (map [string ]string ),
26
- }
27
- }
28
-
29
- // BeginValueProposals is invoked for each sub-group. These sub-groups are only for defining policies, not other config
30
- // so, an emptyGroup is returned to handle them
31
- func (rg * resourceGroup ) BeginValueProposals (tx interface {}, groups []string ) (config.ValueDeserializer , []config.ValueProposer , error ) {
32
- subGroups := make ([]config.ValueProposer , len (groups ))
33
- for i := range subGroups {
34
- subGroups [i ] = emptyGroup {}
35
- }
36
- return & resourceGroupDeserializer {rg : rg }, subGroups , nil
37
- }
38
-
39
- // RollbackConfig a no-op
40
- func (rg * resourceGroup ) RollbackProposals (tx interface {}) {}
41
-
42
- // PreCommit is a no-op
43
- func (rg * resourceGroup ) PreCommit (tx interface {}) error { return nil }
44
-
45
- // CommitProposals writes the pendingResourceToPolicyRef map to the resource config root
46
- func (rg * resourceGroup ) CommitProposals (tx interface {}) {
47
- rg .vpr .updatePolicyRefForResources (rg .pendingResourceToPolicyRef )
20
+ resourcePolicyRefs map [string ]string
48
21
}
49
22
50
- type resourceGroupDeserializer struct {
51
- rg * resourceGroup
23
+ func ( rg * resourceGroup ) PolicyRefForResource ( resourceName string ) string {
24
+ return rg . resourcePolicyRefs [ resourceName ]
52
25
}
53
26
54
- // Deserialize unmarshals bytes to a pb.Resource
55
- func (rgd * resourceGroupDeserializer ) Deserialize (key string , value []byte ) (proto.Message , error ) {
56
- resource := & pb.Resource {}
57
- if err := proto .Unmarshal (value , resource ); err != nil {
58
- return nil , err
27
+ func newResourceGroup (root * cb.ConfigGroup ) (* resourceGroup , error ) {
28
+ resourcePolicyRefs := make (map [string ]string )
29
+
30
+ for key , value := range root .Values {
31
+ resource := & pb.Resource {}
32
+ if err := proto .Unmarshal (value .Value , resource ); err != nil {
33
+ return nil , err
34
+ }
35
+
36
+ // If the policy is fully qualified, ie to /Channel/Application/Readers leave it alone
37
+ // otherwise, make it fully qualified referring to /Resources/policyName
38
+ if '/' != resource .PolicyRef [0 ] {
39
+ resourcePolicyRefs [key ] = "/" + RootGroupKey + "/" + resource .PolicyRef
40
+ } else {
41
+ resourcePolicyRefs [key ] = resource .PolicyRef
42
+ }
59
43
}
60
44
61
- // If the policy is fully qualified, ie to /Channel/Application/Readers leave it alone
62
- // otherwise, make it fully qualified referring to /Resources/policyName
63
- if '/' != resource .PolicyRef [0 ] {
64
- rgd .rg .pendingResourceToPolicyRef [key ] = "/" + RootGroupKey + "/" + resource .PolicyRef
65
- } else {
66
- rgd .rg .pendingResourceToPolicyRef [key ] = resource .PolicyRef
45
+ for _ , subGroup := range root .Groups {
46
+ if err := verifyNoMoreValues (subGroup ); err != nil {
47
+ return nil , err
48
+ }
67
49
}
68
50
69
- return resource , nil
51
+ return & resourceGroup {
52
+ resourcePolicyRefs : resourcePolicyRefs ,
53
+ }, nil
70
54
}
71
55
72
- type emptyGroup struct {}
73
-
74
- func (eg emptyGroup ) BeginValueProposals (tx interface {}, groups []string ) (config.ValueDeserializer , []config.ValueProposer , error ) {
75
- subGroups := make ([]config.ValueProposer , len (groups ))
76
- for i := range subGroups {
77
- subGroups [i ] = emptyGroup {}
56
+ func verifyNoMoreValues (subGroup * cb.ConfigGroup ) error {
57
+ if len (subGroup .Values ) > 0 {
58
+ return fmt .Errorf ("sub-groups not allowed to have values" )
78
59
}
79
- return failDeserializer ("sub-groups not allowed to have values" ), subGroups , nil
60
+ for _ , subGroup := range subGroup .Groups {
61
+ if err := verifyNoMoreValues (subGroup ); err != nil {
62
+ return err
63
+ }
64
+ }
65
+ return nil
80
66
}
81
-
82
- // RollbackConfig a no-op
83
- func (eg emptyGroup ) RollbackProposals (tx interface {}) {}
84
-
85
- // PreCommit is a no-op
86
- func (eg emptyGroup ) PreCommit (tx interface {}) error { return nil }
87
-
88
- // CommitConfig is a no-op
89
- func (eg emptyGroup ) CommitProposals (tx interface {}) {}
0 commit comments