github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/policies/implicitmeta_util.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package policies
     8  
     9  import (
    10  	cb "github.com/hyperledger/fabric-protos-go/common"
    11  	"github.com/hyperledger/fabric/protoutil"
    12  )
    13  
    14  // ImplicitMetaPolicyWithSubPolicy creates an implicitmeta policy
    15  func ImplicitMetaPolicyWithSubPolicy(subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigPolicy {
    16  	return &cb.ConfigPolicy{
    17  		Policy: &cb.Policy{
    18  			Type: int32(cb.Policy_IMPLICIT_META),
    19  			Value: protoutil.MarshalOrPanic(&cb.ImplicitMetaPolicy{
    20  				Rule:      rule,
    21  				SubPolicy: subPolicyName,
    22  			}),
    23  		},
    24  	}
    25  }
    26  
    27  // TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName and subPolicyName
    28  func TemplateImplicitMetaPolicyWithSubPolicy(path []string, policyName string, subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
    29  	root := protoutil.NewConfigGroup()
    30  	group := root
    31  	for _, element := range path {
    32  		group.Groups[element] = protoutil.NewConfigGroup()
    33  		group = group.Groups[element]
    34  	}
    35  
    36  	group.Policies[policyName] = ImplicitMetaPolicyWithSubPolicy(subPolicyName, rule)
    37  	return root
    38  }
    39  
    40  // TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName
    41  // It utilizes the policyName for the subPolicyName as well, as this is the standard usage pattern
    42  func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
    43  	return TemplateImplicitMetaPolicyWithSubPolicy(path, policyName, policyName, rule)
    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  }