Skip to content

Commit c7e3168

Browse files
author
Jason Yellick
committed
[FAB-1746] Add util method for policy config items
https://jira.hyperledger.org/browse/FAB-1746 This changeset completes the pattern of providing utility methods in the consumer packages for configuration transaction artifacts by implementing this for the signature policy. Change-Id: Ie74f366f7df2b64fd5fbc245dbd17f5cf61378d3 Signed-off-by: Jason Yellick <[email protected]>
1 parent add2776 commit c7e3168

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

common/cauthdsl/policy_util.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 cauthdsl
18+
19+
import (
20+
cb "github.com/hyperledger/fabric/protos/common"
21+
"github.com/hyperledger/fabric/protos/utils"
22+
)
23+
24+
// TemplatePolicy creates a headerless configuration item representing a policy for a given key
25+
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigurationItem {
26+
return &cb.ConfigurationItem{
27+
Type: cb.ConfigurationItem_Policy,
28+
Key: key,
29+
Value: utils.MarshalOrPanic(&cb.Policy{
30+
Type: int32(cb.Policy_SIGNATURE),
31+
Policy: utils.MarshalOrPanic(sigPolicyEnv),
32+
}),
33+
}
34+
}

orderer/common/bootstrap/provisional/item.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/hyperledger/fabric/common/configtx"
2222
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
2323
cb "github.com/hyperledger/fabric/protos/common"
24-
"github.com/hyperledger/fabric/protos/utils"
2524
)
2625

2726
func (cbs *commonBootstrapper) templateConsensusType() *cb.ConfigurationItem {
@@ -41,12 +40,7 @@ func (cbs *commonBootstrapper) templateChainCreationPolicyNames() *cb.Configurat
4140
}
4241

4342
func (cbs *commonBootstrapper) templateAcceptAllPolicy() *cb.ConfigurationItem {
44-
configItemKey := AcceptAllPolicyKey
45-
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.AcceptAllPolicy))
46-
modPolicy := configtx.NewConfigurationItemPolicyKey
47-
48-
configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
49-
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
43+
return cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy)
5044
}
5145

5246
func (cbs *commonBootstrapper) templateIngressPolicyNames() *cb.ConfigurationItem {
@@ -59,12 +53,7 @@ func (cbs *commonBootstrapper) templateEgressPolicyNames() *cb.ConfigurationItem
5953

6054
func (cbs *commonBootstrapper) templateRejectAllPolicy() *cb.ConfigurationItem {
6155
// Lock down the new configuration item policy to prevent any new configuration items from being created
62-
configItemKey := configtx.NewConfigurationItemPolicyKey
63-
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.RejectAllPolicy))
64-
modPolicy := configtx.NewConfigurationItemPolicyKey
65-
66-
configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
67-
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
56+
return cauthdsl.TemplatePolicy(configtx.NewConfigurationItemPolicyKey, cauthdsl.RejectAllPolicy)
6857
}
6958

7059
func (kbs *kafkaBootstrapper) templateKafkaBrokers() *cb.ConfigurationItem {

0 commit comments

Comments
 (0)