Skip to content

Commit

Permalink
[FAB-1746] Add util method for policy config items
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jan 19, 2017
1 parent add2776 commit c7e3168
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
34 changes: 34 additions & 0 deletions common/cauthdsl/policy_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cauthdsl

import (
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)

// TemplatePolicy creates a headerless configuration item representing a policy for a given key
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Policy,
Key: key,
Value: utils.MarshalOrPanic(&cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Policy: utils.MarshalOrPanic(sigPolicyEnv),
}),
}
}
15 changes: 2 additions & 13 deletions orderer/common/bootstrap/provisional/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/hyperledger/fabric/common/configtx"
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)

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

func (cbs *commonBootstrapper) templateAcceptAllPolicy() *cb.ConfigurationItem {
configItemKey := AcceptAllPolicyKey
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.AcceptAllPolicy))
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
return cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy)
}

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

func (cbs *commonBootstrapper) templateRejectAllPolicy() *cb.ConfigurationItem {
// Lock down the new configuration item policy to prevent any new configuration items from being created
configItemKey := configtx.NewConfigurationItemPolicyKey
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.RejectAllPolicy))
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
return cauthdsl.TemplatePolicy(configtx.NewConfigurationItemPolicyKey, cauthdsl.RejectAllPolicy)
}

func (kbs *kafkaBootstrapper) templateKafkaBrokers() *cb.ConfigurationItem {
Expand Down

0 comments on commit c7e3168

Please sign in to comment.