github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/protos/peer/configuration.go (about) 1 /* 2 Copyright IBM Corp. 2017 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 peer 18 19 import ( 20 "fmt" 21 22 "github.com/hyperledger/fabric/protos/common" 23 "github.com/hyperledger/fabric/protos/msp" 24 25 "github.com/golang/protobuf/proto" 26 ) 27 28 func init() { 29 common.ChannelGroupMap["Application"] = DynamicApplicationGroupFactory{} 30 } 31 32 type DynamicApplicationGroupFactory struct{} 33 34 func (dagf DynamicApplicationGroupFactory) DynamicConfigGroup(cg *common.ConfigGroup) proto.Message { 35 return &DynamicApplicationGroup{ 36 ConfigGroup: cg, 37 } 38 } 39 40 type DynamicApplicationGroup struct { 41 *common.ConfigGroup 42 } 43 44 func (dag *DynamicApplicationGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) { 45 switch name { 46 case "groups": 47 cg, ok := base.(*common.ConfigGroup) 48 if !ok { 49 return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages") 50 } 51 52 return &DynamicApplicationOrgGroup{ 53 ConfigGroup: cg, 54 }, nil 55 case "values": 56 cv, ok := base.(*common.ConfigValue) 57 if !ok { 58 return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages") 59 } 60 return &DynamicApplicationConfigValue{ 61 ConfigValue: cv, 62 name: key, 63 }, nil 64 default: 65 return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name) 66 } 67 } 68 69 type DynamicApplicationOrgGroup struct { 70 *common.ConfigGroup 71 } 72 73 func (dag *DynamicApplicationOrgGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) { 74 switch name { 75 case "groups": 76 return nil, fmt.Errorf("The application orgs do not support sub-groups") 77 case "values": 78 cv, ok := base.(*common.ConfigValue) 79 if !ok { 80 return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages") 81 } 82 83 return &DynamicApplicationOrgConfigValue{ 84 ConfigValue: cv, 85 name: key, 86 }, nil 87 default: 88 return nil, fmt.Errorf("Not a dynamic application map field: %s", name) 89 } 90 } 91 92 type DynamicApplicationConfigValue struct { 93 *common.ConfigValue 94 name string 95 } 96 97 func (ccv *DynamicApplicationConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) { 98 if name != ccv.VariablyOpaqueFields()[0] { 99 return nil, fmt.Errorf("Not a marshaled field: %s", name) 100 } 101 switch ccv.name { 102 default: 103 return nil, fmt.Errorf("Unknown Application ConfigValue name: %s", ccv.name) 104 } 105 } 106 107 type DynamicApplicationOrgConfigValue struct { 108 *common.ConfigValue 109 name string 110 } 111 112 func (daocv *DynamicApplicationOrgConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) { 113 if name != daocv.VariablyOpaqueFields()[0] { 114 return nil, fmt.Errorf("Not a marshaled field: %s", name) 115 } 116 switch daocv.name { 117 case "MSP": 118 return &msp.MSPConfig{}, nil 119 case "AnchorPeers": 120 return &AnchorPeers{}, nil 121 default: 122 return nil, fmt.Errorf("Unknown Application Org ConfigValue name: %s", daocv.name) 123 } 124 }