Skip to content

Commit

Permalink
Run gofumpt and apply consistent style to tree
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Feb 23, 2021
1 parent 71abb8e commit 7789882
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 63 deletions.
1 change: 0 additions & 1 deletion configtx/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (a *ApplicationGroup) Configuration() (Application, error) {
var applicationOrgs []Organization
for orgName := range a.applicationGroup.Groups {
orgConfig, err := a.Organization(orgName).Configuration()

if err != nil {
return Application{}, fmt.Errorf("retrieving application org %s: %v", orgName, err)
}
Expand Down
6 changes: 4 additions & 2 deletions configtx/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1795,8 +1795,10 @@ func TestSetApplicationOrgPolicy(t *testing.T) {
}

applicationOrg1 := c.Application().Organization("Org1")
err = applicationOrg1.SetPolicy("TestPolicy", Policy{Type: SignaturePolicyType,
Rule: "OR('Org1MSP.admin', 'Org1MSP.peer','Org1MSP.client')"})
err = applicationOrg1.SetPolicy("TestPolicy", Policy{
Type: SignaturePolicyType,
Rule: "OR('Org1MSP.admin', 'Org1MSP.peer','Org1MSP.client')",
})
gt.Expect(err).NotTo(HaveOccurred())

actualOrg1Policies := applicationOrg1.orgGroup.Policies
Expand Down
29 changes: 16 additions & 13 deletions configtx/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func Example_basic() {
baseConfig := fetchSystemChannelConfig()
c := configtx.New(baseConfig)

err := c.Consortium("SampleConsortium").SetChannelCreationPolicy(
configtx.Policy{Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Admins"})
err := c.Consortium("SampleConsortium").SetChannelCreationPolicy(configtx.Policy{
Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Admins",
})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -156,7 +157,6 @@ func ExampleOrdererGroup_SetConfiguration() {
if err != nil {
panic(nil)
}

}

// This example shows the addition and removal of ACLs.
Expand Down Expand Up @@ -436,7 +436,8 @@ func ExampleOrdererGroup_SetConfiguration_individual() {
panic(err)
}

err = o.AddConsenter(orderer.Consenter{Address: orderer.EtcdAddress{Host: "host1", Port: 7050},
err = o.AddConsenter(orderer.Consenter{
Address: orderer.EtcdAddress{Host: "host1", Port: 7050},
ClientTLSCert: generateCert(),
ServerTLSCert: generateCert(),
})
Expand Down Expand Up @@ -588,9 +589,11 @@ func ExampleNewApplicationChannelGenesisBlock() {
},
EtcdRaft: orderer.EtcdRaft{
Consenters: []orderer.Consenter{
{Address: orderer.EtcdAddress{
Host: "host1",
Port: 7050},
{
Address: orderer.EtcdAddress{
Host: "host1",
Port: 7050,
},
ClientTLSCert: generateCert(),
ServerTLSCert: generateCert(),
},
Expand Down Expand Up @@ -854,7 +857,6 @@ func ExampleConsortiumOrg_SetMSP() {
}

func ExampleOrdererGroup_RemoveLegacyKafkaBrokers() {

baseConfig := fetchChannelConfig()
c := configtx.New(baseConfig)
ordererConfig, err := c.Orderer().Configuration()
Expand All @@ -864,9 +866,11 @@ func ExampleOrdererGroup_RemoveLegacyKafkaBrokers() {
ordererConfig.OrdererType = orderer.ConsensusTypeEtcdRaft
ordererConfig.EtcdRaft = orderer.EtcdRaft{
Consenters: []orderer.Consenter{
{Address: orderer.EtcdAddress{
Host: "host1",
Port: 7050},
{
Address: orderer.EtcdAddress{
Host: "host1",
Port: 7050,
},
ClientTLSCert: generateCert(),
ServerTLSCert: generateCert(),
},
Expand Down Expand Up @@ -1167,7 +1171,6 @@ func createSigningIdentity() configtx.SigningIdentity {
func generateCert() *x509.Certificate {
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)

if err != nil {
log.Fatalf("Failed to generate serial number: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion configtx/internal/policydsl/policyparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func secondPass(args ...interface{}) (interface{}, error) {
}

/* get the n in the t out of n */
var n = len(args) - 2
n := len(args) - 2

/* sanity check - t should be positive, permit equal to n+1, but disallow over n+1 */
if t < 0 || t > n+1 {
Expand Down
84 changes: 56 additions & 28 deletions configtx/internal/policydsl/policyparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ func TestOutOf1(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -52,11 +54,13 @@ func TestOutOf2(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -77,11 +81,13 @@ func TestAnd(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -102,11 +108,13 @@ func TestAndClientPeerOrderer(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_CLIENT, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_CLIENT, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_PEER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_PEER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -127,11 +135,13 @@ func TestOr(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -152,15 +162,18 @@ func TestComplex1(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "C"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "C"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -181,19 +194,23 @@ func TestComplex2(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ADMIN, MspIdentifier: "C"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ADMIN, MspIdentifier: "C"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "D"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "D"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -214,15 +231,18 @@ func TestMSPIDWIthSpecialChars(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP.WITH.DOTS"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP.WITH.DOTS"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP-WITH-DASHES"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "MSP-WITH-DASHES"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand Down Expand Up @@ -256,19 +276,23 @@ func TestNodeOUs(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_PEER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_PEER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ADMIN, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ADMIN, MspIdentifier: "B"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ORDERER, MspIdentifier: "C"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_ORDERER, MspIdentifier: "C"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_CLIENT, MspIdentifier: "D"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_CLIENT, MspIdentifier: "D"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -289,11 +313,13 @@ func TestOutOfNumIsString(t *testing.T) {

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})

principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})

p2 := &cb.SignaturePolicyEnvelope{
Version: 0,
Expand Down Expand Up @@ -418,10 +444,12 @@ func TestSecondPassBoundaryCheck(t *testing.T) {
principals := make([]*mb.MSPPrincipal, 0)
principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "A"}),
})
principals = append(principals, &mb.MSPPrincipal{
PrincipalClassification: mb.MSPPrincipal_ROLE,
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"})})
Principal: protoMarshalOrPanic(&mb.MSPRole{Role: mb.MSPRole_MEMBER, MspIdentifier: "B"}),
})
expected1 := &cb.SignaturePolicyEnvelope{
Version: 0,
Rule: policydsl.NOutOf(0, []*cb.SignaturePolicy{policydsl.SignedBy(0), policydsl.SignedBy(1)}),
Expand Down
2 changes: 1 addition & 1 deletion configtx/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (m *MSP) validateCACerts() error {
return fmt.Errorf("invalid intermediate cert: %v", err)
}

//TODO: follow the workaround that msp code use to incorporate cert.Verify()
// TODO: follow the workaround that msp code use to incorporate cert.Verify()
for _, ic := range m.IntermediateCerts {
validIntermediateCert := false
for _, rc := range m.RootCerts {
Expand Down
2 changes: 0 additions & 2 deletions configtx/msp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ func TestAddRootCertFailure(t *testing.T) {
msp, err := c.Orderer().Organization("OrdererOrg").MSP().Configuration()
err = ordererMSP.AddRootCert(msp.RootCerts[0])
gt.Expect(err).To(MatchError("config does not contain value for MSP"))

}

func TestRemoveRootCert(t *testing.T) {
Expand Down Expand Up @@ -1440,5 +1439,4 @@ func certCRLBase64(t *testing.T, msp MSP) (string, string) {
crlBase64 := base64.StdEncoding.EncodeToString(pemCRLBytes[0])

return certBase64, crlBase64

}
1 change: 0 additions & 1 deletion configtx/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ func (o *OrdererGroup) SetPolicy(policyName string, policy Policy) error {
// SetPolicies sets the specified policy in the orderer group's config policy map.
// If the policies already exist in current configuration, the values will be replaced with new policies.
func (o *OrdererGroup) SetPolicies(policies map[string]Policy) error {

if _, ok := policies[BlockValidationPolicyKey]; !ok {
return errors.New("BlockValidation policy must be defined")
}
Expand Down
Loading

0 comments on commit 7789882

Please sign in to comment.