Skip to content

Commit a9ad961

Browse files
author
Jason Yellick
committed
[FAB-2324] Add reader/writer/admin defaults
https://jira.hyperledger.org/browse/FAB-2324 This CR adds default reader/writer/admin policies to the dynamically generated gensis block. There are currently no consumers of these policies, but will be added later. Change-Id: I000220feb9ff1bd806a724b77ea9dcf62f5aa294 Signed-off-by: Jason Yellick <[email protected]>
1 parent 018d888 commit a9ad961

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

common/configtx/tool/provisional/provisional.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
"github.com/hyperledger/fabric/common/configtx"
2424
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2525
configtxchannel "github.com/hyperledger/fabric/common/configvalues/channel"
26+
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
2627
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
2728
"github.com/hyperledger/fabric/common/genesis"
29+
"github.com/hyperledger/fabric/common/policies"
2830
"github.com/hyperledger/fabric/orderer/common/bootstrap"
2931
cb "github.com/hyperledger/fabric/protos/common"
3032
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -54,6 +56,15 @@ const (
5456

5557
// AcceptAllPolicyKey is the key of the AcceptAllPolicy.
5658
AcceptAllPolicyKey = "AcceptAllPolicy"
59+
60+
// ReadersPolicyKey is the key used for the read policy
61+
ReadersPolicyKey = "Readers"
62+
63+
// WritersPolicyKey is the key used for the read policy
64+
WritersPolicyKey = "Writers"
65+
66+
// AdminsPolicyKey is the key used for the read policy
67+
AdminsPolicyKey = "Admins"
5768
)
5869

5970
// DefaultChainCreationPolicyNames is the default value of ChainCreatorsKey.
@@ -85,8 +96,22 @@ func New(conf *genesisconfig.TopLevel) Generator {
8596
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
8697

8798
// Policies
88-
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
8999
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
100+
101+
// Initialize the default Reader/Writer/Admins channel policies
102+
policies.TemplateImplicitMetaAnyPolicy([]string{}, ReadersPolicyKey),
103+
policies.TemplateImplicitMetaAnyPolicy([]string{}, WritersPolicyKey),
104+
policies.TemplateImplicitMetaMajorityPolicy([]string{}, AdminsPolicyKey),
105+
106+
// Initialize the default Reader/Writer/Admins orderer policies
107+
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, ReadersPolicyKey),
108+
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, WritersPolicyKey),
109+
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxorderer.GroupKey}, AdminsPolicyKey),
110+
111+
// Initialize the default Reader/Writer/Admins application policies
112+
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, ReadersPolicyKey),
113+
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, WritersPolicyKey),
114+
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxapplication.GroupKey}, AdminsPolicyKey),
90115
},
91116

92117
systemChainGroups: []*cb.ConfigGroup{

common/policies/implicitmeta_util.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package policies
18+
19+
import (
20+
cb "github.com/hyperledger/fabric/protos/common"
21+
"github.com/hyperledger/fabric/protos/utils"
22+
)
23+
24+
// TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName
25+
// It utilizes the policyName for the subPolicyName as well, as this is the standard usage pattern
26+
func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
27+
root := cb.NewConfigGroup()
28+
group := root
29+
for _, element := range path {
30+
group.Groups[element] = cb.NewConfigGroup()
31+
group = group.Groups[element]
32+
}
33+
34+
group.Policies[policyName] = &cb.ConfigPolicy{
35+
Policy: &cb.Policy{
36+
Type: int32(cb.Policy_IMPLICIT_META),
37+
Policy: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
38+
Rule: rule,
39+
SubPolicy: policyName,
40+
}),
41+
},
42+
}
43+
return root
44+
}
45+
46+
// TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_ANY as the rule
47+
func TemplateImplicitMetaAnyPolicy(path []string, policyName string) *cb.ConfigGroup {
48+
return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ANY)
49+
}
50+
51+
// TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_ALL as the rule
52+
func TemplateImplicitMetaAllPolicy(path []string, policyName string) *cb.ConfigGroup {
53+
return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ALL)
54+
}
55+
56+
// TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_MAJORITY as the rule
57+
func TemplateImplicitMetaMajorityPolicy(path []string, policyName string) *cb.ConfigGroup {
58+
return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_MAJORITY)
59+
}

0 commit comments

Comments
 (0)