github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/common/policies/implicitmeta_util.go (about)

     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 and subPolicyName
    25  func TemplateImplicitMetaPolicyWithSubPolicy(path []string, policyName string, subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
    26  	root := cb.NewConfigGroup()
    27  	group := root
    28  	for _, element := range path {
    29  		group.Groups[element] = cb.NewConfigGroup()
    30  		group = group.Groups[element]
    31  	}
    32  
    33  	group.Policies[policyName] = &cb.ConfigPolicy{
    34  		Policy: &cb.Policy{
    35  			Type: int32(cb.Policy_IMPLICIT_META),
    36  			Policy: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
    37  				Rule:      rule,
    38  				SubPolicy: subPolicyName,
    39  			}),
    40  		},
    41  	}
    42  	return root
    43  }
    44  
    45  // TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName
    46  // It utilizes the policyName for the subPolicyName as well, as this is the standard usage pattern
    47  func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
    48  	return TemplateImplicitMetaPolicyWithSubPolicy(path, policyName, policyName, rule)
    49  }
    50  
    51  // TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_ANY as the rule
    52  func TemplateImplicitMetaAnyPolicy(path []string, policyName string) *cb.ConfigGroup {
    53  	return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ANY)
    54  }
    55  
    56  // TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_ALL as the rule
    57  func TemplateImplicitMetaAllPolicy(path []string, policyName string) *cb.ConfigGroup {
    58  	return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ALL)
    59  }
    60  
    61  // TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_MAJORITY as the rule
    62  func TemplateImplicitMetaMajorityPolicy(path []string, policyName string) *cb.ConfigGroup {
    63  	return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_MAJORITY)
    64  }