Skip to content

Commit

Permalink
[FAB-17038] Update peer.ApplicationPolicy references
Browse files Browse the repository at this point in the history
* peer.ApplicationPolicy -> common.ApplicationPolicy
* Per protos update in FAB-15066

Change-Id: I16641b4d80624cf47a4e68f5cb969583d12bb9cd
Signed-off-by: Danny Cao <dcao@us.ibm.com>
  • Loading branch information
caod123 committed Nov 14, 2019
1 parent 048351a commit 3ec743b
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 50 deletions.
5 changes: 2 additions & 3 deletions core/chaincode/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"

cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/flogging"
Expand Down Expand Up @@ -48,8 +47,8 @@ const (
)

var (
DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: DefaultEndorsementPolicyRef,
},
})
Expand Down
13 changes: 6 additions & 7 deletions core/chaincode/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/channelconfig"
Expand Down Expand Up @@ -610,8 +609,8 @@ var _ = Describe("ExternalFunctions", func() {
Expect(proto.Equal(committedDefinition.ValidationInfo, &lb.ChaincodeValidationInfo{
ValidationPlugin: "vscc",
ValidationParameter: protoutil.MarshalOrPanic(
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
}),
Expand Down Expand Up @@ -876,8 +875,8 @@ var _ = Describe("ExternalFunctions", func() {
testDefinition.EndorsementInfo.EndorsementPlugin = "escc"
testDefinition.ValidationInfo.ValidationPlugin = "vscc"
testDefinition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
})
Expand Down Expand Up @@ -1045,8 +1044,8 @@ var _ = Describe("ExternalFunctions", func() {
testDefinition.EndorsementInfo.EndorsementPlugin = "escc"
testDefinition.ValidationInfo.ValidationPlugin = "vscc"
testDefinition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
})
Expand Down
8 changes: 4 additions & 4 deletions core/chaincode/lifecycle/metadata_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/policies"
Expand Down Expand Up @@ -72,16 +72,16 @@ type MetadataProvider struct {
}

func (mp *MetadataProvider) toSignaturePolicyEnvelope(channelID string, policyBytes []byte) ([]byte, error) {
p := &peer.ApplicationPolicy{}
p := &common.ApplicationPolicy{}
err := proto.Unmarshal(policyBytes, p)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal ApplicationPolicy bytes")
}

switch policy := p.Type.(type) {
case *peer.ApplicationPolicy_SignaturePolicy:
case *common.ApplicationPolicy_SignaturePolicy:
return protoutil.MarshalOrPanic(policy.SignaturePolicy), nil
case *peer.ApplicationPolicy_ChannelConfigPolicyReference:
case *common.ApplicationPolicy_ChannelConfigPolicyReference:
p, err := mp.ChannelPolicyReferenceProvider.NewPolicy(channelID, policy.ChannelConfigPolicyReference)
if err != nil {
return nil, errors.WithMessagef(err, "could not retrieve policy for reference '%s' on channel '%s'", policy.ChannelConfigPolicyReference, channelID)
Expand Down
9 changes: 4 additions & 5 deletions core/chaincode/lifecycle/metadata_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hyperledger/fabric/core/chaincode/lifecycle/mock"
"github.com/pkg/errors"

"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/protoutil"
. "github.com/onsi/ginkgo"
Expand All @@ -40,8 +39,8 @@ var _ = Describe("MetadataProvider", func() {
Version: "cc-version",
},
ValidationInfo: &lb.ChaincodeValidationInfo{
ValidationParameter: protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
ValidationParameter: protoutil.MarshalOrPanic(&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: cauthdsl.AcceptAllPolicy,
},
}),
Expand Down Expand Up @@ -115,8 +114,8 @@ var _ = Describe("MetadataProvider", func() {
Context("when the policy is of the channel reference type", func() {
BeforeEach(func() {
ccInfo.Definition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_ChannelConfigPolicyReference{
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "barf",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
tmocks "github.com/hyperledger/fabric/core/committer/txvalidator/mocks"
"github.com/hyperledger/fabric/core/committer/txvalidator/plugin"
Expand Down Expand Up @@ -108,7 +107,7 @@ func TestSamplePlugin(t *testing.T) {
txnData, _ := proto.Marshal(&transaction)

v := plugindispatcher.NewPluginValidator(pm, qec, deserializer, capabilities, mcpmg, nil)
acceptAllPolicyBytes, _ := proto.Marshal(&peer.ApplicationPolicy{Type: &peer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.AcceptAllPolicy}})
acceptAllPolicyBytes, _ := proto.Marshal(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.AcceptAllPolicy}})
ctx := &plugindispatcher.Context{
Namespace: "mycc",
PluginName: "vscc",
Expand Down
6 changes: 3 additions & 3 deletions core/committer/txvalidator/v20/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (

func signedByAnyMember(ids []string) []byte {
p := cauthdsl.SignedByAnyMember(ids)
return protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: p}})
return protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: p}})
}

func v20Capabilities() *tmocks.ApplicationCapabilities {
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestParallelValidation(t *testing.T) {
mockCR.On("CollectionValidationInfo", ccID, "col1", mock.Anything).Return(nil, nil, nil)

policy := cauthdsl.SignedByMspPeer("Org1")
polBytes := protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: policy}})
polBytes := protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: policy}})
mockQE.On("GetState", "lscc", ccID).Return(protoutil.MarshalOrPanic(&ccp.ChaincodeData{
Name: ccID,
Version: ccVersion,
Expand Down Expand Up @@ -927,7 +927,7 @@ func TestValidateTxWithStateBasedEndorsement(t *testing.T) {
Vscc: "vscc",
Policy: signedByAnyMember([]string{"SampleOrg"}),
}), nil)
mockQE.On("GetStateMetadata", ccID, "key").Return(map[string][]byte{peer.MetaDataKeys_VALIDATION_PARAMETER.String(): protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.RejectAllPolicy}})}, nil)
mockQE.On("GetStateMetadata", ccID, "key").Return(map[string][]byte{peer.MetaDataKeys_VALIDATION_PARAMETER.String(): protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.RejectAllPolicy}})}, nil)

