From 63b156dcf051f885f25940b780db91f90b90e90e Mon Sep 17 00:00:00 2001 From: Will Lahti Date: Mon, 4 May 2020 15:09:48 -0400 Subject: [PATCH] Refactor API chaining to remove UpdatedConfig and related types FAB-17744 Signed-off-by: Will Lahti --- configtx/application.go | 174 +++++++++++----------------------- configtx/application_test.go | 60 ++++++------ configtx/capabilities_test.go | 58 ++++++------ configtx/channel.go | 84 +++++----------- configtx/config.go | 35 ++----- configtx/config_test.go | 10 +- configtx/consortiums.go | 130 +++++++------------------ configtx/consortiums_test.go | 18 ++-- configtx/example_test.go | 73 ++++++++------ configtx/msp_test.go | 62 ++++++------ configtx/orderer.go | 166 ++++++++++---------------------- configtx/orderer_test.go | 24 ++--- configtx/organization_test.go | 16 ++-- configtx/policies_test.go | 75 ++++++++------- 14 files changed, 372 insertions(+), 613 deletions(-) diff --git a/configtx/application.go b/configtx/application.go index cf6cb81..8c2074c 100644 --- a/configtx/application.go +++ b/configtx/application.go @@ -27,18 +27,11 @@ type Application struct { } // ApplicationGroup encapsulates the part of the config that controls -// application channels. This type implements retrieval of the various -// application config values. +// application channels. type ApplicationGroup struct { applicationGroup *cb.ConfigGroup } -// UpdatedApplicationGroup is an ApplicationGroup that can be modified in -// order to generate a config update. -type UpdatedApplicationGroup struct { - *ApplicationGroup -} - // ApplicationOrg encapsulates the parts of the config that control // an application organization's configuration. type ApplicationOrg struct { @@ -46,26 +39,13 @@ type ApplicationOrg struct { name string } -// UpdatedApplicationOrg is an ApplicationOrg that can be modified in order -// to generate a config update. -type UpdatedApplicationOrg struct { - *ApplicationOrg - name string -} - -// Application returns the application group the original config. -func (o *OriginalConfig) Application() *ApplicationGroup { - applicationGroup := o.ChannelGroup.Groups[ApplicationGroupKey] - return &ApplicationGroup{applicationGroup: applicationGroup} -} - // Application returns the application group the updated config. -func (u *UpdatedConfig) Application() *UpdatedApplicationGroup { - applicationGroup := u.ChannelGroup.Groups[ApplicationGroupKey] - return &UpdatedApplicationGroup{ApplicationGroup: &ApplicationGroup{applicationGroup: applicationGroup}} +func (c *ConfigTx) Application() *ApplicationGroup { + applicationGroup := c.updated.ChannelGroup.Groups[ApplicationGroupKey] + return &ApplicationGroup{applicationGroup: applicationGroup} } -// Organization returns the application org from the original config. +// Organization returns the application org from the updated config. func (a *ApplicationGroup) Organization(name string) *ApplicationOrg { organizationGroup, ok := a.applicationGroup.Groups[name] if !ok { @@ -74,29 +54,24 @@ func (a *ApplicationGroup) Organization(name string) *ApplicationOrg { return &ApplicationOrg{name: name, orgGroup: organizationGroup} } -// Organization returns the application org from the updated config. -func (u *UpdatedApplicationGroup) Organization(name string) *UpdatedApplicationOrg { - return &UpdatedApplicationOrg{ApplicationOrg: u.ApplicationGroup.Organization(name)} -} - // SetOrganization sets the organization config group for the given application // org key in an existing Application configuration's Groups map. // If the application org already exists in the current configuration, its value will be overwritten. -func (u *UpdatedApplicationGroup) SetOrganization(org Organization) error { +func (a *ApplicationGroup) SetOrganization(org Organization) error { orgGroup, err := newApplicationOrgConfigGroup(org) if err != nil { return fmt.Errorf("failed to create application org %s: %v", org.Name, err) } - u.applicationGroup.Groups[org.Name] = orgGroup + a.applicationGroup.Groups[org.Name] = orgGroup return nil } // RemoveOrganization removes an org from the Application group. // Removal will panic if the application group does not exist. -func (u *UpdatedApplicationGroup) RemoveOrganization(orgName string) { - delete(u.applicationGroup.Groups, orgName) +func (a *ApplicationGroup) RemoveOrganization(orgName string) { + delete(a.applicationGroup.Groups, orgName) } // Configuration returns the existing application configuration values from a config @@ -138,7 +113,7 @@ func (a *ApplicationGroup) Configuration() (Application, error) { } // Configuration returns the existing application org configuration values -// from the original config. +// from the updated config. func (a *ApplicationOrg) Configuration() (Organization, error) { org, err := getOrganization(a.orgGroup, a.name) if err != nil { @@ -147,14 +122,8 @@ func (a *ApplicationOrg) Configuration() (Organization, error) { return org, nil } -// Configuration returns the existing application org configuration values -// from the updated config. -func (u *UpdatedApplicationOrg) Configuration() (Organization, error) { - return u.ApplicationOrg.Configuration() -} - // Capabilities returns a map of enabled application capabilities -// from the original config. +// from the updated config. func (a *ApplicationGroup) Capabilities() ([]string, error) { capabilities, err := getCapabilities(a.applicationGroup) if err != nil { @@ -164,22 +133,16 @@ func (a *ApplicationGroup) Capabilities() ([]string, error) { return capabilities, nil } -// Capabilities returns a map of enabled application capabilities -// from the updated config. -func (u *UpdatedApplicationGroup) Capabilities() ([]string, error) { - return u.ApplicationGroup.Capabilities() -} - // AddCapability sets capability to the provided channel config. // If the provided capability already exist in current configuration, this action // will be a no-op. -func (u *UpdatedApplicationGroup) AddCapability(capability string) error { - capabilities, err := u.Capabilities() +func (a *ApplicationGroup) AddCapability(capability string) error { + capabilities, err := a.Capabilities() if err != nil { return err } - err = addCapability(u.applicationGroup, capabilities, AdminsPolicyKey, capability) + err = addCapability(a.applicationGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } @@ -188,13 +151,13 @@ func (u *UpdatedApplicationGroup) AddCapability(capability string) error { } // RemoveCapability removes capability to the provided channel config. -func (u *UpdatedApplicationGroup) RemoveCapability(capability string) error { - capabilities, err := u.Capabilities() +func (a *ApplicationGroup) RemoveCapability(capability string) error { + capabilities, err := a.Capabilities() if err != nil { return err } - err = removeCapability(u.applicationGroup, capabilities, AdminsPolicyKey, capability) + err = removeCapability(a.applicationGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } @@ -203,21 +166,15 @@ func (u *UpdatedApplicationGroup) RemoveCapability(capability string) error { } // Policies returns a map of policies for the application config group in -// the original config. +// the updatedconfig. func (a *ApplicationGroup) Policies() (map[string]Policy, error) { return getPolicies(a.applicationGroup.Policies) } -// Policies returns a map of policies for the application config group in -// the updated config. -func (u *UpdatedApplicationGroup) Policies() (map[string]Policy, error) { - return u.ApplicationGroup.Policies() -} - // SetPolicy sets the specified policy in the application group's config policy map. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedApplicationGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { - err := setPolicy(u.applicationGroup, modPolicy, policyName, policy) +func (a *ApplicationGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { + err := setPolicy(a.applicationGroup, modPolicy, policyName, policy) if err != nil { return fmt.Errorf("failed to set policy '%s': %v", policyName, err) } @@ -227,32 +184,26 @@ func (u *UpdatedApplicationGroup) SetPolicy(modPolicy, policyName string, policy // RemovePolicy removes an existing policy from an application's configuration. // Removal will panic if the application group does not exist. -func (u *UpdatedApplicationGroup) RemovePolicy(policyName string) error { - policies, err := u.Policies() +func (a *ApplicationGroup) RemovePolicy(policyName string) error { + policies, err := a.Policies() if err != nil { return err } - removePolicy(u.applicationGroup, policyName, policies) + removePolicy(a.applicationGroup, policyName, policies) return nil } // Policies returns the map of policies for a specific application org in -// the original config.. +// the updated config.. func (a *ApplicationOrg) Policies() (map[string]Policy, error) { return getPolicies(a.orgGroup.Policies) } -// Policies returns the map of policies for a specific application org in -// the updated config.. -func (u *UpdatedApplicationOrg) Policies() (map[string]Policy, error) { - return u.ApplicationOrg.Policies() -} - // SetPolicy sets the specified policy in the application org group's config policy map. // If an Organization policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedApplicationOrg) SetPolicy(modPolicy, policyName string, policy Policy) error { - err := setPolicy(u.orgGroup, modPolicy, policyName, policy) +func (a *ApplicationOrg) SetPolicy(modPolicy, policyName string, policy Policy) error { + err := setPolicy(a.orgGroup, modPolicy, policyName, policy) if err != nil { return fmt.Errorf("failed to set policy '%s': %v", policyName, err) } @@ -261,18 +212,18 @@ func (u *UpdatedApplicationOrg) SetPolicy(modPolicy, policyName string, policy P } // RemovePolicy removes an existing policy from an application organization. -func (u *UpdatedApplicationOrg) RemovePolicy(policyName string) error { - policies, err := u.Policies() +func (a *ApplicationOrg) RemovePolicy(policyName string) error { + policies, err := a.Policies() if err != nil { return err } - removePolicy(u.orgGroup, policyName, policies) + removePolicy(a.orgGroup, policyName, policies) return nil } // AnchorPeers returns the list of anchor peers for an application org -// in the original config. +// in the updated config. func (a *ApplicationOrg) AnchorPeers() ([]Address, error) { anchorPeerConfigValue, ok := a.orgGroup.Values[AnchorPeersKey] if !ok { @@ -301,18 +252,12 @@ func (a *ApplicationOrg) AnchorPeers() ([]Address, error) { return anchorPeers, nil } -// AnchorPeers returns the list of anchor peers for an application org -// in the updatd config. -func (u *UpdatedApplicationOrg) AnchorPeers() ([]Address, error) { - return u.ApplicationOrg.AnchorPeers() -} - // AddAnchorPeer adds an anchor peer to an application org's configuration // in the updated config. -func (u *UpdatedApplicationOrg) AddAnchorPeer(newAnchorPeer Address) error { +func (a *ApplicationOrg) AddAnchorPeer(newAnchorPeer Address) error { anchorPeersProto := &pb.AnchorPeers{} - if anchorPeerConfigValue, ok := u.ApplicationOrg.orgGroup.Values[AnchorPeersKey]; ok { + if anchorPeerConfigValue, ok := a.orgGroup.Values[AnchorPeersKey]; ok { // Unmarshal existing anchor peers if the config value exists err := proto.Unmarshal(anchorPeerConfigValue.Value, anchorPeersProto) if err != nil { @@ -336,7 +281,7 @@ func (u *UpdatedApplicationOrg) AddAnchorPeer(newAnchorPeer Address) error { }) // Add anchor peers config value back to application org - err := setValue(u.orgGroup, anchorPeersValue(anchorProtos), AdminsPolicyKey) + err := setValue(a.orgGroup, anchorPeersValue(anchorProtos), AdminsPolicyKey) if err != nil { return err } @@ -345,14 +290,14 @@ func (u *UpdatedApplicationOrg) AddAnchorPeer(newAnchorPeer Address) error { // RemoveAnchorPeer removes an anchor peer from an application org's configuration // in the updated config. -func (u *UpdatedApplicationOrg) RemoveAnchorPeer(anchorPeerToRemove Address) error { +func (a *ApplicationOrg) RemoveAnchorPeer(anchorPeerToRemove Address) error { anchorPeersProto := &pb.AnchorPeers{} - if anchorPeerConfigValue, ok := u.ApplicationOrg.orgGroup.Values[AnchorPeersKey]; ok { + if anchorPeerConfigValue, ok := a.orgGroup.Values[AnchorPeersKey]; ok { // Unmarshal existing anchor peers if the config value exists err := proto.Unmarshal(anchorPeerConfigValue.Value, anchorPeersProto) if err != nil { - return fmt.Errorf("failed unmarshaling anchor peer endpoints for application org %s: %v", u.ApplicationOrg.name, err) + return fmt.Errorf("failed unmarshaling anchor peer endpoints for application org %s: %v", a.name, err) } } @@ -362,9 +307,9 @@ func (u *UpdatedApplicationOrg) RemoveAnchorPeer(anchorPeerToRemove Address) err existingAnchorPeers = append(existingAnchorPeers, anchorPeer) // Add anchor peers config value back to application org - err := setValue(u.orgGroup, anchorPeersValue(existingAnchorPeers), AdminsPolicyKey) + err := setValue(a.orgGroup, anchorPeersValue(existingAnchorPeers), AdminsPolicyKey) if err != nil { - return fmt.Errorf("failed to remove anchor peer %v from org %s: %v", anchorPeerToRemove, u.ApplicationOrg.name, err) + return fmt.Errorf("failed to remove anchor peer %v from org %s: %v", anchorPeerToRemove, a.name, err) } return nil @@ -372,13 +317,13 @@ func (u *UpdatedApplicationOrg) RemoveAnchorPeer(anchorPeerToRemove Address) err } if len(existingAnchorPeers) == len(anchorPeersProto.AnchorPeers) { - return fmt.Errorf("could not find anchor peer %s:%d in application org %s", anchorPeerToRemove.Host, anchorPeerToRemove.Port, u.name) + return fmt.Errorf("could not find anchor peer %s:%d in application org %s", anchorPeerToRemove.Host, anchorPeerToRemove.Port, a.name) } // Add anchor peers config value back to application org - err := setValue(u.orgGroup, anchorPeersValue(existingAnchorPeers), AdminsPolicyKey) + err := setValue(a.orgGroup, anchorPeersValue(existingAnchorPeers), AdminsPolicyKey) if err != nil { - return fmt.Errorf("failed to remove anchor peer %v from org %s: %v", anchorPeerToRemove, u.name, err) + return fmt.Errorf("failed to remove anchor peer %v from org %s: %v", anchorPeerToRemove, a.name, err) } return nil @@ -401,15 +346,10 @@ func (a *ApplicationGroup) ACLs() (map[string]string, error) { return retACLs, nil } -// ACLs returns a map of ACLS for given config application. -func (u *UpdatedApplicationGroup) ACLs() (map[string]string, error) { - return u.ApplicationGroup.ACLs() -} - // SetACLs sets ACLS to an existing channel config application. // If an ACL already exist in current configuration, it will be replaced with new ACL. -func (u *UpdatedApplicationGroup) SetACLs(acls map[string]string) error { - err := setValue(u.applicationGroup, aclValues(acls), AdminsPolicyKey) +func (a *ApplicationGroup) SetACLs(acls map[string]string) error { + err := setValue(a.applicationGroup, aclValues(acls), AdminsPolicyKey) if err != nil { return err } @@ -420,8 +360,8 @@ func (u *UpdatedApplicationGroup) SetACLs(acls map[string]string) error { // RemoveACLs a list of ACLs from given channel config application. // Specifying acls that do not exist in the application ConfigGroup of the channel config will not return a error. // Removal will panic if application group does not exist. -func (u *UpdatedApplicationGroup) RemoveACLs(acls []string) error { - configACLs, err := u.ACLs() +func (a *ApplicationGroup) RemoveACLs(acls []string) error { + configACLs, err := a.ACLs() if err != nil { return err } @@ -430,7 +370,7 @@ func (u *UpdatedApplicationGroup) RemoveACLs(acls []string) error { delete(configACLs, acl) } - err = setValue(u.applicationGroup, aclValues(configACLs), AdminsPolicyKey) + err = setValue(a.applicationGroup, aclValues(configACLs), AdminsPolicyKey) if err != nil { return err } @@ -439,21 +379,15 @@ func (u *UpdatedApplicationGroup) RemoveACLs(acls []string) error { } // MSP returns the MSP configuration for an existing application -// org in the original config of a config transaction. +// org in the updated config of a config transaction. func (a *ApplicationOrg) MSP() (MSP, error) { return getMSPConfig(a.orgGroup) } -// MSP returns the MSP configuration for an existing application -// org in the updated config of a config transaction. -func (u *UpdatedApplicationOrg) MSP() (MSP, error) { - return getMSPConfig(u.orgGroup) -} - // SetMSP updates the MSP config for the specified application // org group. -func (u *UpdatedApplicationOrg) SetMSP(updatedMSP MSP) error { - currentMSP, err := u.MSP() +func (a *ApplicationOrg) SetMSP(updatedMSP MSP) error { + currentMSP, err := a.MSP() if err != nil { return fmt.Errorf("retrieving msp: %v", err) } @@ -467,7 +401,7 @@ func (u *UpdatedApplicationOrg) SetMSP(updatedMSP MSP) error { return err } - err = u.setMSPConfig(updatedMSP) + err = a.setMSPConfig(updatedMSP) if err != nil { return err } @@ -475,13 +409,13 @@ func (u *UpdatedApplicationOrg) SetMSP(updatedMSP MSP) error { return nil } -func (u *UpdatedApplicationOrg) setMSPConfig(updatedMSP MSP) error { +func (a *ApplicationOrg) setMSPConfig(updatedMSP MSP) error { mspConfig, err := newMSPConfig(updatedMSP) if err != nil { return fmt.Errorf("new msp config: %v", err) } - err = setValue(u.ApplicationOrg.orgGroup, mspValue(mspConfig), AdminsPolicyKey) + err = setValue(a.orgGroup, mspValue(mspConfig), AdminsPolicyKey) if err != nil { return err } @@ -491,8 +425,8 @@ func (u *UpdatedApplicationOrg) setMSPConfig(updatedMSP MSP) error { // CreateMSPCRL creates a CRL that revokes the provided certificates // for the specified application org signed by the provided SigningIdentity. -func (u *UpdatedApplicationOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { - msp, err := u.MSP() +func (a *ApplicationOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { + msp, err := a.MSP() if err != nil { return nil, fmt.Errorf("retrieving application org msp: %s", err) } diff --git a/configtx/application_test.go b/configtx/application_test.go index d66cc9f..13b56fc 100644 --- a/configtx/application_test.go +++ b/configtx/application_test.go @@ -356,13 +356,13 @@ func TestAddAnchorPeer(t *testing.T) { err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedUpdatedConfigJSON), expectedUpdatedConfig) gt.Expect(err).ToNot(HaveOccurred()) - err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(newOrg1AnchorPeer) + err = c.Application().Organization("Org1").AddAnchorPeer(newOrg1AnchorPeer) gt.Expect(err).NotTo(HaveOccurred()) - err = c.UpdatedConfig().Application().Organization("Org2").AddAnchorPeer(newOrg2AnchorPeer) + err = c.Application().Organization("Org2").AddAnchorPeer(newOrg2AnchorPeer) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue()) } func TestRemoveAnchorPeer(t *testing.T) { @@ -485,17 +485,18 @@ func TestRemoveAnchorPeer(t *testing.T) { ` anchorPeer1 := Address{Host: "host1", Port: 123} - err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(anchorPeer1) + applicationOrg1 := c.Application().Organization("Org1") + err = applicationOrg1.AddAnchorPeer(anchorPeer1) gt.Expect(err).NotTo(HaveOccurred()) expectedUpdatedConfig := &cb.Config{} err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedUpdatedConfigJSON), expectedUpdatedConfig) gt.Expect(err).NotTo(HaveOccurred()) - err = c.UpdatedConfig().Application().Organization("Org1").RemoveAnchorPeer(anchorPeer1) + err = applicationOrg1.RemoveAnchorPeer(anchorPeer1) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue()) } func TestRemoveAnchorPeerFailure(t *testing.T) { @@ -541,7 +542,7 @@ func TestRemoveAnchorPeerFailure(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().Organization(tt.orgName).RemoveAnchorPeer(tt.anchorPeerToRemove) + err = c.Application().Organization(tt.orgName).RemoveAnchorPeer(tt.anchorPeerToRemove) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -565,24 +566,24 @@ func TestAnchorPeers(t *testing.T) { c := New(config) - anchorPeers, err := c.UpdatedConfig().Application().Organization("Org1").AnchorPeers() + anchorPeers, err := c.Application().Organization("Org1").AnchorPeers() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(anchorPeers).To(BeNil()) gt.Expect(anchorPeers).To(HaveLen(0)) expectedAnchorPeer := Address{Host: "host1", Port: 123} - err = c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(expectedAnchorPeer) + err = c.Application().Organization("Org1").AddAnchorPeer(expectedAnchorPeer) gt.Expect(err).NotTo(HaveOccurred()) - anchorPeers, err = c.UpdatedConfig().Application().Organization("Org1").AnchorPeers() + anchorPeers, err = c.Application().Organization("Org1").AnchorPeers() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(anchorPeers).To(HaveLen(1)) gt.Expect(anchorPeers[0]).To(Equal(expectedAnchorPeer)) - err = c.UpdatedConfig().Application().Organization("Org1").RemoveAnchorPeer(expectedAnchorPeer) + err = c.Application().Organization("Org1").RemoveAnchorPeer(expectedAnchorPeer) gt.Expect(err).NotTo(HaveOccurred()) - anchorPeers, err = c.UpdatedConfig().Application().Organization("Org1").AnchorPeers() + anchorPeers, err = c.Application().Organization("Org1").AnchorPeers() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(anchorPeers).To(BeNil()) gt.Expect(anchorPeers).To(HaveLen(0)) @@ -630,24 +631,19 @@ func TestSetACL(t *testing.T) { config := &cb.Config{ ChannelGroup: channelGroup, } - expectedOriginalACL := map[string]string{"acl1": "hi"} if tt.configMod != nil { tt.configMod(config) } c := New(config) - err = c.UpdatedConfig().Application().SetACLs(tt.newACL) + err = c.Application().SetACLs(tt.newACL) if tt.expectedErr != "" { gt.Expect(err).To(MatchError(tt.expectedErr)) } else { gt.Expect(err).NotTo(HaveOccurred()) - acls, err := c.UpdatedConfig().Application().ACLs() + acls, err := c.Application().ACLs() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(acls).To(Equal(tt.expectedACL)) - - originalACLs, err := c.OriginalConfig().Application().ACLs() - gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(originalACLs).To(Equal(expectedOriginalACL)) } }) } @@ -705,12 +701,12 @@ func TestRemoveACL(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().RemoveACLs(tt.removeACL) + err = c.Application().RemoveACLs(tt.removeACL) if tt.expectedErr != "" { gt.Expect(err).To(MatchError(tt.expectedErr)) } else { gt.Expect(err).NotTo(HaveOccurred()) - acls, err := c.UpdatedConfig().Application().ACLs() + acls, err := c.Application().ACLs() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(acls).To(Equal(tt.expectedACL)) } @@ -888,10 +884,10 @@ func TestSetApplicationOrg(t *testing.T) { } `, certBase64, crlBase64) - err = c.UpdatedConfig().Application().SetOrganization(org) + err = c.Application().SetOrganization(org) gt.Expect(err).NotTo(HaveOccurred()) - actualApplicationConfigGroup := c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Groups["Org3"] + actualApplicationConfigGroup := c.Application().Organization("Org3").orgGroup buf := bytes.Buffer{} err = protolator.DeepMarshalJSON(&buf, &peerext.DynamicApplicationOrgGroup{ConfigGroup: actualApplicationConfigGroup}) gt.Expect(err).NotTo(HaveOccurred()) @@ -921,7 +917,7 @@ func TestSetApplicationOrgFailures(t *testing.T) { Name: "Org3", } - err = c.UpdatedConfig().Application().SetOrganization(org) + err = c.Application().SetOrganization(org) gt.Expect(err).To(MatchError("failed to create application org Org3: no policies defined")) } @@ -944,13 +940,11 @@ func TestApplicationConfiguration(t *testing.T) { c := New(config) for _, org := range baseApplicationConf.Organizations { - err = c.UpdatedConfig().Application().SetOrganization(org) + err = c.Application().SetOrganization(org) gt.Expect(err).NotTo(HaveOccurred()) } - c = New(c.UpdatedConfig().Config) - - applicationConfig, err := c.OriginalConfig().Application().Configuration() + applicationConfig, err := c.Application().Configuration() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(applicationConfig.ACLs).To(Equal(baseApplicationConf.ACLs)) gt.Expect(applicationConfig.Capabilities).To(Equal(baseApplicationConf.Capabilities)) @@ -971,7 +965,7 @@ func TestApplicationConfigurationFailure(t *testing.T) { configMod: func(c ConfigTx, appOrg Application, gt *GomegaWithT) { for _, org := range appOrg.Organizations { if org.Name == "Org2" { - err := c.UpdatedConfig().Application().SetOrganization(org) + err := c.Application().SetOrganization(org) gt.Expect(err).NotTo(HaveOccurred()) } } @@ -1004,9 +998,9 @@ func TestApplicationConfigurationFailure(t *testing.T) { tt.configMod(c, baseApplicationConf, gt) } - c = New(c.UpdatedConfig().Config) + c = New(c.updated) - _, err = c.OriginalConfig().Application().Configuration() + _, err = c.Application().Configuration() gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -1031,7 +1025,7 @@ func TestApplicationACLs(t *testing.T) { c := New(config) - applicationACLs, err := c.UpdatedConfig().Application().ACLs() + applicationACLs, err := c.Application().ACLs() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(applicationACLs).To(Equal(baseApplicationConf.ACLs)) } @@ -1059,7 +1053,7 @@ func TestApplicationACLsFailure(t *testing.T) { c := New(config) - applicationACLs, err := c.UpdatedConfig().Application().ACLs() + applicationACLs, err := c.Application().ACLs() gt.Expect(err).To(MatchError("unmarshaling ACLs: unexpected EOF")) gt.Expect(applicationACLs).To(BeNil()) } diff --git a/configtx/capabilities_test.go b/configtx/capabilities_test.go index fd75f6c..e8a088c 100644 --- a/configtx/capabilities_test.go +++ b/configtx/capabilities_test.go @@ -32,18 +32,18 @@ func TestChannelCapabilities(t *testing.T) { }, } - c := New(config) - err := setValue(config.ChannelGroup, capabilitiesValue(expectedCapabilities), AdminsPolicyKey) gt.Expect(err).NotTo(HaveOccurred()) - channelCapabilities, err := c.OriginalConfig().Channel().Capabilities() + c := New(config) + + channelCapabilities, err := c.Channel().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(channelCapabilities).To(Equal(expectedCapabilities)) // Delete the capabilities key and assert retrieval to return nil - delete(config.ChannelGroup.Values, CapabilitiesKey) - channelCapabilities, err = c.OriginalConfig().Channel().Capabilities() + delete(c.Channel().channelGroup.Values, CapabilitiesKey) + channelCapabilities, err = c.Channel().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(channelCapabilities).To(BeNil()) } @@ -67,13 +67,13 @@ func TestOrdererCapabilities(t *testing.T) { c := New(config) - ordererCapabilities, err := c.OriginalConfig().Orderer().Capabilities() + ordererCapabilities, err := c.Orderer().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(ordererCapabilities).To(Equal(baseOrdererConf.Capabilities)) // Delete the capabilities key and assert retrieval to return nil - delete(c.OriginalConfig().Orderer().ordererGroup.Values, CapabilitiesKey) - ordererCapabilities, err = c.OriginalConfig().Orderer().Capabilities() + delete(c.Orderer().ordererGroup.Values, CapabilitiesKey) + ordererCapabilities, err = c.Orderer().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(ordererCapabilities).To(BeNil()) } @@ -97,13 +97,13 @@ func TestApplicationCapabilities(t *testing.T) { c := New(config) - applicationCapabilities, err := c.OriginalConfig().Application().Capabilities() + applicationCapabilities, err := c.Application().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(applicationCapabilities).To(Equal(baseApplicationConf.Capabilities)) // Delete the capabilities key and assert retrieval to return nil - delete(config.ChannelGroup.Groups[ApplicationGroupKey].Values, CapabilitiesKey) - applicationCapabilities, err = c.OriginalConfig().Application().Capabilities() + delete(c.Application().applicationGroup.Values, CapabilitiesKey) + applicationCapabilities, err = c.Application().Capabilities() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(applicationCapabilities).To(BeNil()) } @@ -142,11 +142,11 @@ func TestSetChannelCapability(t *testing.T) { } ` - err := c.UpdatedConfig().Channel().AddCapability("V3_0") + err := c.Channel().AddCapability("V3_0") gt.Expect(err).NotTo(HaveOccurred()) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup}) + err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.Channel().channelGroup}) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON)) @@ -186,7 +186,7 @@ func TestSetChannelCapabilityFailures(t *testing.T) { c := New(tt.config) - err := c.UpdatedConfig().Channel().AddCapability(tt.capability) + err := c.Channel().AddCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -431,11 +431,11 @@ func TestAddOrdererCapability(t *testing.T) { `, orgCertBase64, orgCRLBase64) capability := "V3_0" - err = c.UpdatedConfig().Orderer().AddCapability(capability) + err = c.Orderer().AddCapability(capability) gt.Expect(err).NotTo(HaveOccurred()) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.UpdatedConfig().Orderer().ordererGroup}) + err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.Orderer().ordererGroup}) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON)) @@ -486,7 +486,7 @@ func TestAddOrdererCapabilityFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Orderer().AddCapability(tt.capability) + err = c.Orderer().AddCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -690,14 +690,14 @@ func TestAddApplicationCapability(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().AddCapability(tt.capability) + err = c.Application().AddCapability(tt.capability) gt.Expect(err).NotTo(HaveOccurred()) updatedApplicationGroupJSON := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&updatedApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey]}) + err = protolator.DeepMarshalJSON(&updatedApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.Application().applicationGroup}) gt.Expect(err).NotTo(HaveOccurred()) originalApplicationGroupJSON := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&originalApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.OriginalConfig().ChannelGroup.Groups[ApplicationGroupKey]}) + err = protolator.DeepMarshalJSON(&originalApplicationGroupJSON, &peerext.DynamicApplicationGroup{ConfigGroup: c.original.ChannelGroup.Groups[ApplicationGroupKey]}) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedApplicationGroupJSON.String()).To(Equal(tt.expectedConfigGroupJSON)) @@ -755,7 +755,7 @@ func TestAddApplicationCapabilityFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().AddCapability(tt.capability) + err = c.Application().AddCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -798,11 +798,11 @@ func TestRemoveChannelCapability(t *testing.T) { } ` - err := c.UpdatedConfig().Channel().RemoveCapability("V3_0") + err := c.Channel().RemoveCapability("V3_0") gt.Expect(err).NotTo(HaveOccurred()) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.UpdatedConfig().ChannelGroup}) + err = protolator.DeepMarshalJSON(&buf, &commonext.DynamicChannelGroup{ConfigGroup: c.Channel().channelGroup}) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON)) @@ -856,7 +856,7 @@ func TestRemoveChannelCapabilityFailures(t *testing.T) { c := New(tt.config) - err := c.UpdatedConfig().Channel().RemoveCapability(tt.capability) + err := c.Channel().RemoveCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -1098,11 +1098,11 @@ func TestRemoveOrdererCapability(t *testing.T) { `, orgCertBase64, orgCRLBase64) capability := "V1_3" - err = c.UpdatedConfig().Orderer().RemoveCapability(capability) + err = c.Orderer().RemoveCapability(capability) gt.Expect(err).NotTo(HaveOccurred()) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.UpdatedConfig().Orderer().ordererGroup}) + err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererGroup{ConfigGroup: c.Orderer().ordererGroup}) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(Equal(expectedConfigGroupJSON)) @@ -1160,7 +1160,7 @@ func TestRemoveOrdererCapabilityFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Orderer().RemoveCapability(tt.capability) + err = c.Orderer().RemoveCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -1262,7 +1262,7 @@ func TestRemoveApplicationCapability(t *testing.T) { } ` capability := "V1_3" - err = c.UpdatedConfig().Application().RemoveCapability(capability) + err = c.Application().RemoveCapability(capability) gt.Expect(err).NotTo(HaveOccurred()) buf := bytes.Buffer{} @@ -1324,7 +1324,7 @@ func TestRemoveApplicationCapabilityFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().RemoveCapability(tt.capability) + err = c.Application().RemoveCapability(tt.capability) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } diff --git a/configtx/channel.go b/configtx/channel.go index 7c6c325..5d8a1f1 100644 --- a/configtx/channel.go +++ b/configtx/channel.go @@ -18,31 +18,16 @@ type ChannelGroup struct { channelGroup *cb.ConfigGroup } -// UpdatedChannelGroup is a ChannelGroup that can be modified in order to -// generate a config update. -type UpdatedChannelGroup struct { - *ChannelGroup -} - -// Channel returns the channel group from the original config. -func (o *OriginalConfig) Channel() *ChannelGroup { - return &ChannelGroup{channelGroup: o.ChannelGroup} -} - // Channel returns the channel group from the updated config. -func (u *UpdatedConfig) Channel() *UpdatedChannelGroup { - return &UpdatedChannelGroup{ChannelGroup: &ChannelGroup{channelGroup: u.ChannelGroup}} +func (c *ConfigTx) Channel() *ChannelGroup { + return &ChannelGroup{channelGroup: c.updated.ChannelGroup} } // Configuration returns a channel configuration value from a config transaction. func (c *ChannelGroup) Configuration() (Channel, error) { var ( - err error - consortium string - application Application - orderer Orderer - consortiums []Consortium - capabilities []string + config Channel + err error ) if _, ok := c.channelGroup.Values[ConsortiumKey]; ok { @@ -51,12 +36,12 @@ func (c *ChannelGroup) Configuration() (Channel, error) { if err != nil { return Channel{}, err } - consortium = consortiumProto.Name + config.Consortium = consortiumProto.Name } if applicationGroup, ok := c.channelGroup.Groups[ApplicationGroupKey]; ok { a := &ApplicationGroup{applicationGroup: applicationGroup} - application, err = a.Configuration() + config.Application, err = a.Configuration() if err != nil { return Channel{}, err } @@ -64,7 +49,7 @@ func (c *ChannelGroup) Configuration() (Channel, error) { if ordererGroup, ok := c.channelGroup.Groups[OrdererGroupKey]; ok { o := &OrdererGroup{ordererGroup: ordererGroup, channelGroup: c.channelGroup} - orderer, err = o.Configuration() + config.Orderer, err = o.Configuration() if err != nil { return Channel{}, err } @@ -72,37 +57,25 @@ func (c *ChannelGroup) Configuration() (Channel, error) { if consortiumsGroup, ok := c.channelGroup.Groups[ConsortiumsGroupKey]; ok { c := &ConsortiumsGroup{consortiumsGroup: consortiumsGroup} - consortiums, err = c.Configuration() + config.Consortiums, err = c.Configuration() if err != nil { return Channel{}, err } } if _, ok := c.channelGroup.Values[CapabilitiesKey]; ok { - capabilities, err = c.Capabilities() + config.Capabilities, err = c.Capabilities() if err != nil { return Channel{}, err } } - policies, err := c.Policies() + config.Policies, err = c.Policies() if err != nil { return Channel{}, err } - return Channel{ - Consortium: consortium, - Application: application, - Orderer: orderer, - Consortiums: consortiums, - Capabilities: capabilities, - Policies: policies, - }, nil -} - -// Configuration returns a channel configuration value from a config transaction. -func (u *UpdatedChannelGroup) Configuration() (Channel, error) { - return u.ChannelGroup.Configuration() + return config, nil } // Policies returns a map of policies for channel configuration. @@ -110,30 +83,25 @@ func (c *ChannelGroup) Policies() (map[string]Policy, error) { return getPolicies(c.channelGroup.Policies) } -// Policies returns a map of policies for channel configuration. -func (u *UpdatedChannelGroup) Policies() (map[string]Policy, error) { - return u.ChannelGroup.Policies() -} - // SetPolicy sets the specified policy in the channel group's config policy map. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedChannelGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { - return setPolicy(u.channelGroup, modPolicy, policyName, policy) +func (c *ChannelGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { + return setPolicy(c.channelGroup, modPolicy, policyName, policy) } // RemovePolicy removes an existing channel level policy. -func (u *UpdatedChannelGroup) RemovePolicy(policyName string) error { - policies, err := u.Policies() +func (c *ChannelGroup) RemovePolicy(policyName string) error { + policies, err := c.Policies() if err != nil { return err } - removePolicy(u.channelGroup, policyName, policies) + removePolicy(c.channelGroup, policyName, policies) return nil } // Capabilities returns a map of enabled channel capabilities -// from a config transaction's original config. +// from a config transaction's updated config. func (c *ChannelGroup) Capabilities() ([]string, error) { capabilities, err := getCapabilities(c.channelGroup) if err != nil { @@ -143,22 +111,16 @@ func (c *ChannelGroup) Capabilities() ([]string, error) { return capabilities, nil } -// Capabilities returns a map of enabled channel capabilities -// from a config transaction's updated config.. -func (u *UpdatedChannelGroup) Capabilities() ([]string, error) { - return u.ChannelGroup.Capabilities() -} - // AddCapability adds capability to the provided channel config. // If the provided capability already exist in current configuration, this action // will be a no-op. -func (u *UpdatedChannelGroup) AddCapability(capability string) error { - capabilities, err := u.Capabilities() +func (c *ChannelGroup) AddCapability(capability string) error { + capabilities, err := c.Capabilities() if err != nil { return err } - err = addCapability(u.channelGroup, capabilities, AdminsPolicyKey, capability) + err = addCapability(c.channelGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } @@ -167,13 +129,13 @@ func (u *UpdatedChannelGroup) AddCapability(capability string) error { } // RemoveCapability removes capability to the provided channel config. -func (u *UpdatedChannelGroup) RemoveCapability(capability string) error { - capabilities, err := u.Capabilities() +func (c *ChannelGroup) RemoveCapability(capability string) error { + capabilities, err := c.Capabilities() if err != nil { return err } - err = removeCapability(u.channelGroup, capabilities, AdminsPolicyKey, capability) + err = removeCapability(c.channelGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } diff --git a/configtx/config.go b/configtx/config.go index adfb20e..1bd7caf 100644 --- a/configtx/config.go +++ b/configtx/config.go @@ -78,51 +78,28 @@ type standardConfigPolicy struct { // ConfigTx wraps a config transaction. type ConfigTx struct { // original state of the config - original *OriginalConfig + original *cb.Config // modified state of the config - updated *UpdatedConfig + updated *cb.Config } // New creates a new ConfigTx from a Config protobuf. // New will panic if given an empty config. func New(config *cb.Config) ConfigTx { return ConfigTx{ - original: &OriginalConfig{Config: config}, + original: config, // Clone the base config for processing updates - updated: &UpdatedConfig{Config: proto.Clone(config).(*cb.Config)}, + updated: proto.Clone(config).(*cb.Config), } } -// OriginalConfig wraps the original state of the config -// and implements functions for retrieving values on it. -type OriginalConfig struct { - *cb.Config -} - -// UpdatedConfig wraps the modified state of the config -// and implements functions for retrieving and setting values -// on it. -type UpdatedConfig struct { - *cb.Config -} - -// OriginalConfig returns the original state of the config. -func (c *ConfigTx) OriginalConfig() *OriginalConfig { - return c.original -} - -// UpdatedConfig returns the modified state of the config -func (c *ConfigTx) UpdatedConfig() *UpdatedConfig { - return c.updated -} - // ComputeUpdate computes the ConfigUpdate from a base and modified config transaction. func (c *ConfigTx) ComputeUpdate(channelID string) (*cb.ConfigUpdate, error) { if channelID == "" { return nil, errors.New("channel ID is required") } - updt, err := computeConfigUpdate(c.original.Config, c.updated.Config) + updt, err := computeConfigUpdate(c.original, c.updated) if err != nil { return nil, fmt.Errorf("failed to compute update: %v", err) } @@ -223,7 +200,7 @@ func newSystemChannelGroup(channelConfig Channel) (*cb.ConfigGroup, error) { err = setPolicies(channelGroup, channelConfig.Policies, AdminsPolicyKey) if err != nil { - return nil, fmt.Errorf("failed to add system channel policies: %v", err) + return nil, fmt.Errorf("failed to set system channel policies: %v", err) } if len(channelConfig.Orderer.Addresses) == 0 { diff --git a/configtx/config_test.go b/configtx/config_test.go index e10bf86..deb957b 100644 --- a/configtx/config_test.go +++ b/configtx/config_test.go @@ -1146,8 +1146,8 @@ func TestComputeUpdate(t *testing.T) { } c := ConfigTx{ - original: &OriginalConfig{Config: original}, - updated: &UpdatedConfig{Config: updated}, + original: original, + updated: updated, } channelID := "testChannel" @@ -1182,8 +1182,8 @@ func TestComputeUpdateFailures(t *testing.T) { updated := &cb.Config{} c := ConfigTx{ - original: &OriginalConfig{Config: original}, - updated: &UpdatedConfig{Config: updated}, + original: original, + updated: updated, } for _, test := range []struct { @@ -1286,7 +1286,7 @@ func TestChannelConfiguration(t *testing.T) { config := tt.configMod(gt) c := New(config) - channel, err := c.OriginalConfig().Channel().Configuration() + channel, err := c.Channel().Configuration() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(channel.Consortium).To(Equal(tt.expectedChannel.Consortium)) gt.Expect(channel.Application.Organizations).To(ContainElements(tt.expectedChannel.Application.Organizations)) diff --git a/configtx/consortiums.go b/configtx/consortiums.go index dd4113c..1d19f9c 100644 --- a/configtx/consortiums.go +++ b/configtx/consortiums.go @@ -23,19 +23,11 @@ type Consortium struct { Organizations []Organization } -// ConsortiumsGroup encapsulates the parts of the config that control -// consortiums. This type implements retrieval of the various consortiums -// config values. +// ConsortiumsGroup encapsulates the parts of the config that control consortiums. type ConsortiumsGroup struct { consortiumsGroup *cb.ConfigGroup } -// UpdatedConsortiumsGroup is a ConsortiumsGroup that can be modified in -// order to generate a config update. -type UpdatedConsortiumsGroup struct { - *ConsortiumsGroup -} - // ConsortiumGroup encapsulates the parts of the config that control // a specific consortium. This type implements retrieval of the various // consortium config values. @@ -44,12 +36,6 @@ type ConsortiumGroup struct { name string } -// UpdatedConsortiumGroup is a ConsortiumGroup that can be modified in order -// to generate a config update. -type UpdatedConsortiumGroup struct { - *ConsortiumGroup -} - // ConsortiumOrg encapsulates the parts of the config that control a // consortium organization's configuration. type ConsortiumOrg struct { @@ -57,25 +43,13 @@ type ConsortiumOrg struct { name string } -// UpdatedConsortiumOrg is a ConsortiumOrg that can be modified in order -// to generate a config update. -type UpdatedConsortiumOrg struct { - *ConsortiumOrg -} - -// Consortiums returns the consortiums group from the original config. -func (o *OriginalConfig) Consortiums() *ConsortiumsGroup { - consortiumsGroup := o.ChannelGroup.Groups[ConsortiumsGroupKey] - return &ConsortiumsGroup{consortiumsGroup: consortiumsGroup} -} - // Consortiums returns the consortiums group from the updated config. -func (u *UpdatedConfig) Consortiums() *UpdatedConsortiumsGroup { - consortiumsGroup := u.ChannelGroup.Groups[ConsortiumsGroupKey] - return &UpdatedConsortiumsGroup{&ConsortiumsGroup{consortiumsGroup: consortiumsGroup}} +func (c *ConfigTx) Consortiums() *ConsortiumsGroup { + consortiumsGroup := c.updated.ChannelGroup.Groups[ConsortiumsGroupKey] + return &ConsortiumsGroup{consortiumsGroup: consortiumsGroup} } -// Consortium returns a consortium group from the original config. +// Consortium returns a consortium group from the updated config. func (c *ConsortiumsGroup) Consortium(name string) *ConsortiumGroup { consortiumGroup, ok := c.consortiumsGroup.Groups[name] if !ok { @@ -84,18 +58,13 @@ func (c *ConsortiumsGroup) Consortium(name string) *ConsortiumGroup { return &ConsortiumGroup{name: name, consortiumGroup: consortiumGroup} } -// Consortium returns a consortium group from the updated config. -func (u *UpdatedConsortiumsGroup) Consortium(name string) *UpdatedConsortiumGroup { - return &UpdatedConsortiumGroup{ConsortiumGroup: u.ConsortiumsGroup.Consortium(name)} -} - // SetConsortium sets the consortium in a channel configuration. // If the consortium already exists in the current configuration, its value will be overwritten. -func (u *UpdatedConsortiumsGroup) SetConsortium(consortium Consortium) error { - u.consortiumsGroup.Groups[consortium.Name] = newConfigGroup() +func (c *ConsortiumsGroup) SetConsortium(consortium Consortium) error { + c.consortiumsGroup.Groups[consortium.Name] = newConfigGroup() for _, org := range consortium.Organizations { - err := u.Consortium(consortium.Name).SetOrganization(org) + err := c.Consortium(consortium.Name).SetOrganization(org) if err != nil { return err } @@ -106,8 +75,8 @@ func (u *UpdatedConsortiumsGroup) SetConsortium(consortium Consortium) error { // RemoveConsortium removes a consortium from a channel configuration. // Removal will panic if the consortiums group does not exist. -func (u *UpdatedConsortiumsGroup) RemoveConsortium(name string) { - delete(u.consortiumsGroup.Groups, name) +func (c *ConsortiumsGroup) RemoveConsortium(name string) { + delete(c.consortiumsGroup.Groups, name) } // Organization returns the consortium org from the original config. @@ -119,33 +88,28 @@ func (c *ConsortiumGroup) Organization(name string) *ConsortiumOrg { return &ConsortiumOrg{name: name, orgGroup: orgGroup} } -// Organization returns the consortium org from the original updated config. -func (u *UpdatedConsortiumGroup) Organization(name string) *UpdatedConsortiumOrg { - return &UpdatedConsortiumOrg{ConsortiumOrg: u.ConsortiumGroup.Organization(name)} -} - // SetOrganization sets the organization config group for the given org key in // an existing Consortium configuration's Groups map. // If the consortium org already exists in the current configuration, its // value will be overwritten. -func (u *UpdatedConsortiumGroup) SetOrganization(org Organization) error { +func (c *ConsortiumGroup) SetOrganization(org Organization) error { orgGroup, err := newOrgConfigGroup(org) if err != nil { return fmt.Errorf("failed to create consortium org %s: %v", org.Name, err) } - u.consortiumGroup.Groups[org.Name] = orgGroup + c.consortiumGroup.Groups[org.Name] = orgGroup return nil } // RemoveOrganization removes an org from a consortium group. // Removal will panic if either the consortiums group or consortium group does not exist. -func (u *UpdatedConsortiumGroup) RemoveOrganization(name string) { - delete(u.consortiumGroup.Groups, name) +func (c *ConsortiumGroup) RemoveOrganization(name string) { + delete(c.consortiumGroup.Groups, name) } -// Configuration returns a list of consortium configurations from the original +// Configuration returns a list of consortium configurations from the updated // config. Consortiums are only defined for the ordering system channel. func (c *ConsortiumsGroup) Configuration() ([]Consortium, error) { consortiums := []Consortium{} @@ -160,13 +124,7 @@ func (c *ConsortiumsGroup) Configuration() ([]Consortium, error) { return consortiums, nil } -// Configuration returns a list of consortium configurations from the updated -// config. Consortiums are only defined for the ordering system channel. -func (u *UpdatedConsortiumsGroup) Configuration() ([]Consortium, error) { - return u.ConsortiumsGroup.Configuration() -} - -// Configuration returns the configuration for a consortium group +// Configuration returns the configuration for a consortium group. func (c *ConsortiumGroup) Configuration() (Consortium, error) { orgs := []Organization{} for orgName, orgGroup := range c.consortiumGroup.Groups { @@ -182,13 +140,8 @@ func (c *ConsortiumGroup) Configuration() (Consortium, error) { }, nil } -// Configuration returns the configuration for a consortium group -func (u *UpdatedConsortiumGroup) Configuration() (Consortium, error) { - return u.ConsortiumGroup.Configuration() -} - -// Configuration retrieves an existing org's configuration from a consortium organization -// config group in the original config. +// Configuration retrieves an existing org's configuration from a consortium +// organization config group in the updated config. func (c *ConsortiumOrg) Configuration() (Organization, error) { org, err := getOrganization(c.orgGroup, c.name) if err != nil { @@ -201,28 +154,16 @@ func (c *ConsortiumOrg) Configuration() (Organization, error) { return org, err } -// Configuration retrieves an existing org's configuration from a consortium organization -// config group in the updated config. -func (u *UpdatedConsortiumOrg) Configuration() (Organization, error) { - return u.ConsortiumOrg.Configuration() -} - // MSP returns the MSP configuration for an existing consortium // org in a config transaction. func (c *ConsortiumOrg) MSP() (MSP, error) { return getMSPConfig(c.orgGroup) } -// MSP returns the MSP configuration for an existing consortium -// org in a config transaction. -func (u *UpdatedConsortiumOrg) MSP() (MSP, error) { - return getMSPConfig(u.ConsortiumOrg.orgGroup) -} - // CreateMSPCRL creates a CRL that revokes the provided certificates // for the specified consortium org signed by the provided SigningIdentity. -func (u *UpdatedConsortiumOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { - msp, err := u.MSP() +func (c *ConsortiumOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { + msp, err := c.MSP() if err != nil { return nil, fmt.Errorf("retrieving consortium org msp: %s", err) } @@ -231,8 +172,8 @@ func (u *UpdatedConsortiumOrg) CreateMSPCRL(signingIdentity *SigningIdentity, ce } // SetMSP updates the MSP config for the specified consortium org group. -func (u *UpdatedConsortiumOrg) SetMSP(updatedMSP MSP) error { - currentMSP, err := u.MSP() +func (c *ConsortiumOrg) SetMSP(updatedMSP MSP) error { + currentMSP, err := c.MSP() if err != nil { return fmt.Errorf("retrieving msp: %v", err) } @@ -246,7 +187,7 @@ func (u *UpdatedConsortiumOrg) SetMSP(updatedMSP MSP) error { return err } - err = u.setMSPConfig(updatedMSP) + err = c.setMSPConfig(updatedMSP) if err != nil { return err } @@ -254,13 +195,13 @@ func (u *UpdatedConsortiumOrg) SetMSP(updatedMSP MSP) error { return nil } -func (u *UpdatedConsortiumOrg) setMSPConfig(updatedMSP MSP) error { +func (c *ConsortiumOrg) setMSPConfig(updatedMSP MSP) error { mspConfig, err := newMSPConfig(updatedMSP) if err != nil { return fmt.Errorf("new msp config: %v", err) } - err = setValue(u.ConsortiumOrg.orgGroup, mspValue(mspConfig), AdminsPolicyKey) + err = setValue(c.orgGroup, mspValue(mspConfig), AdminsPolicyKey) if err != nil { return err } @@ -271,7 +212,7 @@ func (u *UpdatedConsortiumOrg) setMSPConfig(updatedMSP MSP) error { // SetChannelCreationPolicy sets the ConsortiumChannelCreationPolicy for // the given configuration Group. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedConsortiumGroup) SetChannelCreationPolicy(policy Policy) error { +func (c *ConsortiumGroup) SetChannelCreationPolicy(policy Policy) error { imp, err := implicitMetaFromString(policy.Rule) if err != nil { return fmt.Errorf("invalid implicit meta policy rule '%s': %v", policy.Rule, err) @@ -283,8 +224,8 @@ func (u *UpdatedConsortiumGroup) SetChannelCreationPolicy(policy Policy) error { } // update channel creation policy value back to consortium - if err = setValue(u.ConsortiumGroup.consortiumGroup, channelCreationPolicyValue(implicitMetaPolicy), ordererAdminsPolicyName); err != nil { - return fmt.Errorf("failed to update channel creation policy to consortium %s: %v", u.name, err) + if err = setValue(c.consortiumGroup, channelCreationPolicyValue(implicitMetaPolicy), ordererAdminsPolicyName); err != nil { + return fmt.Errorf("failed to update channel creation policy to consortium %s: %v", c.name, err) } return nil @@ -295,17 +236,12 @@ func (c *ConsortiumOrg) Policies() (map[string]Policy, error) { return getPolicies(c.orgGroup.Policies) } -// Policies returns a map of policies for a specific consortium org. -func (u *UpdatedConsortiumOrg) Policies() (map[string]Policy, error) { - return u.ConsortiumOrg.Policies() -} - // SetPolicy sets the specified policy in the consortium org group's config policy map. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedConsortiumOrg) SetPolicy(name string, policy Policy) error { - err := setPolicy(u.ConsortiumOrg.orgGroup, AdminsPolicyKey, name, policy) +func (c *ConsortiumOrg) SetPolicy(name string, policy Policy) error { + err := setPolicy(c.orgGroup, AdminsPolicyKey, name, policy) if err != nil { - return fmt.Errorf("failed to set policy '%s' to consortium org '%s': %v", name, u.name, err) + return fmt.Errorf("failed to set policy '%s' to consortium org '%s': %v", name, c.name, err) } return nil @@ -313,8 +249,8 @@ func (u *UpdatedConsortiumOrg) SetPolicy(name string, policy Policy) error { // RemovePolicy removes an existing policy from a consortium's organization. // Removal will panic if either the consortiums group, consortium group, or consortium org group does not exist. -func (u *UpdatedConsortiumOrg) RemovePolicy(name string) { - delete(u.ConsortiumOrg.orgGroup.Policies, name) +func (c *ConsortiumOrg) RemovePolicy(name string) { + delete(c.orgGroup.Policies, name) } // newConsortiumsGroup returns the consortiums component of the channel configuration. This element is only defined for diff --git a/configtx/consortiums_test.go b/configtx/consortiums_test.go index 4ca02f1..e789d6d 100644 --- a/configtx/consortiums_test.go +++ b/configtx/consortiums_test.go @@ -750,10 +750,10 @@ func TestSetConsortiumOrg(t *testing.T) { err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedConfigJSON), expectedConfigProto) gt.Expect(err).NotTo(HaveOccurred()) - err = c.UpdatedConfig().Consortiums().Consortium("Consortium1").SetOrganization(orgToAdd) + err = c.Consortiums().Consortium("Consortium1").SetOrganization(orgToAdd) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedConfigProto)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedConfigProto)).To(BeTrue()) } func TestSetConsortiumOrgFailures(t *testing.T) { @@ -797,7 +797,7 @@ func TestSetConsortiumOrgFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Consortiums().Consortium(test.consortium).SetOrganization(test.org) + err = c.Consortiums().Consortium(test.consortium).SetOrganization(test.org) gt.Expect(err).To(MatchError(test.expectedErr)) }) } @@ -824,10 +824,10 @@ func TestRemoveConsortium(t *testing.T) { c := New(config) - c.UpdatedConfig().Consortiums().RemoveConsortium("Consortium1") + c.Consortiums().RemoveConsortium("Consortium1") - updatedConsortiumsGroup := c.UpdatedConfig().Consortiums() - gt.Expect(updatedConsortiumsGroup.Consortium("Consortium1").ConsortiumGroup).To(BeNil()) + updatedConsortiumsGroup := c.Consortiums() + gt.Expect(updatedConsortiumsGroup.Consortium("Consortium1")).To(BeNil()) } func TestGetConsortiums(t *testing.T) { @@ -851,7 +851,7 @@ func TestGetConsortiums(t *testing.T) { config := &cb.Config{ChannelGroup: channelGroup} c := New(config) - consortiums, err := c.OriginalConfig().Consortiums().Configuration() + consortiums, err := c.Consortiums().Configuration() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(len(baseConsortiums)).To(Equal(len(consortiums))) } @@ -893,7 +893,7 @@ func TestSetConsortium(t *testing.T) { newConsortium := consortiums[0] newConsortium.Name = "Consortium2" - err = c.UpdatedConfig().Consortiums().SetConsortium(newConsortium) + err = c.Consortiums().SetConsortium(newConsortium) gt.Expect(err).NotTo(HaveOccurred()) org1CertBase64, org1CRLBase64 := certCRLBase64(t, consortiums[0].Organizations[0].MSP) @@ -1415,7 +1415,7 @@ func TestSetConsortium(t *testing.T) { err = protolator.DeepUnmarshalJSON(bytes.NewBufferString(expectedConfigJSON), expectedConfigProto) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedConfigProto)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedConfigProto)).To(BeTrue()) } func baseConsortiums(t *testing.T) ([]Consortium, []*ecdsa.PrivateKey) { diff --git a/configtx/example_test.go b/configtx/example_test.go index 7b07e47..51e657c 100644 --- a/configtx/example_test.go +++ b/configtx/example_test.go @@ -87,7 +87,7 @@ func Example_basic() { baseConfig := fetchSystemChannelConfig() c := configtx.New(baseConfig) - err := c.UpdatedConfig().Consortiums().Consortium("SampleConsortium").SetChannelCreationPolicy( + err := c.Consortiums().Consortium("SampleConsortium").SetChannelCreationPolicy( configtx.Policy{Type: configtx.ImplicitMetaPolicyType, Rule: "MAJORITY Admins"}) if err != nil { @@ -132,21 +132,22 @@ func Example_basic() { } // This example updates an existing orderer configuration. -func ExampleUpdatedOrdererGroup_SetConfiguration() { +func ExampleOrdererGroup_SetConfiguration() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + o := c.Orderer() // Must retrieve the current orderer configuration from block and modify // the desired values - orderer, err := c.UpdatedConfig().Orderer().Configuration() + oConfig, err := o.Configuration() if err != nil { panic(err) } - orderer.Kafka.Brokers = []string{"kafka0:9092", "kafka1:9092", "kafka2:9092"} - orderer.BatchSize.MaxMessageCount = 500 + oConfig.Kafka.Brokers = []string{"kafka0:9092", "kafka1:9092", "kafka2:9092"} + oConfig.BatchSize.MaxMessageCount = 500 - err = c.UpdatedConfig().Orderer().SetConfiguration(orderer) + err = o.SetConfiguration(oConfig) if err != nil { panic(nil) } @@ -157,19 +158,20 @@ func ExampleUpdatedOrdererGroup_SetConfiguration() { func Example_aCLs() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + a := c.Application() acls := map[string]string{ "peer/Propose": "/Channel/Application/Writers", } - err := c.UpdatedConfig().Application().SetACLs(acls) + err := a.SetACLs(acls) if err != nil { panic(err) } aclsToDelete := []string{"event/Block"} - err = c.UpdatedConfig().Application().RemoveACLs(aclsToDelete) + err = a.RemoveACLs(aclsToDelete) if err != nil { panic(err) } @@ -180,6 +182,7 @@ func Example_aCLs() { func Example_anchorPeers() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + applicationOrg1 := c.Application().Organization("Org1") newAnchorPeer := configtx.Address{ Host: "127.0.0.2", @@ -187,7 +190,7 @@ func Example_anchorPeers() { } // Add a new anchor peer - err := c.UpdatedConfig().Application().Organization("Org1").AddAnchorPeer(newAnchorPeer) + err := applicationOrg1.AddAnchorPeer(newAnchorPeer) if err != nil { panic(err) } @@ -198,7 +201,7 @@ func Example_anchorPeers() { } // Remove an anchor peer - err = c.UpdatedConfig().Application().Organization("Org1").RemoveAnchorPeer(oldAnchorPeer) + err = applicationOrg1.RemoveAnchorPeer(oldAnchorPeer) if err != nil { panic(err) } @@ -209,8 +212,9 @@ func Example_anchorPeers() { func Example_policies() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + applicationOrg1 := c.Application().Organization("Org1") - err := c.UpdatedConfig().Application().Organization("Org1").SetPolicy( + err := applicationOrg1.SetPolicy( configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{ @@ -221,17 +225,20 @@ func Example_policies() { panic(err) } - err = c.UpdatedConfig().Application().Organization("Org1").RemovePolicy(configtx.WritersPolicyKey) + err = applicationOrg1.RemovePolicy(configtx.WritersPolicyKey) if err != nil { panic(err) } - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").RemovePolicy(configtx.WritersPolicyKey) + o := c.Orderer() + ordererOrg := o.Organization("OrdererOrg") + + err = ordererOrg.RemovePolicy(configtx.WritersPolicyKey) if err != nil { panic(err) } - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetPolicy( + err = ordererOrg.SetPolicy( configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{ @@ -242,12 +249,12 @@ func Example_policies() { panic(err) } - err = c.UpdatedConfig().Orderer().RemovePolicy(configtx.WritersPolicyKey) + err = o.RemovePolicy(configtx.WritersPolicyKey) if err != nil { panic(err) } - err = c.UpdatedConfig().Orderer().SetPolicy(configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{ + err = o.SetPolicy(configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{ Type: configtx.ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement", }) @@ -261,15 +268,16 @@ func Example_policies() { func Example_ordererEndpoints() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + ordererOrg := c.Orderer().Organization("OrdererOrg") - err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetEndpoint( + err := ordererOrg.SetEndpoint( configtx.Address{Host: "127.0.0.3", Port: 8050}, ) if err != nil { panic(err) } - err = c.UpdatedConfig().Orderer().Organization("Orderer").RemoveEndpoint( + err = ordererOrg.RemoveEndpoint( configtx.Address{Host: "127.0.0.1", Port: 9050}, ) if err != nil { @@ -282,6 +290,7 @@ func Example_ordererEndpoints() { func Example_organizations() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + a := c.Application() appOrg := configtx.Organization{ Name: "Org2", @@ -316,24 +325,26 @@ func Example_organizations() { }, } - err := c.UpdatedConfig().Application().SetOrganization(appOrg) + err := a.SetOrganization(appOrg) if err != nil { panic(err) } - c.UpdatedConfig().Application().RemoveOrganization("Org2") + a.RemoveOrganization("Org2") + + o := c.Orderer() // Orderer Organization ordererOrg := appOrg ordererOrg.Name = "OrdererOrg2" ordererOrg.AnchorPeers = nil - err = c.UpdatedConfig().Orderer().SetOrganization(ordererOrg) + err = o.SetOrganization(ordererOrg) if err != nil { panic(err) } - c.UpdatedConfig().Orderer().RemoveOrganization("OrdererOrg2") + o.RemoveOrganization("OrdererOrg2") } func ExampleNewSystemChannelGenesisBlock() { @@ -500,11 +511,12 @@ func ExampleNewCreateChannelTx() { // This example shows the addition of a certificate to an application org's intermediate // certificate list. -func ExampleUpdatedApplicationOrg_SetMSP() { +func ExampleApplicationOrg_SetMSP() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + applicationOrg1 := c.Application().Organization("Org1") - msp, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + msp, err := applicationOrg1.MSP() if err != nil { panic(err) } @@ -516,7 +528,7 @@ func ExampleUpdatedApplicationOrg_SetMSP() { msp.IntermediateCerts = append(msp.IntermediateCerts, newIntermediateCert) - err = c.UpdatedConfig().Application().Organization("Org1").SetMSP(msp) + err = applicationOrg1.SetMSP(msp) if err != nil { panic(err) } @@ -524,11 +536,12 @@ func ExampleUpdatedApplicationOrg_SetMSP() { // This example shows the addition of a certificate to an orderer org's intermediate // certificate list. -func ExampleUpdatedOrdererOrg_SetMSP() { +func ExampleOrdererOrg_SetMSP() { baseConfig := fetchChannelConfig() c := configtx.New(baseConfig) + ordererOrg := c.Orderer().Organization("OrdererOrg") - msp, err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").MSP() + msp, err := ordererOrg.MSP() if err != nil { panic(err) } @@ -540,7 +553,7 @@ func ExampleUpdatedOrdererOrg_SetMSP() { msp.IntermediateCerts = append(msp.IntermediateCerts, newIntermediateCert) - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetMSP(msp) + err = ordererOrg.SetMSP(msp) if err != nil { panic(err) } @@ -548,11 +561,11 @@ func ExampleUpdatedOrdererOrg_SetMSP() { // This example shows the addition of a certificate to a consortium org's intermediate // certificate list. -func ExampleUpdatedConsortiumOrg_SetMSP() { +func ExampleConsortiumOrg_SetMSP() { baseConfig := fetchSystemChannelConfig() c := configtx.New(baseConfig) - sampleConsortiumOrg1 := c.UpdatedConfig().Consortiums().Consortium("SampleConsortium").Organization("Org1") + sampleConsortiumOrg1 := c.Consortiums().Consortium("SampleConsortium").Organization("Org1") msp, err := sampleConsortiumOrg1.MSP() if err != nil { diff --git a/configtx/msp_test.go b/configtx/msp_test.go index 98aa94c..d853b76 100644 --- a/configtx/msp_test.go +++ b/configtx/msp_test.go @@ -64,7 +64,7 @@ func TestApplicationMSP(t *testing.T) { c := New(config) - msp, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + msp, err := c.Application().Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(msp).To(Equal(expectedMSP)) } @@ -90,7 +90,7 @@ func TestOrdererMSP(t *testing.T) { c := New(config) - msp, err := c.OriginalConfig().Orderer().Organization("OrdererOrg").MSP() + msp, err := c.Orderer().Organization("OrdererOrg").MSP() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(msp).To(Equal(expectedMSP)) } @@ -116,7 +116,7 @@ func TestConsortiumMSP(t *testing.T) { c := New(config) - msp, err := c.OriginalConfig().Consortiums().Consortium("Consortium1").Organization("Org1").MSP() + msp, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(msp).To(Equal(expectedMSP)) } @@ -257,8 +257,8 @@ func TestMSPConfigurationFailures(t *testing.T) { } c := &ConfigTx{ - original: &OriginalConfig{Config: config}, - updated: &UpdatedConfig{Config: config}, + original: config, + updated: config, } if tt.mspMod != nil && tt.orgType != ConsortiumsGroupKey { baseMSP, _ := baseMSP(t) @@ -282,13 +282,13 @@ func TestMSPConfigurationFailures(t *testing.T) { switch tt.orgType { case ApplicationGroupKey: - _, err := c.UpdatedConfig().Application().Organization(tt.orgName).MSP() + _, err := c.Application().Organization(tt.orgName).MSP() gt.Expect(err).To(MatchError(tt.expectedErr)) case OrdererGroupKey: - _, err := c.OriginalConfig().Orderer().Organization(tt.orgName).MSP() + _, err := c.Orderer().Organization(tt.orgName).MSP() gt.Expect(err).To(MatchError(tt.expectedErr)) case ConsortiumsGroupKey: - _, err := c.UpdatedConfig().Consortiums().Consortium(tt.consortiumName).Organization(tt.orgName).MSP() + _, err := c.Consortiums().Consortium(tt.consortiumName).Organization(tt.orgName).MSP() gt.Expect(err).To(MatchError(tt.expectedErr)) default: t.Fatalf("invalid org type %s", tt.orgType) @@ -432,7 +432,7 @@ func TestSetConsortiumMSP(t *testing.T) { } c := New(config) - consortium1 := c.UpdatedConfig().Consortiums().Consortium("Consortium1") + consortium1 := c.Consortiums().Consortium("Consortium1") consortiumOrg1MSP, err := consortium1.Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) consortiumOrg2MSP, err := consortium1.Organization("Org2").MSP() @@ -752,7 +752,7 @@ func TestSetConsortiumMSP(t *testing.T) { `, consortiumOrg1CertBase64, newIntermediateCertBase64, consortiumOrg1CRLBase64, newCRLBase64, newRootCertBase64, consortiumOrg2CertBase64, consortiumOrg2CRLBase64) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, c.UpdatedConfig().Config) + err = protolator.DeepMarshalJSON(&buf, c.updated) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(MatchJSON(expectedConfigJSON)) @@ -809,7 +809,7 @@ func TestSetConsortiumMSPFailure(t *testing.T) { } c := New(config) - consortiumOrg1 := c.UpdatedConfig().Consortiums().Consortium("Consortium1").Organization("Org1") + consortiumOrg1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") consortiumOrg1MSP, err := consortiumOrg1.MSP() gt.Expect(err).NotTo(HaveOccurred()) @@ -832,7 +832,7 @@ func TestUpdateOrdererMSP(t *testing.T) { } c := New(config) - ordererMSP, err := c.OriginalConfig().Orderer().Organization("OrdererOrg").MSP() + ordererMSP, err := c.Orderer().Organization("OrdererOrg").MSP() gt.Expect(err).NotTo(HaveOccurred()) ordererCertBase64, ordererCRLBase64 := certCRLBase64(t, ordererMSP) @@ -852,14 +852,14 @@ func TestUpdateOrdererMSP(t *testing.T) { PrivateKey: privKeys[0], MSPID: "MSPID", } - newCRL, err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").CreateMSPCRL(signingIdentity, certToRevoke) + newCRL, err := c.Orderer().Organization("OrdererOrg").CreateMSPCRL(signingIdentity, certToRevoke) gt.Expect(err).NotTo(HaveOccurred()) pemNewCRL, err := pemEncodeCRL(newCRL) gt.Expect(err).NotTo(HaveOccurred()) newCRLBase64 := base64.StdEncoding.EncodeToString(pemNewCRL) ordererMSP.RevocationList = append(ordererMSP.RevocationList, newCRL) - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetMSP(ordererMSP) + err = c.Orderer().Organization("OrdererOrg").SetMSP(ordererMSP) gt.Expect(err).NotTo(HaveOccurred()) expectedConfigJSON := fmt.Sprintf(` @@ -1092,7 +1092,7 @@ func TestUpdateOrdererMSP(t *testing.T) { }`, ordererCertBase64, newIntermediateCertBase64, ordererCRLBase64, newCRLBase64, newRootCertBase64) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, c.UpdatedConfig().Config) + err = protolator.DeepMarshalJSON(&buf, c.updated) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(MatchJSON(expectedConfigJSON)) @@ -1146,11 +1146,11 @@ func TestUpdateOrdererMSPFailure(t *testing.T) { } c := New(config) - ordererMSP, err := c.OriginalConfig().Orderer().Organization("OrdererOrg").MSP() + ordererMSP, err := c.Orderer().Organization("OrdererOrg").MSP() gt.Expect(err).NotTo(HaveOccurred()) ordererMSP = tc.mspMod(ordererMSP) - err = c.UpdatedConfig().Orderer().Organization(tc.orgName).SetMSP(ordererMSP) + err = c.Orderer().Organization(tc.orgName).SetMSP(ordererMSP) gt.Expect(err).To(MatchError(tc.expectedErr)) }) } @@ -1168,9 +1168,9 @@ func TestSetApplicationMSP(t *testing.T) { c := New(config) - org1MSP, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + org1MSP, err := c.Application().Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) - org2MSP, err := c.UpdatedConfig().Application().Organization("Org2").MSP() + org2MSP, err := c.Application().Organization("Org2").MSP() gt.Expect(err).NotTo(HaveOccurred()) org1CertBase64, org1CRLBase64 := certCRLBase64(t, org1MSP) org2CertBase64, org2CRLBase64 := certCRLBase64(t, org2MSP) @@ -1191,14 +1191,14 @@ func TestSetApplicationMSP(t *testing.T) { PrivateKey: privKey, MSPID: "MSPID", } - newCRL, err := c.UpdatedConfig().Application().Organization("Org1").CreateMSPCRL(signingIdentity, certToRevoke) + newCRL, err := c.Application().Organization("Org1").CreateMSPCRL(signingIdentity, certToRevoke) gt.Expect(err).NotTo(HaveOccurred()) pemNewCRL, err := pemEncodeCRL(newCRL) gt.Expect(err).NotTo(HaveOccurred()) newCRLBase64 := base64.StdEncoding.EncodeToString(pemNewCRL) org1MSP.RevocationList = append(org1MSP.RevocationList, newCRL) - err = c.UpdatedConfig().Application().Organization("Org1").SetMSP(org1MSP) + err = c.Application().Organization("Org1").SetMSP(org1MSP) gt.Expect(err).NotTo(HaveOccurred()) expectedConfigJSON := fmt.Sprintf(` @@ -1526,7 +1526,7 @@ func TestSetApplicationMSP(t *testing.T) { `, org1CertBase64, newIntermediateCertBase64, org1CRLBase64, newCRLBase64, newRootCertBase64, org2CertBase64, org2CRLBase64) buf := bytes.Buffer{} - err = protolator.DeepMarshalJSON(&buf, c.UpdatedConfig().Config) + err = protolator.DeepMarshalJSON(&buf, c.updated) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(MatchJSON(expectedConfigJSON)) @@ -1649,11 +1649,11 @@ func TestSetApplicationMSPFailure(t *testing.T) { c := New(config) - org1MSP, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + org1MSP, err := c.Application().Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) org1MSP = tc.mspMod(org1MSP) - err = c.UpdatedConfig().Application().Organization(tc.orgName).SetMSP(org1MSP) + err = c.Application().Organization(tc.orgName).SetMSP(org1MSP) gt.Expect(err).To(MatchError(tc.expectedErr)) }) } @@ -1671,20 +1671,20 @@ func TestCreateApplicationMSPCRL(t *testing.T) { c := New(config) - org1MSP, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + org1MSP, err := c.Application().Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) org1RootCert := org1MSP.RootCerts[0] org1PrivKey := privKeys[0] // update org2MSP to include an intemediate cert that is different // from the root cert - org2MSP, err := c.UpdatedConfig().Application().Organization("Org2").MSP() + org2MSP, err := c.Application().Organization("Org2").MSP() gt.Expect(err).NotTo(HaveOccurred()) org2Cert := org2MSP.RootCerts[0] org2PrivKey := privKeys[1] org2IntermediateCert, org2IntermediatePrivKey := generateIntermediateCACertAndPrivateKey(t, "org2.example.com", org2Cert, org2PrivKey) org2MSP.IntermediateCerts = append(org2MSP.IntermediateCerts, org2IntermediateCert) - err = c.UpdatedConfig().Application().Organization("Org2").SetMSP(org2MSP) + err = c.Application().Organization("Org2").SetMSP(org2MSP) gt.Expect(err).NotTo(HaveOccurred()) tests := []struct { @@ -1724,7 +1724,7 @@ func TestCreateApplicationMSPCRL(t *testing.T) { PrivateKey: tc.caPrivKey, MSPID: "MSPID", } - crl, err := c.UpdatedConfig().Application().Organization(tc.orgName).CreateMSPCRL(signingIdentity, certsToRevoke...) + crl, err := c.Application().Organization(tc.orgName).CreateMSPCRL(signingIdentity, certsToRevoke...) gt.Expect(err).NotTo(HaveOccurred()) err = tc.caCert.CheckCRLSignature(crl) gt.Expect(err).NotTo(HaveOccurred()) @@ -1748,13 +1748,13 @@ func TestCreateApplicationMSPCRLFailure(t *testing.T) { c := New(config) - org1MSP, err := c.UpdatedConfig().Application().Organization("Org1").MSP() + org1MSP, err := c.Application().Organization("Org1").MSP() gt.Expect(err).NotTo(HaveOccurred()) org1Cert := org1MSP.RootCerts[0] org1PrivKey := privKeys[0] org1CertToRevoke, _ := generateCertAndPrivateKeyFromCACert(t, "org1.example.com", org1Cert, org1PrivKey) - org2MSP, err := c.UpdatedConfig().Application().Organization("Org2").MSP() + org2MSP, err := c.Application().Organization("Org2").MSP() gt.Expect(err).NotTo(HaveOccurred()) org2Cert := org2MSP.RootCerts[0] org2PrivKey := privKeys[1] @@ -1797,7 +1797,7 @@ func TestCreateApplicationMSPCRLFailure(t *testing.T) { t.Parallel() gt := NewGomegaWithT(t) - newCRL, err := c.UpdatedConfig().Application().Organization(tc.orgName).CreateMSPCRL(tc.signingIdentity, tc.certToRevoke) + newCRL, err := c.Application().Organization(tc.orgName).CreateMSPCRL(tc.signingIdentity, tc.certToRevoke) gt.Expect(err).To(MatchError(tc.expectedErr)) gt.Expect(newCRL).To(BeNil()) }) diff --git a/configtx/orderer.go b/configtx/orderer.go index 21e52fa..40e7f1c 100644 --- a/configtx/orderer.go +++ b/configtx/orderer.go @@ -44,19 +44,12 @@ type Orderer struct { } // OrdererGroup encapsulates the parts of the config that control -// the orderering service behavior. This type implements retrieval -// of the various orderer config values. +// the orderering service behavior. type OrdererGroup struct { channelGroup *cb.ConfigGroup ordererGroup *cb.ConfigGroup } -// UpdatedOrdererGroup is an OrdererGroup that can be modified in -// order to generate a config update. -type UpdatedOrdererGroup struct { - *OrdererGroup -} - // OrdererOrg encapsulates the parts of the config that control // an orderer organization's configuration. type OrdererOrg struct { @@ -64,27 +57,14 @@ type OrdererOrg struct { name string } -// UpdatedOrdererOrg is an OrdererOrg that can be modified in order -// to generate a config update. -type UpdatedOrdererOrg struct { - *OrdererOrg -} - -// Orderer returns the orderer group from the original config. -func (o *OriginalConfig) Orderer() *OrdererGroup { - channelGroup := o.ChannelGroup - ordererGroup := channelGroup.Groups[OrdererGroupKey] - return &OrdererGroup{channelGroup: channelGroup, ordererGroup: ordererGroup} -} - // Orderer returns the orderer group from the updated config. -func (u *UpdatedConfig) Orderer() *UpdatedOrdererGroup { - channelGroup := u.ChannelGroup +func (c *ConfigTx) Orderer() *OrdererGroup { + channelGroup := c.updated.ChannelGroup ordererGroup := channelGroup.Groups[OrdererGroupKey] - return &UpdatedOrdererGroup{&OrdererGroup{channelGroup: channelGroup, ordererGroup: ordererGroup}} + return &OrdererGroup{channelGroup: channelGroup, ordererGroup: ordererGroup} } -// Organization returns the orderer org from the original config. +// Organization returns the orderer org from the updated config. func (o *OrdererGroup) Organization(name string) *OrdererOrg { orgGroup, ok := o.ordererGroup.Groups[name] if !ok { @@ -93,12 +73,7 @@ func (o *OrdererGroup) Organization(name string) *OrdererOrg { return &OrdererOrg{name: name, orgGroup: orgGroup} } -// Organization returns the orderer org from the updated config. -func (u *UpdatedOrdererGroup) Organization(name string) *UpdatedOrdererOrg { - return &UpdatedOrdererOrg{OrdererOrg: u.OrdererGroup.Organization(name)} -} - -// Configuration returns the existing orderer configuration values from the original +// Configuration returns the existing orderer configuration values from the updated // config in a config transaction as an Orderer type. This can be used to retrieve // existing values for the orderer prior to updating the orderer configuration. func (o *OrdererGroup) Configuration() (Orderer, error) { @@ -233,15 +208,8 @@ func (o *OrdererGroup) getOrdererAddresses() ([]Address, error) { return addresses, nil } -// Configuration returns the existing orderer configuration values from the updated -// config in a config transaction as an Orderer type. This can be used to retrieve -// existing values for the orderer while updating the orderer configuration. -func (u *UpdatedOrdererGroup) Configuration() (Orderer, error) { - return u.OrdererGroup.Configuration() -} - // Configuration retrieves an existing org's configuration from an -// orderer organization config group in the original config. +// orderer organization config group in the updated config. func (o *OrdererOrg) Configuration() (Organization, error) { org, err := getOrganization(o.orgGroup, o.name) if err != nil { @@ -266,45 +234,39 @@ func (o *OrdererOrg) Configuration() (Organization, error) { return org, nil } -// Configuration retrieves an existing org's configuration from an -// orderer organization config group in the updated config. -func (u *UpdatedOrdererOrg) Configuration() (Organization, error) { - return u.OrdererOrg.Configuration() -} - // SetOrganization sets the organization config group for the given orderer // org key in an existing Orderer configuration's Groups map. // If the orderer org already exists in the current configuration, its value will be overwritten. -func (u *UpdatedOrdererGroup) SetOrganization(org Organization) error { +func (o *OrdererGroup) SetOrganization(org Organization) error { orgGroup, err := newOrdererOrgConfigGroup(org) if err != nil { return fmt.Errorf("failed to create orderer org %s: %v", org.Name, err) } - u.ordererGroup.Groups[org.Name] = orgGroup + o.ordererGroup.Groups[org.Name] = orgGroup return nil } // RemoveOrganization removes an org from the Orderer group. // Removal will panic if the orderer group does not exist. -func (u *UpdatedOrdererGroup) RemoveOrganization(name string) { - delete(u.ordererGroup.Groups, name) +func (o *OrdererGroup) RemoveOrganization(name string) { + delete(o.ordererGroup.Groups, name) } // SetConfiguration modifies an updated config's Orderer configuration // via the passed in Orderer values. It skips updating OrdererOrgGroups and Policies. -func (u *UpdatedOrdererGroup) SetConfiguration(o Orderer) error { +func (o *OrdererGroup) SetConfiguration(ord Orderer) error { // update orderer addresses - if len(o.Addresses) > 0 { - err := setValue(u.channelGroup, ordererAddressesValue(o.Addresses), ordererAdminsPolicyName) + if len(ord.Addresses) > 0 { + err := setValue(o.channelGroup, ordererAddressesValue(ord.Addresses), ordererAdminsPolicyName) if err != nil { return err } } // update orderer values - err := addOrdererValues(u.ordererGroup, o) + err := addOrdererValues(o.ordererGroup, ord) if err != nil { return err } @@ -313,7 +275,7 @@ func (u *UpdatedOrdererGroup) SetConfiguration(o Orderer) error { } // Capabilities returns a map of enabled orderer capabilities -// from the original config. +// from the updated config. func (o *OrdererGroup) Capabilities() ([]string, error) { capabilities, err := getCapabilities(o.ordererGroup) if err != nil { @@ -323,22 +285,16 @@ func (o *OrdererGroup) Capabilities() ([]string, error) { return capabilities, nil } -// Capabilities returns a map of enabled orderer capabilities -// from the updated config. -func (u *UpdatedOrdererGroup) Capabilities() ([]string, error) { - return u.OrdererGroup.Capabilities() -} - // AddCapability adds capability to the provided channel config. // If the provided capability already exist in current configuration, this action // will be a no-op. -func (u *UpdatedOrdererGroup) AddCapability(capability string) error { - capabilities, err := u.Capabilities() +func (o *OrdererGroup) AddCapability(capability string) error { + capabilities, err := o.Capabilities() if err != nil { return err } - err = addCapability(u.ordererGroup, capabilities, AdminsPolicyKey, capability) + err = addCapability(o.ordererGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } @@ -347,13 +303,13 @@ func (u *UpdatedOrdererGroup) AddCapability(capability string) error { } // RemoveCapability removes capability to the provided channel config. -func (u *UpdatedOrdererGroup) RemoveCapability(capability string) error { - capabilities, err := u.Capabilities() +func (o *OrdererGroup) RemoveCapability(capability string) error { + capabilities, err := o.Capabilities() if err != nil { return err } - err = removeCapability(u.ordererGroup, capabilities, AdminsPolicyKey, capability) + err = removeCapability(o.ordererGroup, capabilities, AdminsPolicyKey, capability) if err != nil { return err } @@ -363,13 +319,13 @@ func (u *UpdatedOrdererGroup) RemoveCapability(capability string) error { // SetEndpoint adds an orderer's endpoint to an existing channel config transaction. // If the same endpoint already exist in current configuration, this will be a no-op. -func (u *UpdatedOrdererOrg) SetEndpoint(endpoint Address) error { +func (o *OrdererOrg) SetEndpoint(endpoint Address) error { ordererAddrProto := &cb.OrdererAddresses{} - if ordererAddrConfigValue, ok := u.orgGroup.Values[EndpointsKey]; ok { + if ordererAddrConfigValue, ok := o.orgGroup.Values[EndpointsKey]; ok { err := proto.Unmarshal(ordererAddrConfigValue.Value, ordererAddrProto) if err != nil { - return fmt.Errorf("failed unmarshaling endpoints for orderer org %s: %v", u.name, err) + return fmt.Errorf("failed unmarshaling endpoints for orderer org %s: %v", o.name, err) } } @@ -385,9 +341,9 @@ func (u *UpdatedOrdererOrg) SetEndpoint(endpoint Address) error { existingOrdererEndpoints = append(existingOrdererEndpoints, endpointToAdd) // Add orderer endpoints config value back to orderer org - err := setValue(u.orgGroup, endpointsValue(existingOrdererEndpoints), AdminsPolicyKey) + err := setValue(o.orgGroup, endpointsValue(existingOrdererEndpoints), AdminsPolicyKey) if err != nil { - return fmt.Errorf("failed to add endpoint %v to orderer org %s: %v", endpoint, u.name, err) + return fmt.Errorf("failed to add endpoint %v to orderer org %s: %v", endpoint, o.name, err) } return nil @@ -395,13 +351,13 @@ func (u *UpdatedOrdererOrg) SetEndpoint(endpoint Address) error { // RemoveEndpoint removes an orderer's endpoint from an existing channel config transaction. // Removal will panic if either the orderer group or orderer org group does not exist. -func (u *UpdatedOrdererOrg) RemoveEndpoint(endpoint Address) error { +func (o *OrdererOrg) RemoveEndpoint(endpoint Address) error { ordererAddrProto := &cb.OrdererAddresses{} - if ordererAddrConfigValue, ok := u.orgGroup.Values[EndpointsKey]; ok { + if ordererAddrConfigValue, ok := o.orgGroup.Values[EndpointsKey]; ok { err := proto.Unmarshal(ordererAddrConfigValue.Value, ordererAddrProto) if err != nil { - return fmt.Errorf("failed unmarshaling endpoints for orderer org %s: %v", u.name, err) + return fmt.Errorf("failed unmarshaling endpoints for orderer org %s: %v", o.name, err) } } @@ -415,9 +371,9 @@ func (u *UpdatedOrdererOrg) RemoveEndpoint(endpoint Address) error { } // Add orderer endpoints config value back to orderer org - err := setValue(u.orgGroup, endpointsValue(existingEndpoints), AdminsPolicyKey) + err := setValue(o.orgGroup, endpointsValue(existingEndpoints), AdminsPolicyKey) if err != nil { - return fmt.Errorf("failed to remove endpoint %v from orderer org %s: %v", endpoint, u.name, err) + return fmt.Errorf("failed to remove endpoint %v from orderer org %s: %v", endpoint, o.name, err) } return nil @@ -425,8 +381,8 @@ func (u *UpdatedOrdererOrg) RemoveEndpoint(endpoint Address) error { // SetPolicy sets the specified policy in the orderer group's config policy map. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedOrdererGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { - err := setPolicy(u.ordererGroup, modPolicy, policyName, policy) +func (o *OrdererGroup) SetPolicy(modPolicy, policyName string, policy Policy) error { + err := setPolicy(o.ordererGroup, modPolicy, policyName, policy) if err != nil { return fmt.Errorf("failed to set policy '%s': %v", policyName, err) } @@ -435,48 +391,36 @@ func (u *UpdatedOrdererGroup) SetPolicy(modPolicy, policyName string, policy Pol } // RemovePolicy removes an existing orderer policy configuration. -func (u *UpdatedOrdererGroup) RemovePolicy(policyName string) error { +func (o *OrdererGroup) RemovePolicy(policyName string) error { if policyName == BlockValidationPolicyKey { return errors.New("BlockValidation policy must be defined") } - policies, err := u.Policies() + policies, err := o.Policies() if err != nil { return err } - removePolicy(u.ordererGroup, policyName, policies) + removePolicy(o.ordererGroup, policyName, policies) return nil } // Policies returns a map of policies for channel orderer in the -// original config. +// updated config. func (o *OrdererGroup) Policies() (map[string]Policy, error) { return getPolicies(o.ordererGroup.Policies) } -// Policies returns a map of policies for channel orderer in the -// updated config. -func (u *UpdatedOrdererGroup) Policies() (map[string]Policy, error) { - return u.OrdererGroup.Policies() -} - // MSP returns the MSP value for an orderer organization in the -// original config. +// updated config. func (o *OrdererOrg) MSP() (MSP, error) { return getMSPConfig(o.orgGroup) } -// MSP returns the MSP value for an orderer organization in the -// updated config. -func (u *UpdatedOrdererOrg) MSP() (MSP, error) { - return u.OrdererOrg.MSP() -} - // SetMSP updates the MSP config for the specified orderer org // in the updated config. -func (u *UpdatedOrdererOrg) SetMSP(updatedMSP MSP) error { - currentMSP, err := u.MSP() +func (o *OrdererOrg) SetMSP(updatedMSP MSP) error { + currentMSP, err := o.MSP() if err != nil { return fmt.Errorf("retrieving msp: %v", err) } @@ -490,7 +434,7 @@ func (u *UpdatedOrdererOrg) SetMSP(updatedMSP MSP) error { return err } - err = u.setMSPConfig(updatedMSP) + err = o.setMSPConfig(updatedMSP) if err != nil { return err } @@ -498,13 +442,13 @@ func (u *UpdatedOrdererOrg) SetMSP(updatedMSP MSP) error { return nil } -func (u *UpdatedOrdererOrg) setMSPConfig(updatedMSP MSP) error { +func (o *OrdererOrg) setMSPConfig(updatedMSP MSP) error { mspConfig, err := newMSPConfig(updatedMSP) if err != nil { return fmt.Errorf("new msp config: %v", err) } - err = setValue(u.OrdererOrg.orgGroup, mspValue(mspConfig), AdminsPolicyKey) + err = setValue(o.orgGroup, mspValue(mspConfig), AdminsPolicyKey) if err != nil { return err } @@ -514,8 +458,8 @@ func (u *UpdatedOrdererOrg) setMSPConfig(updatedMSP MSP) error { // CreateMSPCRL creates a CRL that revokes the provided certificates // for the specified orderer org signed by the provided SigningIdentity. -func (u *UpdatedOrdererOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { - msp, err := u.MSP() +func (o *OrdererOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs ...*x509.Certificate) (*pkix.CertificateList, error) { + msp, err := o.MSP() if err != nil { return nil, fmt.Errorf("retrieving orderer msp: %s", err) } @@ -525,33 +469,27 @@ func (u *UpdatedOrdererOrg) CreateMSPCRL(signingIdentity *SigningIdentity, certs // SetPolicy sets the specified policy in the orderer org group's config policy map. // If the policy already exist in current configuration, its value will be overwritten. -func (u *UpdatedOrdererOrg) SetPolicy(modPolicy, policyName string, policy Policy) error { - return setPolicy(u.orgGroup, modPolicy, policyName, policy) +func (o *OrdererOrg) SetPolicy(modPolicy, policyName string, policy Policy) error { + return setPolicy(o.orgGroup, modPolicy, policyName, policy) } // RemovePolicy removes an existing policy from an orderer organization. -func (u *UpdatedOrdererOrg) RemovePolicy(policyName string) error { - policies, err := u.Policies() +func (o *OrdererOrg) RemovePolicy(policyName string) error { + policies, err := o.Policies() if err != nil { return err } - removePolicy(u.orgGroup, policyName, policies) + removePolicy(o.orgGroup, policyName, policies) return nil } // Policies returns a map of policies for a specific orderer org -// in the original config.. +// in the updated config. func (o *OrdererOrg) Policies() (map[string]Policy, error) { return getPolicies(o.orgGroup.Policies) } -// Policies returns a map of policies for a specific orderer org -// in the updated config.. -func (u *UpdatedOrdererOrg) Policies() (map[string]Policy, error) { - return u.OrdererOrg.Policies() -} - // newOrdererGroup returns the orderer component of the channel configuration. // It defines parameters of the ordering service about how large blocks should be, // how frequently they should be emitted, etc. as well as the organizations of the ordering network. diff --git a/configtx/orderer_test.go b/configtx/orderer_test.go index 503758e..f25e257 100644 --- a/configtx/orderer_test.go +++ b/configtx/orderer_test.go @@ -942,7 +942,7 @@ func TestSetOrdererConfiguration(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Orderer().SetConfiguration(updatedOrdererConf) + err = c.Orderer().SetConfiguration(updatedOrdererConf) gt.Expect(err).NotTo(HaveOccurred()) expectedConfigJSON := fmt.Sprintf(` @@ -1213,7 +1213,7 @@ func TestSetOrdererConfiguration(t *testing.T) { `, certBase64, crlBase64) buf := &bytes.Buffer{} - err = protolator.DeepMarshalJSON(buf, c.UpdatedConfig().Config) + err = protolator.DeepMarshalJSON(buf, c.updated) gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(buf.String()).To(MatchJSON(expectedConfigJSON)) @@ -1270,7 +1270,7 @@ func TestOrdererConfiguration(t *testing.T) { c := New(config) - ordererConf, err := c.OriginalConfig().Orderer().Configuration() + ordererConf, err := c.Orderer().Configuration() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(ordererConf).To(Equal(baseOrdererConf)) }) @@ -1360,7 +1360,7 @@ func TestOrdererConfigurationFailure(t *testing.T) { c := New(config) - _, err = c.OriginalConfig().Orderer().Configuration() + _, err = c.Orderer().Configuration() gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -1519,10 +1519,10 @@ func TestSetOrdererOrg(t *testing.T) { } `, certBase64, crlBase64) - err = c.UpdatedConfig().Orderer().SetOrganization(org) + err = c.Orderer().SetOrganization(org) gt.Expect(err).NotTo(HaveOccurred()) - actualOrdererConfigGroup := c.UpdatedConfig().Orderer().Organization("OrdererOrg2").orgGroup + actualOrdererConfigGroup := c.Orderer().Organization("OrdererOrg2").orgGroup buf := bytes.Buffer{} err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: actualOrdererConfigGroup}) gt.Expect(err).NotTo(HaveOccurred()) @@ -1552,7 +1552,7 @@ func TestSetOrdererOrgFailures(t *testing.T) { Name: "OrdererOrg2", } - err = c.UpdatedConfig().Orderer().SetOrganization(org) + err = c.Orderer().SetOrganization(org) gt.Expect(err).To(MatchError("failed to create orderer org OrdererOrg2: no policies defined")) } @@ -1636,10 +1636,10 @@ func TestSetOrdererEndpoint(t *testing.T) { gt.Expect(err).ToNot(HaveOccurred()) newOrderer1OrgEndpoint := Address{Host: "127.0.0.1", Port: 9050} - err = c.UpdatedConfig().Orderer().Organization("Orderer1Org").SetEndpoint(newOrderer1OrgEndpoint) + err = c.Orderer().Organization("Orderer1Org").SetEndpoint(newOrderer1OrgEndpoint) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue()) } func TestRemoveOrdererEndpoint(t *testing.T) { @@ -1723,10 +1723,10 @@ func TestRemoveOrdererEndpoint(t *testing.T) { gt.Expect(err).ToNot(HaveOccurred()) removedEndpoint := Address{Host: "127.0.0.1", Port: 8050} - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").RemoveEndpoint(removedEndpoint) + err = c.Orderer().Organization("OrdererOrg").RemoveEndpoint(removedEndpoint) gt.Expect(err).NotTo(HaveOccurred()) - gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue()) + gt.Expect(proto.Equal(c.updated, expectedUpdatedConfig)).To(BeTrue()) } func TestRemoveOrdererEndpointFailure(t *testing.T) { @@ -1763,7 +1763,7 @@ func TestRemoveOrdererEndpointFailure(t *testing.T) { c := New(config) - err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").RemoveEndpoint(Address{Host: "127.0.0.1", Port: 8050}) + err := c.Orderer().Organization("OrdererOrg").RemoveEndpoint(Address{Host: "127.0.0.1", Port: 8050}) gt.Expect(err).To(MatchError("failed unmarshaling endpoints for orderer org OrdererOrg: proto: can't skip unknown wire type 6")) } diff --git a/configtx/organization_test.go b/configtx/organization_test.go index f77fbf3..6e219eb 100644 --- a/configtx/organization_test.go +++ b/configtx/organization_test.go @@ -72,7 +72,7 @@ func TestApplicationOrg(t *testing.T) { t.Parallel() gt := NewGomegaWithT(t) - org, err := c.UpdatedConfig().Application().Organization(tc.orgName).Configuration() + org, err := c.Application().Organization(tc.orgName).Configuration() gt.Expect(err).ToNot(HaveOccurred()) gt.Expect(expectedOrg).To(Equal(org)) }) @@ -102,7 +102,7 @@ func TestRemoveApplicationOrg(t *testing.T) { c := New(config) - c.UpdatedConfig().Application().RemoveOrganization("Org1") + c.Application().RemoveOrganization("Org1") gt.Expect(c.updated.ChannelGroup.Groups[ApplicationGroupKey].Groups["Org1"]).To(BeNil()) } @@ -140,7 +140,7 @@ func TestOrdererOrg(t *testing.T) { t.Parallel() gt := NewGomegaWithT(t) - org, err := c.OriginalConfig().Orderer().Organization(tc.orgName).Configuration() + org, err := c.Orderer().Organization(tc.orgName).Configuration() if tc.expectedErr != "" { gt.Expect(err).To(MatchError(tc.expectedErr)) gt.Expect(Organization{}).To(Equal(org)) @@ -166,8 +166,8 @@ func TestRemoveOrdererOrg(t *testing.T) { c := New(config) - c.UpdatedConfig().Orderer().RemoveOrganization("OrdererOrg") - gt.Expect(c.UpdatedConfig().Orderer().Organization("OrdererOrg").OrdererOrg).To(BeNil()) + c.Orderer().RemoveOrganization("OrdererOrg") + gt.Expect(c.Orderer().Organization("OrdererOrg")).To(BeNil()) } func TestConsortiumOrg(t *testing.T) { @@ -206,7 +206,7 @@ func TestConsortiumOrg(t *testing.T) { t.Parallel() gt := NewGomegaWithT(t) - org, err := c.UpdatedConfig().Consortiums().Consortium(tc.consortiumName).Organization(tc.orgName).Configuration() + org, err := c.Consortiums().Consortium(tc.consortiumName).Organization(tc.orgName).Configuration() if tc.expectedErr != "" { gt.Expect(Organization{}).To(Equal(org)) gt.Expect(err).To(MatchError(tc.expectedErr)) @@ -232,8 +232,8 @@ func TestRemoveConsortiumOrg(t *testing.T) { c := New(config) - c.UpdatedConfig().Consortiums().Consortium("Consortium1").RemoveOrganization("Org1") - gt.Expect(c.UpdatedConfig().Consortiums().Consortium("Consortium1").Organization("Org1").ConsortiumOrg).To(BeNil()) + c.Consortiums().Consortium("Consortium1").RemoveOrganization("Org1") + gt.Expect(c.Consortiums().Consortium("Consortium1").Organization("Org1")).To(BeNil()) } func TestNewOrgConfigGroup(t *testing.T) { diff --git a/configtx/policies_test.go b/configtx/policies_test.go index 43f7842..e703838 100644 --- a/configtx/policies_test.go +++ b/configtx/policies_test.go @@ -81,10 +81,11 @@ func TestRemoveApplicationOrgPolicy(t *testing.T) { expectedOrgConfigGroup, _ := newOrgConfigGroup(application.Organizations[0]) expectedPolicies := expectedOrgConfigGroup.Policies - err := c.UpdatedConfig().Application().Organization("Org1").RemovePolicy("TestPolicy") + applicationOrg1 := c.Application().Organization("Org1") + err := applicationOrg1.RemovePolicy("TestPolicy") gt.Expect(err).NotTo(HaveOccurred()) - actualOrg1Policies := c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Groups["Org1"].Policies + actualOrg1Policies := applicationOrg1.orgGroup.Policies gt.Expect(actualOrg1Policies).To(Equal(expectedPolicies)) } @@ -115,7 +116,7 @@ func TestRemoveApplicationOrgPolicyFailures(t *testing.T) { c := New(config) - err := c.UpdatedConfig().Application().Organization("Org1").RemovePolicy("TestPolicy") + err := c.Application().Organization("Org1").RemovePolicy("TestPolicy") gt.Expect(err).To(MatchError("unknown policy type: 15")) } @@ -148,10 +149,12 @@ func TestSetApplicationOrgPolicy(t *testing.T) { expectedPolicies := expectedOrgConfigGroup.Policies expectedPolicies["TestPolicy"] = expectedPolicies[EndorsementPolicyKey] - err := c.UpdatedConfig().Application().Organization("Org1").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) + applicationOrg1 := c.Application().Organization("Org1") + err := applicationOrg1.SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) - actualOrg1Policies := c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Groups["Org1"].Policies + actualOrg1Policies := applicationOrg1.orgGroup.Policies + gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(actualOrg1Policies).To(Equal(expectedPolicies)) } @@ -178,7 +181,7 @@ func TestSetApplicationOrgPolicyFailures(t *testing.T) { c := New(config) - err := c.UpdatedConfig().Application().Organization("Org1").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) + err := c.Application().Organization("Org1").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) gt.Expect(err).To(MatchError("failed to set policy 'TestPolicy': unknown policy type: ")) } @@ -218,10 +221,11 @@ func TestSetApplicationPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Application().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) + a := c.Application() + err = a.SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) - updatedPolicies, err := getPolicies(c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Policies) + updatedPolicies, err := a.Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -246,7 +250,7 @@ func TestSetApplicationPolicyFailures(t *testing.T) { expectedPolicies := application.Policies expectedPolicies["TestPolicy"] = expectedPolicies[EndorsementPolicyKey] - err = c.UpdatedConfig().Application().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) + err = c.Application().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) gt.Expect(err).To(MatchError("failed to set policy 'TestPolicy': unknown policy type: ")) } @@ -283,10 +287,11 @@ func TestRemoveApplicationPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Application().RemovePolicy("TestPolicy") + a := c.Application() + err = a.RemovePolicy("TestPolicy") gt.Expect(err).NotTo(HaveOccurred()) - updatedPolicies, err := getPolicies(c.UpdatedConfig().ChannelGroup.Groups[ApplicationGroupKey].Policies) + updatedPolicies, err := a.Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -314,7 +319,7 @@ func TestRemoveApplicationPolicyFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Application().RemovePolicy("TestPolicy") + err = c.Application().RemovePolicy("TestPolicy") gt.Expect(err).To(MatchError("unknown policy type: 15")) } @@ -361,7 +366,7 @@ func TestSetConsortiumOrgPolicy(t *testing.T) { }, } - consortium1Org1 := c.UpdatedConfig().Consortiums().Consortium("Consortium1").Organization("Org1") + consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") err = consortium1Org1.SetPolicy("TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) @@ -405,7 +410,7 @@ func TestSetConsortiumOrgPolicyFailures(t *testing.T) { expectedErr: "failed to set policy 'TestPolicy' to consortium org 'Org1': unknown policy type: ", }, } { - err := c.UpdatedConfig().Consortiums().Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy) + err := c.Consortiums().Consortium(test.consortium).Organization(test.org).SetPolicy("TestPolicy", test.policy) gt.Expect(err).To(MatchError(test.expectedErr)) } } @@ -451,7 +456,7 @@ func TestRemoveConsortiumOrgPolicy(t *testing.T) { }, } - consortium1Org1 := c.UpdatedConfig().Consortiums().Consortium("Consortium1").Organization("Org1") + consortium1Org1 := c.Consortiums().Consortium("Consortium1").Organization("Org1") consortium1Org1.RemovePolicy("TestPolicy") updatedPolicies, err := consortium1Org1.Policies() @@ -502,10 +507,10 @@ func TestSetOrdererPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Orderer().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Endorsement"}) + err = c.Orderer().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) - updatedPolicies, err := c.UpdatedConfig().Orderer().Policies() + updatedPolicies, err := c.Orderer().Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -530,7 +535,7 @@ func TestSetOrdererPolicyFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Orderer().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) + err = c.Orderer().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) gt.Expect(err).To(MatchError("failed to set policy 'TestPolicy': unknown policy type: ")) } @@ -574,10 +579,10 @@ func TestRemoveOrdererPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Orderer().RemovePolicy("TestPolicy") + err = c.Orderer().RemovePolicy("TestPolicy") gt.Expect(err).NotTo(HaveOccurred()) - updatedPolicies, err := c.UpdatedConfig().Orderer().Policies() + updatedPolicies, err := c.Orderer().Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -631,7 +636,7 @@ func TestRemoveOrdererPolicyFailures(t *testing.T) { config.ChannelGroup.Groups[OrdererGroupKey] = ordererGroup } - err = c.UpdatedConfig().Orderer().RemovePolicy(tt.policyName) + err = c.Orderer().RemovePolicy(tt.policyName) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -680,11 +685,11 @@ func TestSetOrdererOrgPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Endorsement"}) + ordererOrg := c.Orderer().Organization("OrdererOrg") + err = ordererOrg.SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Endorsement"}) gt.Expect(err).NotTo(HaveOccurred()) - ordererOrgConfigGroup := c.UpdatedConfig().ChannelGroup.Groups[OrdererGroupKey].Groups["OrdererOrg"] - updatedPolicies, err := getPolicies(ordererOrgConfigGroup.Policies) + updatedPolicies, err := ordererOrg.Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -709,7 +714,7 @@ func TestSetOrdererOrgPolicyFailures(t *testing.T) { c := New(config) - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) + err = c.Orderer().Organization("OrdererOrg").SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{}) gt.Expect(err).To(MatchError("unknown policy type: ")) } @@ -753,10 +758,10 @@ func TestRemoveOrdererOrgPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").RemovePolicy("TestPolicy") + err = c.Orderer().Organization("OrdererOrg").RemovePolicy("TestPolicy") gt.Expect(err).NotTo(HaveOccurred()) - updatedPolicies, err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").Policies() + updatedPolicies, err := c.Orderer().Organization("OrdererOrg").Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedPolicies).To(Equal(expectedPolicies)) } @@ -783,7 +788,7 @@ func TestSetConsortiumChannelCreationPolicy(t *testing.T) { updatedPolicy := Policy{Type: ImplicitMetaPolicyType, Rule: "MAJORITY Admins"} - consortium1 := c.UpdatedConfig().Consortiums().Consortium("Consortium1") + consortium1 := c.Consortiums().Consortium("Consortium1") err = consortium1.SetChannelCreationPolicy(updatedPolicy) gt.Expect(err).NotTo(HaveOccurred()) @@ -836,7 +841,7 @@ func TestSetConsortiumChannelCreationPolicyFailures(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { gt := NewGomegaWithT(t) - err := c.UpdatedConfig().Consortiums().Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy) + err := c.Consortiums().Consortium(tt.consortiumName).SetChannelCreationPolicy(tt.updatedpolicy) gt.Expect(err).To(MatchError(tt.expectedErr)) }) } @@ -858,7 +863,7 @@ func TestSetChannelPolicy(t *testing.T) { "TestPolicy": {Type: ImplicitMetaPolicyType, Rule: "ANY Readers"}, } - err = c.UpdatedConfig().Channel().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Readers"}) + err = c.Channel().SetPolicy(AdminsPolicyKey, "TestPolicy", Policy{Type: ImplicitMetaPolicyType, Rule: "ANY Readers"}) gt.Expect(err).NotTo(HaveOccurred()) updatedChannelPolicy, err := getPolicies(c.updated.ChannelGroup.Policies) @@ -896,14 +901,14 @@ func TestRemoveChannelPolicy(t *testing.T) { }, } - err = c.UpdatedConfig().Channel().RemovePolicy(ReadersPolicyKey) + err = c.Channel().RemovePolicy(ReadersPolicyKey) gt.Expect(err).NotTo(HaveOccurred()) - updatedChannelPolicy, err := getPolicies(c.UpdatedConfig().ChannelGroup.Policies) + updatedChannelPolicy, err := c.Channel().Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(updatedChannelPolicy).To(Equal(expectedPolicies)) - originalChannel := c.OriginalConfig().ChannelGroup + originalChannel := c.original.ChannelGroup gt.Expect(originalChannel.Policies).To(HaveLen(3)) gt.Expect(originalChannel.Policies[ReadersPolicyKey]).ToNot(BeNil()) } @@ -928,7 +933,7 @@ func TestRemoveChannelPolicyFailures(t *testing.T) { } c := New(config) - err = c.UpdatedConfig().Channel().RemovePolicy(ReadersPolicyKey) + err = c.Channel().RemovePolicy(ReadersPolicyKey) gt.Expect(err).To(MatchError("unknown policy type: 15")) } @@ -971,7 +976,7 @@ func TestConsortiumOrgPolicies(t *testing.T) { }, } - policies, err := c.UpdatedConfig().Consortiums().Consortium("Consortium1").Organization("Org1").Policies() + policies, err := c.Consortiums().Consortium("Consortium1").Organization("Org1").Policies() gt.Expect(err).NotTo(HaveOccurred()) gt.Expect(policies).To(Equal(expectedPolicies)) }