/
configuration.go
244 lines (207 loc) · 6.33 KB
/
configuration.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package commonext
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/common/tools/protolator/protoext/ordererext"
"github.com/hyperledger/fabric/common/tools/protolator/protoext/peerext"
"github.com/pkg/errors"
)
type DynamicChannelGroup struct {
*common.ConfigGroup
}
func (dcg *DynamicChannelGroup) DynamicMapFields() []string {
return []string{"values", "groups"}
}
func (dcg *DynamicChannelGroup) Underlying() proto.Message {
return dcg.ConfigGroup
}
func (dcg *DynamicChannelGroup) 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 "Consortiums":
return &DynamicConsortiumsGroup{ConfigGroup: cg}, nil
case "Orderer":
return &ordererext.DynamicOrdererGroup{ConfigGroup: cg}, nil
case "Application":
return &peerext.DynamicApplicationGroup{ConfigGroup: cg}, nil
default:
return nil, errors.Errorf("unknown channel group sub-group '%s'", key)
}
case "values":
cv, ok := base.(*common.ConfigValue)
if !ok {
return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
}
return &DynamicChannelConfigValue{
ConfigValue: cv,
name: key,
}, nil
default:
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
}
type DynamicChannelConfigValue struct {
*common.ConfigValue
name string
}
func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFields() []string {
return []string{"value"}
}
func (dccv *DynamicChannelConfigValue) Underlying() proto.Message {
return dccv.ConfigValue
}
func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
if name != "value" {
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
switch dccv.name {
case "HashingAlgorithm":
return &common.HashingAlgorithm{}, nil
case "BlockDataHashingStructure":
return &common.BlockDataHashingStructure{}, nil
case "OrdererAddresses":
return &common.OrdererAddresses{}, nil
case "Consortium":
return &common.Consortium{}, nil
case "Capabilities":
return &common.Capabilities{}, nil
default:
return nil, fmt.Errorf("unknown Channel ConfigValue name: %s", dccv.name)
}
}
type DynamicConsortiumsGroup struct {
*common.ConfigGroup
}
func (dcg *DynamicConsortiumsGroup) Underlying() proto.Message {
return dcg.ConfigGroup
}
func (dcg *DynamicConsortiumsGroup) DynamicMapFields() []string {
return []string{"values", "groups"}
}
func (dcg *DynamicConsortiumsGroup) 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 &DynamicConsortiumGroup{
ConfigGroup: cg,
}, nil
case "values":
return nil, fmt.Errorf("Consortiums currently support no config values")
default:
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
}
}
type DynamicConsortiumGroup struct {
*common.ConfigGroup
}
func (dcg *DynamicConsortiumGroup) Underlying() proto.Message {
return dcg.ConfigGroup
}
func (dcg *DynamicConsortiumGroup) DynamicMapFields() []string {
return []string{"values", "groups"}
}
func (dcg *DynamicConsortiumGroup) 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 &DynamicConsortiumOrgGroup{
ConfigGroup: cg,
}, nil
case "values":
cv, ok := base.(*common.ConfigValue)
if !ok {
return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
}
return &DynamicConsortiumConfigValue{
ConfigValue: cv,
name: key,
}, nil
default:
return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
}
}
type DynamicConsortiumConfigValue struct {
*common.ConfigValue
name string
}
func (dccv *DynamicConsortiumConfigValue) Underlying() proto.Message {
return dccv.ConfigValue
}
func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFields() []string {
return []string{"value"}
}
func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != "value" {
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
switch dccv.name {
case "ChannelCreationPolicy":
return &common.Policy{}, nil
default:
return nil, fmt.Errorf("unknown Consortium ConfigValue name: %s", dccv.name)
}
}
type DynamicConsortiumOrgGroup struct {
*common.ConfigGroup
}
func (dcg *DynamicConsortiumOrgGroup) Underlying() proto.Message {
return dcg.ConfigGroup
}
func (dcg *DynamicConsortiumOrgGroup) DynamicMapFields() []string {
return []string{"groups", "values"}
}
func (dcg *DynamicConsortiumOrgGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
switch name {
case "groups":
return nil, fmt.Errorf("ConsortiumOrg groups do not support sub groups")
case "values":
cv, ok := base.(*common.ConfigValue)
if !ok {
return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
}
return &DynamicConsortiumOrgConfigValue{
ConfigValue: cv,
name: key,
}, nil
default:
return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
}
}
type DynamicConsortiumOrgConfigValue struct {
*common.ConfigValue
name string
}
func (dcocv *DynamicConsortiumOrgConfigValue) Underlying() proto.Message {
return dcocv.ConfigValue
}
func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFields() []string {
return []string{"value"}
}
func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
if name != "value" {
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
switch dcocv.name {
case "MSP":
return &msp.MSPConfig{}, nil
default:
return nil, fmt.Errorf("unknown Consortium Org ConfigValue name: %s", dcocv.name)
}
}