Skip to content

Commit

Permalink
Fix duplicate AddOrgToConsortium
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Cao <dcao@us.ibm.com>
  • Loading branch information
caod123 authored and sykesm committed Feb 28, 2020
1 parent 8c1a290 commit b78d79b
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 238 deletions.
47 changes: 0 additions & 47 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,53 +179,6 @@ func CreateSignedConfigUpdateEnvelope(configUpdate *cb.ConfigUpdate, signingIden
return signedEnvelope, nil
}

// AddOrgToConsortium adds an org definition to a named consortium in a given
// channel configuration.
func AddOrgToConsortium(
org *Organization,
consortium, channelID string,
config *cb.Config,
mspConfig *mb.MSPConfig,
) (*cb.ConfigUpdate, error) {
if org == nil {
return nil, errors.New("organization is empty")
}

if consortium == "" {
return nil, errors.New("consortium is empty")
}

updatedConfig := proto.Clone(config).(*cb.Config)

consortiumsGroup, ok := updatedConfig.ChannelGroup.Groups[ConsortiumsGroupKey]
if !ok {
return nil, errors.New("consortiums group does not exist")
}

consortiumGroup, ok := consortiumsGroup.Groups[consortium]
if !ok {
return nil, fmt.Errorf("consortium '%s' does not exist", consortium)
}

orgGroup, err := newOrgConfigGroup(org, mspConfig)
if err != nil {
return nil, fmt.Errorf("failed to create consortium org: %v", err)
}

if consortiumGroup.Groups == nil {
consortiumGroup.Groups = map[string]*cb.ConfigGroup{}
}

consortiumGroup.Groups[org.Name] = orgGroup

configUpdate, err := ComputeUpdate(config, updatedConfig, channelID)
if err != nil {
return nil, err
}

return configUpdate, nil
}

func signatureHeader(signingIdentity *SigningIdentity) (*cb.SignatureHeader, error) {
buffer := bytes.NewBuffer(nil)

Expand Down
61 changes: 28 additions & 33 deletions pkg/config/consortiums.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,6 @@ type Consortium struct {
Organizations []*Organization
}

// AddOrgToConsortium adds an org definition to a named consortium in a given
// channel configuration.
func AddOrgToConsortium(config *cb.Config, org *Organization, consortium string, mspConfig *mb.MSPConfig) error {
if org == nil {
return errors.New("organization is required")
}
if consortium == "" {
return errors.New("consortium is required")
}

consortiumsGroup, ok := config.ChannelGroup.Groups[ConsortiumsGroupKey]
if !ok {
return errors.New("consortiums group does not exist")
}

consortiumGroup, ok := consortiumsGroup.Groups[consortium]
if !ok {
return fmt.Errorf("consortium '%s' does not exist", consortium)
}

orgGroup, err := newConsortiumOrgGroup(org, mspConfig)
if err != nil {
return fmt.Errorf("failed to create consortium org: %v", err)
}

if consortiumGroup.Groups == nil {
consortiumGroup.Groups = map[string]*cb.ConfigGroup{}
}
consortiumGroup.Groups[org.Name] = orgGroup

return nil
}

// NewConsortiumsGroup returns the consortiums component of the channel configuration. This element is only defined for
// the ordering system channel.
// It sets the mod_policy for all elements to "/Channel/Orderer/Admins".
Expand Down Expand Up @@ -86,6 +53,34 @@ func NewConsortiumsGroup(consortiums []*Consortium, mspConfig *mb.MSPConfig) (*c
return consortiumsGroup, nil
}

// AddOrgToConsortium adds an org definition to a named consortium in a given
// channel configuration.
func AddOrgToConsortium(config *cb.Config, org *Organization, consortium string, mspConfig *mb.MSPConfig) error {
var err error

if org == nil {
return errors.New("organization is required")
}

if consortium == "" {
return errors.New("consortium is required")
}

consortiumsGroup := config.ChannelGroup.Groups[ConsortiumsGroupKey]

consortiumGroup, ok := consortiumsGroup.Groups[consortium]
if !ok {
return fmt.Errorf("consortium '%s' does not exist", consortium)
}

consortiumGroup.Groups[org.Name], err = newOrgConfigGroup(org, mspConfig)
if err != nil {
return fmt.Errorf("failed to create consortium org: %v", err)
}

return nil
}

// newConsortiumGroup returns a consortiums component of the channel configuration.
func newConsortiumGroup(consortium *Consortium, mspConfig *mb.MSPConfig) (*cb.ConfigGroup, error) {
var err error
Expand Down
Loading

0 comments on commit b78d79b

Please sign in to comment.