-
Notifications
You must be signed in to change notification settings - Fork 6
/
resources.go
171 lines (143 loc) · 4.6 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package peer
import (
"fmt"
"github.com/hyperledger/fabric/protos/common"
"github.com/golang/protobuf/proto"
)
const ResourceConfigSeedDataKey = "resource_config_seed_data"
func init() {
common.DynamicConfigTypes[common.ConfigType_RESOURCE] = func(cg *common.ConfigGroup) proto.Message {
return &DynamicResourceConfigGroup{
ConfigGroup: cg,
}
}
common.ConfigUpdateIsolatedDataTypes[ResourceConfigSeedDataKey] = func(key string) proto.Message {
return &common.Config{}
}
}
type DynamicResourceConfigGroup struct {
*common.ConfigGroup
}
func (drcg *DynamicResourceConfigGroup) DynamicMapFields() []string {
return []string{"values", "groups"}
}
func (drcg *DynamicResourceConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
switch name {
case "groups":
cg, ok := base.(*common.ConfigGroup)
if !ok {
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
}
switch key {
case "APIs":
return &DynamicResourceAPIsConfigGroup{ConfigGroup: cg}, nil
case "Chaincodes":
return &DynamicResourceChaincodesConfigGroup{ConfigGroup: cg}, nil
case "PeerPolicies":
return cg, nil
}
}
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
type DynamicResourceChaincodesConfigGroup struct {
*common.ConfigGroup
}
func (draccg *DynamicResourceChaincodesConfigGroup) DynamicMapFields() []string {
return []string{"groups"}
}
func (drccg *DynamicResourceChaincodesConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
switch name {
case "groups":
cg, ok := base.(*common.ConfigGroup)
if !ok {
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
}
return &DynamicResourceChaincodeConfigGroup{ConfigGroup: cg}, nil
default:
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
}
type DynamicResourceChaincodeConfigGroup struct {
*common.ConfigGroup
}
func (draccg *DynamicResourceChaincodeConfigGroup) DynamicMapFields() []string {
return []string{"values"}
}
func (drccg *DynamicResourceChaincodeConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
switch name {
case "values":
cv, ok := base.(*common.ConfigValue)
if !ok {
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigValue messages")
}
return &DynamicResourceChaincodeConfigValue{ConfigValue: cv, key: key}, nil
default:
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
}
type DynamicResourceChaincodeConfigValue struct {
*common.ConfigValue
key string
}
func (drccv *DynamicResourceChaincodeConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != drccv.VariablyOpaqueFields()[0] {
return nil, fmt.Errorf("Not a marshaled field: %s", name)
}
switch drccv.key {
case "ChaincodeIdentifier":
return &ChaincodeIdentifier{}, nil
case "ChaincodeValidation":
return &ChaincodeValidation{}, nil
case "ChaincodeEndorsement":
return &ChaincodeEndorsement{}, nil
default:
return nil, fmt.Errorf("unknown value key: %s", drccv.key)
}
}
func (cv *ChaincodeValidation) VariablyOpaqueFields() []string {
return []string{"argument"}
}
func (cv *ChaincodeValidation) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != cv.VariablyOpaqueFields()[0] {
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
switch cv.Name {
case "vscc":
return &VSCCArgs{}, nil
default:
return nil, fmt.Errorf("unknown validation name: %s", cv.Name)
}
}
type DynamicResourceAPIsConfigGroup struct {
*common.ConfigGroup
}
func (dracg *DynamicResourceAPIsConfigGroup) DynamicMapFields() []string {
return []string{"values"}
}
func (dracg *DynamicResourceAPIsConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
switch name {
case "values":
cv, ok := base.(*common.ConfigValue)
if !ok {
return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
}
return &DynamicResourceAPIsConfigValue{
ConfigValue: cv,
}, nil
default:
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
}
type DynamicResourceAPIsConfigValue struct {
*common.ConfigValue
}
func (drcv *DynamicResourceAPIsConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != drcv.VariablyOpaqueFields()[0] {
return nil, fmt.Errorf("Not a marshaled field: %s", name)
}
return &APIResource{}, nil
}