github.com/ewagmig/fabric@v2.1.1+incompatible/common/channelconfig/applicationorg.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  	"fmt"
    11  
    12  	cb "github.com/hyperledger/fabric-protos-go/common"
    13  	pb "github.com/hyperledger/fabric-protos-go/peer"
    14  	"github.com/pkg/errors"
    15  )
    16  
    17  const (
    18  	// AnchorPeersKey is the key name for the AnchorPeers ConfigValue
    19  	AnchorPeersKey = "AnchorPeers"
    20  )
    21  
    22  // ApplicationOrgProtos are deserialized from the config
    23  type ApplicationOrgProtos struct {
    24  	AnchorPeers *pb.AnchorPeers
    25  }
    26  
    27  // ApplicationOrgConfig defines the configuration for an application org
    28  type ApplicationOrgConfig struct {
    29  	*OrganizationConfig
    30  	protos *ApplicationOrgProtos
    31  	name   string
    32  }
    33  
    34  // NewApplicationOrgConfig creates a new config for an application org
    35  func NewApplicationOrgConfig(id string, orgGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ApplicationOrgConfig, error) {
    36  	if len(orgGroup.Groups) > 0 {
    37  		return nil, fmt.Errorf("ApplicationOrg config does not allow sub-groups")
    38  	}
    39  
    40  	protos := &ApplicationOrgProtos{}
    41  	orgProtos := &OrganizationProtos{}
    42  
    43  	if err := DeserializeProtoValuesFromGroup(orgGroup, protos, orgProtos); err != nil {
    44  		return nil, errors.Wrap(err, "failed to deserialize values")
    45  	}
    46  
    47  	aoc := &ApplicationOrgConfig{
    48  		name:   id,
    49  		protos: protos,
    50  		OrganizationConfig: &OrganizationConfig{
    51  			name:             id,
    52  			protos:           orgProtos,
    53  			mspConfigHandler: mspConfig,
    54  		},
    55  	}
    56  
    57  	if err := aoc.Validate(); err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	return aoc, nil
    62  }
    63  
    64  // AnchorPeers returns the list of anchor peers of this Organization
    65  func (aog *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
    66  	return aog.protos.AnchorPeers.AnchorPeers
    67  }
    68  
    69  func (aoc *ApplicationOrgConfig) Validate() error {
    70  	logger.Debugf("Anchor peers for org %s are %v", aoc.name, aoc.protos.AnchorPeers)
    71  	return aoc.OrganizationConfig.Validate()
    72  }