github.com/ewagmig/fabric@v2.1.1+incompatible/common/channelconfig/consortium.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package channelconfig 8 9 import ( 10 cb "github.com/hyperledger/fabric-protos-go/common" 11 "github.com/pkg/errors" 12 ) 13 14 const ( 15 // ChannelCreationPolicyKey is the key used in the consortium config to denote the policy 16 // to be used in evaluating whether a channel creation request is authorized 17 ChannelCreationPolicyKey = "ChannelCreationPolicy" 18 ) 19 20 // ConsortiumProtos holds the config protos for the consortium config 21 type ConsortiumProtos struct { 22 ChannelCreationPolicy *cb.Policy 23 } 24 25 // ConsortiumConfig holds the consortium's configuration information 26 type ConsortiumConfig struct { 27 protos *ConsortiumProtos 28 orgs map[string]Org 29 } 30 31 // NewConsortiumConfig creates a new instance of the consortium's config 32 func NewConsortiumConfig(consortiumGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ConsortiumConfig, error) { 33 cc := &ConsortiumConfig{ 34 protos: &ConsortiumProtos{}, 35 orgs: make(map[string]Org), 36 } 37 38 if err := DeserializeProtoValuesFromGroup(consortiumGroup, cc.protos); err != nil { 39 return nil, errors.Wrap(err, "failed to deserialize values") 40 } 41 42 for orgName, orgGroup := range consortiumGroup.Groups { 43 var err error 44 if cc.orgs[orgName], err = NewOrganizationConfig(orgName, orgGroup, mspConfig); err != nil { 45 return nil, err 46 } 47 } 48 49 return cc, nil 50 } 51 52 // Organizations returns the set of organizations in the consortium 53 func (cc *ConsortiumConfig) Organizations() map[string]Org { 54 return cc.orgs 55 } 56 57 // CreationPolicy returns the policy structure used to validate 58 // the channel creation 59 func (cc *ConsortiumConfig) ChannelCreationPolicy() *cb.Policy { 60 return cc.protos.ChannelCreationPolicy 61 }