Skip to content

Commit c3bfd6d

Browse files
author
Jason Yellick
committed
[FAB-6223] Define resource tree config protos
The resource tree needs to represent both API ACLs as well as chaincodes. This CR renames the Resource message to APIResource and adds a collection of Chaincode messages for defining the chaincode group. For the new Chaincode group, there is now a structure of: [Group] Resources [Group] Chaincodes [Group] mycc [Value] ChaincodeIdentifier bytes hash = 1; string version = 2; [Value] ChaincodeValidation string name = 1; // Set to vscc bytes argument = 2; // A marshaled: message VSCCArgs string endorsement_policy_ref = 1; [Value] ChaincodeEndorsement string name = 1; // Set to escc Change-Id: Ic2d02fb11a55779031eedce898902bc67185a4aa Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent cc29eed commit c3bfd6d

File tree

8 files changed

+338
-34
lines changed

8 files changed

+338
-34
lines changed

common/resourcesconfig/apis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func newAPIsGroup(group *cb.ConfigGroup) (*apisGroup, error) {
3131
apiPolicyRefs := make(map[string]string)
3232

3333
for key, value := range group.Values {
34-
api := &pb.Resource{}
34+
api := &pb.APIResource{}
3535
if err := proto.Unmarshal(value.Value, api); err != nil {
3636
return nil, err
3737
}

common/resourcesconfig/bundle_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func TestBundleGreenPath(t *testing.T) {
3737
APIsGroupKey: &cb.ConfigGroup{
3838
Values: map[string]*cb.ConfigValue{
3939
"Foo": &cb.ConfigValue{
40-
Value: utils.MarshalOrPanic(&pb.Resource{
40+
Value: utils.MarshalOrPanic(&pb.APIResource{
4141
PolicyRef: "foo",
4242
}),
4343
},
4444
"Bar": &cb.ConfigValue{
45-
Value: utils.MarshalOrPanic(&pb.Resource{
45+
Value: utils.MarshalOrPanic(&pb.APIResource{
4646
PolicyRef: "/Channel/foo",
4747
}),
4848
},
@@ -87,8 +87,8 @@ func TestBundleBadSubGroup(t *testing.T) {
8787
Groups: map[string]*cb.ConfigGroup{
8888
PeerPoliciesGroupKey: &cb.ConfigGroup{
8989
Values: map[string]*cb.ConfigValue{
90-
"Foo": {
91-
Value: utils.MarshalOrPanic(&pb.Resource{
90+
"Foo": &cb.ConfigValue{
91+
Value: utils.MarshalOrPanic(&pb.APIResource{
9292
PolicyRef: "foo",
9393
}),
9494
},

common/tools/protolator/blackbox_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
2525
. "github.com/hyperledger/fabric/common/tools/protolator"
2626
cb "github.com/hyperledger/fabric/protos/common"
27+
pb "github.com/hyperledger/fabric/protos/peer"
2728
"github.com/hyperledger/fabric/protos/utils"
2829

2930
"github.com/golang/protobuf/proto"
@@ -72,3 +73,54 @@ func TestGenesisBlock(t *testing.T) {
7273

7374
bidirectionalMarshal(t, gb)
7475
}
76+
77+
func TestResourcesConfig(t *testing.T) {
78+
p := &cb.Config{
79+
Type: int32(cb.ConfigType_RESOURCE),
80+
ChannelGroup: &cb.ConfigGroup{
81+
Groups: map[string]*cb.ConfigGroup{
82+
"Chaincodes": &cb.ConfigGroup{
83+
Groups: map[string]*cb.ConfigGroup{
84+
"cc1": &cb.ConfigGroup{
85+
Values: map[string]*cb.ConfigValue{
86+
"ChaincodeIdentifier": &cb.ConfigValue{
87+
Value: utils.MarshalOrPanic(&pb.ChaincodeIdentifier{
88+
Hash: []byte("somehashvalue"),
89+
Version: "aversionstring",
90+
}),
91+
},
92+
"ChaincodeValidation": &cb.ConfigValue{
93+
Value: utils.MarshalOrPanic(
94+
&pb.ChaincodeValidation{
95+
Name: "vscc",
96+
Argument: utils.MarshalOrPanic(&pb.VSCCArgs{
97+
EndorsementPolicyRef: "foo",
98+
}),
99+
}),
100+
},
101+
"ChaincodeEndorsement": &cb.ConfigValue{
102+
Value: utils.MarshalOrPanic(&pb.ChaincodeEndorsement{
103+
Name: "escc",
104+
}),
105+
},
106+
},
107+
},
108+
},
109+
},
110+
"APIs": &cb.ConfigGroup{
111+
Values: map[string]*cb.ConfigValue{
112+
"Test": &cb.ConfigValue{
113+
Value: utils.MarshalOrPanic(&pb.APIResource{PolicyRef: "Foo"}),
114+
},
115+
"Another": &cb.ConfigValue{
116+
Value: utils.MarshalOrPanic(&pb.APIResource{PolicyRef: "Bar"}),
117+
},
118+
},
119+
},
120+
"PeerPolicies": &cb.ConfigGroup{},
121+
},
122+
},
123+
}
124+
125+
bidirectionalMarshal(t, p)
126+
}

core/scc/rscc/rscc_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func createConfig() []byte {
9696
// All of the default seed data values would inside this ConfigGroup
9797
Values: map[string]*common.ConfigValue{
9898
"res": &common.ConfigValue{
99-
Value: utils.MarshalOrPanic(&pb.Resource{
99+
Value: utils.MarshalOrPanic(&pb.APIResource{
100100
PolicyRef: "respol",
101101
}),
102102
ModPolicy: "resmodpol",

protos/peer/admin.pb.go

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/peer/resources.go

+112-5
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,139 @@ type DynamicResourceConfigGroup struct {
3333
}
3434

3535
func (drcg *DynamicResourceConfigGroup) DynamicMapFields() []string {
36-
return []string{"values"}
36+
return []string{"values", "groups"}
3737
}
3838

3939
func (drcg *DynamicResourceConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
40+
switch name {
41+
case "groups":
42+
cg, ok := base.(*common.ConfigGroup)
43+
if !ok {
44+
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
45+
}
46+
switch key {
47+
case "APIs":
48+
return &DynamicResourceAPIsConfigGroup{ConfigGroup: cg}, nil
49+
case "Chaincodes":
50+
return &DynamicResourceChaincodesConfigGroup{ConfigGroup: cg}, nil
51+
case "PeerPolicies":
52+
return cg, nil
53+
}
54+
}
55+
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
56+
}
57+
58+
type DynamicResourceChaincodesConfigGroup struct {
59+
*common.ConfigGroup
60+
}
61+
62+
func (draccg *DynamicResourceChaincodesConfigGroup) DynamicMapFields() []string {
63+
return []string{"groups"}
64+
}
65+
66+
func (drccg *DynamicResourceChaincodesConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
67+
switch name {
68+
case "groups":
69+
cg, ok := base.(*common.ConfigGroup)
70+
if !ok {
71+
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
72+
}
73+
return &DynamicResourceChaincodeConfigGroup{ConfigGroup: cg}, nil
74+
default:
75+
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
76+
}
77+
}
78+
79+
type DynamicResourceChaincodeConfigGroup struct {
80+
*common.ConfigGroup
81+
}
82+
83+
func (draccg *DynamicResourceChaincodeConfigGroup) DynamicMapFields() []string {
84+
return []string{"values"}
85+
}
86+
87+
func (drccg *DynamicResourceChaincodeConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
88+
switch name {
89+
case "values":
90+
cv, ok := base.(*common.ConfigValue)
91+
if !ok {
92+
return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigValue messages")
93+
}
94+
return &DynamicResourceChaincodeConfigValue{ConfigValue: cv, key: key}, nil
95+
default:
96+
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
97+
}
98+
}
99+
100+
type DynamicResourceChaincodeConfigValue struct {
101+
*common.ConfigValue
102+
key string
103+
}
104+
105+
func (drccv *DynamicResourceChaincodeConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
106+
if name != drccv.VariablyOpaqueFields()[0] {
107+
return nil, fmt.Errorf("Not a marshaled field: %s", name)
108+
}
109+
110+
switch drccv.key {
111+
case "ChaincodeIdentifier":
112+
return &ChaincodeIdentifier{}, nil
113+
case "ChaincodeValidation":
114+
return &ChaincodeValidation{}, nil
115+
case "ChaincodeEndorsement":
116+
return &ChaincodeEndorsement{}, nil
117+
default:
118+
return nil, fmt.Errorf("unknown value key: %s", drccv.key)
119+
}
120+
}
121+
122+
func (cv *ChaincodeValidation) VariablyOpaqueFields() []string {
123+
return []string{"argument"}
124+
}
125+
126+
func (cv *ChaincodeValidation) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
127+
if name != cv.VariablyOpaqueFields()[0] {
128+
return nil, fmt.Errorf("not a marshaled field: %s", name)
129+
}
130+
switch cv.Name {
131+
case "vscc":
132+
return &VSCCArgs{}, nil
133+
default:
134+
return nil, fmt.Errorf("unknown validation name: %s", cv.Name)
135+
}
136+
}
137+
138+
type DynamicResourceAPIsConfigGroup struct {
139+
*common.ConfigGroup
140+
}
141+
142+
func (dracg *DynamicResourceAPIsConfigGroup) DynamicMapFields() []string {
143+
return []string{"values"}
144+
}
145+
146+
func (dracg *DynamicResourceAPIsConfigGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
40147
switch name {
41148
case "values":
42149
cv, ok := base.(*common.ConfigValue)
43150
if !ok {
44151
return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
45152
}
46-
return &DynamicResourceConfigValue{
153+
return &DynamicResourceAPIsConfigValue{
47154
ConfigValue: cv,
48155
}, nil
49156
default:
50157
return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
51158
}
52159
}
53160

54-
type DynamicResourceConfigValue struct {
161+
type DynamicResourceAPIsConfigValue struct {
55162
*common.ConfigValue
56163
}
57164

58-
func (drcv *DynamicResourceConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
165+
func (drcv *DynamicResourceAPIsConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
59166
if name != drcv.VariablyOpaqueFields()[0] {
60167
return nil, fmt.Errorf("Not a marshaled field: %s", name)
61168
}
62169

63-
return &Resource{}, nil
170+
return &APIResource{}, nil
64171
}

0 commit comments

Comments
 (0)