github.com/ewagmig/fabric@v2.1.1+incompatible/common/policies/implicitmetaparser.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package policies 8 9 import ( 10 "strings" 11 12 cb "github.com/hyperledger/fabric-protos-go/common" 13 "github.com/pkg/errors" 14 ) 15 16 func ImplicitMetaFromString(input string) (*cb.ImplicitMetaPolicy, error) { 17 args := strings.Split(input, " ") 18 if len(args) != 2 { 19 return nil, errors.Errorf("expected two space separated tokens, but got %d", len(args)) 20 } 21 22 res := &cb.ImplicitMetaPolicy{ 23 SubPolicy: args[1], 24 } 25 26 switch args[0] { 27 case cb.ImplicitMetaPolicy_ANY.String(): 28 res.Rule = cb.ImplicitMetaPolicy_ANY 29 case cb.ImplicitMetaPolicy_ALL.String(): 30 res.Rule = cb.ImplicitMetaPolicy_ALL 31 case cb.ImplicitMetaPolicy_MAJORITY.String(): 32 res.Rule = cb.ImplicitMetaPolicy_MAJORITY 33 default: 34 return nil, errors.Errorf("unknown rule type '%s', expected ALL, ANY, or MAJORITY", args[0]) 35 } 36 37 return res, nil 38 }