tx := getEnv(ccID, nil, createRWset(t, ccID), t)
b := &common.Block{Data: &common.BlockData{Data: [][]byte{protoutil.MarshalOrPanic(tx)}}, Header: &common.BlockHeader{Number: 3}}
Expand Down
5 changes: 2 additions & 3 deletions core/committer/txvalidator/v20/valinforetriever/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package valinforetriever
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/core/committer/txvalidator/v20/plugindispatcher"
"github.com/hyperledger/fabric/core/ledger"
)
Expand Down Expand Up @@ -65,8 +64,8 @@ func (v *ValidationInfoRetrieveShim) ValidationInfo(channelID, chaincodeName str
}

newArgs, err := proto.Marshal(
&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spe,
},
},
Expand Down
5 changes: 2 additions & 3 deletions core/committer/txvalidator/v20/valinforetriever/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/protoutil"

"github.com/hyperledger/fabric/core/committer/txvalidator/v20/valinforetriever"
Expand Down Expand Up @@ -144,8 +143,8 @@ func TestValidationInfoRetrieverFromLegacyWithConversion(t *testing.T) {
assert.NoError(t, unexpectedErr)
assert.NoError(t, validationErr)
assert.Equal(t, "vscc", plugin)
assert.Equal(t, protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
assert.Equal(t, protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: &common.SignaturePolicyEnvelope{Version: 1},
},
}), args)
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v20/validation_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (n *toApplicationPolicyTranslator) Translate(b []byte) ([]byte, error) {
return nil, errors.Wrap(err, "could not unmarshal signature policy envelope")
}

return protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
return protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spe,
},
}), nil
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v20/validation_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func TestToApplicationPolicyTranslator_Translate(t *testing.T) {

res, err = tr.Translate(protoutil.MarshalOrPanic(cauthdsl.SignedByMspMember("the right honourable member for Ipswich")))
assert.NoError(t, err)
assert.Equal(t, res, protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
assert.Equal(t, res, protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: cauthdsl.SignedByMspMember("the right honourable member for Ipswich"),
},
}))
Expand Down
7 changes: 3 additions & 4 deletions core/policy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package policy
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
Expand Down Expand Up @@ -146,16 +145,16 @@ func (a *ApplicationPolicyEvaluator) evaluateChannelConfigPolicyReference(channe
}

func (a *ApplicationPolicyEvaluator) Evaluate(policyBytes []byte, signatureSet []*protoutil.SignedData) error {
p := &peer.ApplicationPolicy{}
p := &common.ApplicationPolicy{}
err := proto.Unmarshal(policyBytes, p)
if err != nil {
return errors.Wrap(err, "failed to unmarshal ApplicationPolicy bytes")
}

switch policy := p.Type.(type) {
case *peer.ApplicationPolicy_SignaturePolicy:
case *common.ApplicationPolicy_SignaturePolicy:
return a.evaluateSignaturePolicy(policy.SignaturePolicy, signatureSet)
case *peer.ApplicationPolicy_ChannelConfigPolicyReference:
case *common.ApplicationPolicy_ChannelConfigPolicyReference:
return a.evaluateChannelConfigPolicyReference(policy.ChannelConfigPolicyReference, signatureSet)
default:
return errors.Errorf("unsupported policy type %T", policy)
Expand Down
13 changes: 6 additions & 7 deletions core/policy/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/core/policy/mocks"
"github.com/hyperledger/fabric/msp"
Expand All @@ -32,8 +31,8 @@ func TestComponentIntegrationSignaturePolicyEnv(t *testing.T) {
}

spenv := cauthdsl.SignedByMspMember("msp")
mspenv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
mspenv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spenv,
},
})
Expand Down Expand Up @@ -79,8 +78,8 @@ func TestEvaluator(t *testing.T) {
// SCENARIO: signature policy supplied - good and bad path

spenv := &common.SignaturePolicyEnvelope{}
mspenv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
mspenv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spenv,
},
})
Expand All @@ -99,8 +98,8 @@ func TestEvaluator(t *testing.T) {
// SCENARIO: channel ref policy supplied - good and bad path

chrefstr := "Quo usque tandem abutere, Catilina, patientia nostra?"
chrefstrEnv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_ChannelConfigPolicyReference{
chrefstrEnv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: chrefstr,
},
})
Expand Down
10 changes: 5 additions & 5 deletions internal/peer/lifecycle/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ func createPolicyBytes(signaturePolicy, channelConfigPolicy string) ([]byte, err
return nil, errors.New("cannot specify both \"--signature-policy\" and \"--channel-config-policy\"")
}

var applicationPolicy *pb.ApplicationPolicy
var applicationPolicy *cb.ApplicationPolicy
if signaturePolicy != "" {
signaturePolicyEnvelope, err := cauthdsl.FromString(signaturePolicy)
if err != nil {
return nil, errors.Errorf("invalid signature policy: %s", signaturePolicy)
}

applicationPolicy = &pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_SignaturePolicy{
applicationPolicy = &cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: signaturePolicyEnvelope,
},
}
}

if channelConfigPolicy != "" {
applicationPolicy = &pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
applicationPolicy = &cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: channelConfigPolicy,
},
}
Expand Down

0 comments on commit 3ec743b

Please sign in to comment.