From 60534bc6f0a79a5a54ee75527cfdc0386b26b55e Mon Sep 17 00:00:00 2001 From: Will Lahti Date: Wed, 6 Mar 2019 14:40:05 -0500 Subject: [PATCH] Add channel config policy ref to _lifecycle CLI Also, similar refactor for collection config package creation. FAB-14517 #done Change-Id: I543302588cd4379c7b2cf6d79d6aa41268d56bb5 Signed-off-by: Will Lahti Signed-off-by: Alessandro Sorniotti --- integration/nwo/commands/peer.go | 58 +++++++------- integration/nwo/deploy.go | 80 ++++++++++--------- integration/nwo/network_test.go | 27 ++++--- integration/pvtdata/pvtdata_test.go | 4 +- .../lifecycle/chaincode/approveformyorg.go | 41 ++-------- .../chaincode/approveformyorg_test.go | 50 +++++++++++- .../peer/lifecycle/chaincode/chaincode.go | 8 +- internal/peer/lifecycle/chaincode/commit.go | 41 ++-------- .../peer/lifecycle/chaincode/commit_test.go | 4 +- internal/peer/lifecycle/chaincode/common.go | 54 +++++++++++++ .../chaincode/queryapprovalstatus.go | 35 ++------ .../chaincode/queryapprovalstatus_test.go | 6 +- 12 files changed, 223 insertions(+), 185 deletions(-) diff --git a/integration/nwo/commands/peer.go b/integration/nwo/commands/peer.go index de4fd580e97..856354dcfa3 100644 --- a/integration/nwo/commands/peer.go +++ b/integration/nwo/commands/peer.go @@ -193,19 +193,20 @@ func (c ChaincodeInstall) Args() []string { } type ChaincodeApproveForMyOrgLifecycle struct { - ChannelID string - Orderer string - Name string - Version string - PackageID string - Sequence string - EndorsementPlugin string - ValidationPlugin string - Policy string - InitRequired bool - CollectionsConfig string - PeerAddresses []string - WaitForEvent bool + ChannelID string + Orderer string + Name string + Version string + PackageID string + Sequence string + EndorsementPlugin string + ValidationPlugin string + SignaturePolicy string + ChannelConfigPolicy string + InitRequired bool + CollectionsConfig string + PeerAddresses []string + WaitForEvent bool } func (c ChaincodeApproveForMyOrgLifecycle) SessionName() string { @@ -223,7 +224,8 @@ func (c ChaincodeApproveForMyOrgLifecycle) Args() []string { "--sequence", c.Sequence, "--escc", c.EndorsementPlugin, "--vscc", c.ValidationPlugin, - "--policy", c.Policy, + "--signature-policy", c.SignaturePolicy, + "--channel-config-policy", c.ChannelConfigPolicy, } if c.InitRequired { @@ -246,18 +248,19 @@ func (c ChaincodeApproveForMyOrgLifecycle) Args() []string { } type ChaincodeCommitLifecycle struct { - ChannelID string - Orderer string - Name string - Version string - Sequence string - EndorsementPlugin string - ValidationPlugin string - Policy string - InitRequired bool - CollectionsConfig string - PeerAddresses []string - WaitForEvent bool + ChannelID string + Orderer string + Name string + Version string + Sequence string + EndorsementPlugin string + ValidationPlugin string + SignaturePolicy string + ChannelConfigPolicy string + InitRequired bool + CollectionsConfig string + PeerAddresses []string + WaitForEvent bool } func (c ChaincodeCommitLifecycle) SessionName() string { @@ -274,7 +277,8 @@ func (c ChaincodeCommitLifecycle) Args() []string { "--sequence", c.Sequence, "--escc", c.EndorsementPlugin, "--vscc", c.ValidationPlugin, - "--policy", c.Policy, + "--signature-policy", c.SignaturePolicy, + "--channel-config-policy", c.ChannelConfigPolicy, } if c.InitRequired { args = append(args, "--init-required") diff --git a/integration/nwo/deploy.go b/integration/nwo/deploy.go index b03fc4b7917..e48871fc4dc 100644 --- a/integration/nwo/deploy.go +++ b/integration/nwo/deploy.go @@ -24,20 +24,22 @@ import ( ) type Chaincode struct { - Name string - Version string - Path string - Ctor string - Policy string - Lang string - CollectionsConfig string // optional - PackageFile string - PackageID string // if unspecified, chaincode won't be executable - Sequence string - EndorsementPlugin string - ValidationPlugin string - InitRequired bool - Label string + Name string + Version string + Path string + Ctor string + Policy string + Lang string + CollectionsConfig string // optional + PackageFile string + PackageID string // if unspecified, chaincode won't be executable + Sequence string + EndorsementPlugin string + ValidationPlugin string + InitRequired bool + Label string + SignaturePolicy string + ChannelConfigPolicy string } // DeployChaincodeNewLifecycle is a helper that will install chaincode to all @@ -201,18 +203,19 @@ func ApproveChaincodeForMyOrgNewLifecycle(n *Network, channel string, orderer *O for _, p := range peers { if _, ok := approvedOrgs[p.Organization]; !ok { sess, err := n.PeerAdminSession(p, commands.ChaincodeApproveForMyOrgLifecycle{ - ChannelID: channel, - Orderer: n.OrdererAddress(orderer, ListenPort), - Name: chaincode.Name, - Version: chaincode.Version, - PackageID: chaincode.PackageID, - Sequence: chaincode.Sequence, - EndorsementPlugin: chaincode.EndorsementPlugin, - ValidationPlugin: chaincode.ValidationPlugin, - Policy: chaincode.Policy, - InitRequired: chaincode.InitRequired, - CollectionsConfig: chaincode.CollectionsConfig, - WaitForEvent: true, + ChannelID: channel, + Orderer: n.OrdererAddress(orderer, ListenPort), + Name: chaincode.Name, + Version: chaincode.Version, + PackageID: chaincode.PackageID, + Sequence: chaincode.Sequence, + EndorsementPlugin: chaincode.EndorsementPlugin, + ValidationPlugin: chaincode.ValidationPlugin, + SignaturePolicy: chaincode.SignaturePolicy, + ChannelConfigPolicy: chaincode.ChannelConfigPolicy, + InitRequired: chaincode.InitRequired, + CollectionsConfig: chaincode.CollectionsConfig, + WaitForEvent: true, }) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) @@ -234,18 +237,19 @@ func CommitChaincodeNewLifecycle(n *Network, channel string, orderer *Orderer, c } sess, err := n.PeerAdminSession(peer, commands.ChaincodeCommitLifecycle{ - ChannelID: channel, - Orderer: n.OrdererAddress(orderer, ListenPort), - Name: chaincode.Name, - Version: chaincode.Version, - Sequence: chaincode.Sequence, - EndorsementPlugin: chaincode.EndorsementPlugin, - ValidationPlugin: chaincode.ValidationPlugin, - Policy: chaincode.Policy, - InitRequired: chaincode.InitRequired, - CollectionsConfig: chaincode.CollectionsConfig, - PeerAddresses: peerAddresses, - WaitForEvent: true, + ChannelID: channel, + Orderer: n.OrdererAddress(orderer, ListenPort), + Name: chaincode.Name, + Version: chaincode.Version, + Sequence: chaincode.Sequence, + EndorsementPlugin: chaincode.EndorsementPlugin, + ValidationPlugin: chaincode.ValidationPlugin, + SignaturePolicy: chaincode.SignaturePolicy, + ChannelConfigPolicy: chaincode.ChannelConfigPolicy, + InitRequired: chaincode.InitRequired, + CollectionsConfig: chaincode.CollectionsConfig, + PeerAddresses: peerAddresses, + WaitForEvent: true, }) Expect(err).NotTo(HaveOccurred()) Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) diff --git a/integration/nwo/network_test.go b/integration/nwo/network_test.go index 1510587bc64..60a683b012b 100644 --- a/integration/nwo/network_test.go +++ b/integration/nwo/network_test.go @@ -97,18 +97,19 @@ var _ = Describe("Network", func() { peer := network.Peer("org1", "peer2") chaincode := nwo.Chaincode{ - Name: "mycc", - Version: "0.0", - Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd", - Lang: "golang", - PackageFile: filepath.Join(tempDir, "simplecc.tar.gz"), - Ctor: `{"Args":["init","a","100","b","200"]}`, - EndorsementPlugin: "escc", - ValidationPlugin: "vscc", - Policy: `AND ('Org1ExampleCom.member','Org2ExampleCom.member')`, - Sequence: "1", - InitRequired: true, - Label: "my_simple_chaincode", + Name: "mycc", + Version: "0.0", + Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd", + Lang: "golang", + PackageFile: filepath.Join(tempDir, "simplecc.tar.gz"), + Ctor: `{"Args":["init","a","100","b","200"]}`, + EndorsementPlugin: "escc", + ValidationPlugin: "vscc", + Policy: `AND ('Org1ExampleCom.member','Org2ExampleCom.member')`, + ChannelConfigPolicy: "/Channel/Application/Endorsement", + Sequence: "1", + InitRequired: true, + Label: "my_simple_chaincode", } network.CreateAndJoinChannels(orderer) @@ -264,7 +265,7 @@ var _ = Describe("Network", func() { Ctor: `{"Args":["init","a","100","b","200"]}`, EndorsementPlugin: "escc", ValidationPlugin: "vscc", - Policy: `AND ('Org1ExampleCom.member','Org2ExampleCom.member')`, + SignaturePolicy: `AND ('Org1ExampleCom.member','Org2ExampleCom.member')`, Sequence: "1", InitRequired: true, Label: "my_simple_chaincode", diff --git a/integration/pvtdata/pvtdata_test.go b/integration/pvtdata/pvtdata_test.go index 0a826028594..0ad4937c4da 100644 --- a/integration/pvtdata/pvtdata_test.go +++ b/integration/pvtdata/pvtdata_test.go @@ -665,7 +665,7 @@ var _ bool = Describe("PrivateData", func() { Lang: "golang", PackageFile: filepath.Join(testDir, "marbles-pvtdata.tar.gz"), Label: "marbles-private-2.0", - Policy: `OR ('Org1MSP.member','Org2MSP.member', 'Org3MSP.member')`, + SignaturePolicy: `OR ('Org1MSP.member','Org2MSP.member', 'Org3MSP.member')`, CollectionsConfig: filepath.Join("testdata", "collection_configs", "collections_config2.json"), Sequence: "1", } @@ -691,7 +691,7 @@ var _ bool = Describe("PrivateData", func() { By("upgrading chaincode to remove org3 from collectionMarbles") chaincode.Sequence = "2" - chaincode.Policy = `OR ('Org1MSP.member','Org2MSP.member')` + chaincode.SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')` chaincode.CollectionsConfig = filepath.Join("testdata", "collection_configs", "collections_config1.json") maxLedgerHeight := nwo.GetMaxLedgerHeight(network, "testchannel", peerAllThreeOrgs...) diff --git a/internal/peer/lifecycle/chaincode/approveformyorg.go b/internal/peer/lifecycle/chaincode/approveformyorg.go index 8d65fe382c6..0fbd936cb52 100644 --- a/internal/peer/lifecycle/chaincode/approveformyorg.go +++ b/internal/peer/lifecycle/chaincode/approveformyorg.go @@ -13,7 +13,6 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/internal/peer/chaincode" "github.com/hyperledger/fabric/internal/peer/common" "github.com/hyperledger/fabric/internal/peer/common/api" @@ -77,14 +76,6 @@ func (a *ApproveForMyOrgInput) Validate() error { return errors.New("The required parameter 'sequence' is empty. Rerun the command with --sequence flag") } - if a.EndorsementPlugin == "" { - a.EndorsementPlugin = "escc" - } - - if a.ValidationPlugin == "" { - a.ValidationPlugin = "vscc" - } - return nil } @@ -144,7 +135,8 @@ func ApproveForMyOrgCmd(a *ApproverForMyOrg) *cobra.Command { "sequence", "escc", "vscc", - "policy", + "signature-policy", + "channel-config-policy", "init-required", "collections-config", "peerAddresses", @@ -254,31 +246,14 @@ func (a *ApproverForMyOrg) Approve() error { // createInput creates the input struct based on the CLI flags func (a *ApproverForMyOrg) createInput() (*ApproveForMyOrgInput, error) { - var ( - policyBytes []byte - ccp *cb.CollectionConfigPackage - ) - - if policy != "" { - signaturePolicyEnvelope, err := cauthdsl.FromString(policy) - if err != nil { - return nil, errors.Errorf("invalid signature policy: %s", policy) - } - - applicationPolicy := &pb.ApplicationPolicy{ - Type: &pb.ApplicationPolicy_SignaturePolicy{ - SignaturePolicy: signaturePolicyEnvelope, - }, - } - policyBytes = protoutil.MarshalOrPanic(applicationPolicy) + policyBytes, err := createPolicyBytes(signaturePolicy, channelConfigPolicy) + if err != nil { + return nil, err } - if collectionsConfigFile != "" { - var err error - ccp, _, err = chaincode.GetCollectionConfigFromFile(collectionsConfigFile) - if err != nil { - return nil, errors.WithMessagef(err, "invalid collection configuration in file %s", collectionsConfigFile) - } + ccp, err := createCollectionConfigPackage(collectionsConfigFile) + if err != nil { + return nil, err } input := &ApproveForMyOrgInput{ diff --git a/internal/peer/lifecycle/chaincode/approveformyorg_test.go b/internal/peer/lifecycle/chaincode/approveformyorg_test.go index 60bb5712246..d49babdc835 100644 --- a/internal/peer/lifecycle/chaincode/approveformyorg_test.go +++ b/internal/peer/lifecycle/chaincode/approveformyorg_test.go @@ -327,7 +327,7 @@ var _ = Describe("ApproverForMyOrg", func() { "--sequence=1", "--peerAddresses=querypeer1", "--tlsRootCertFiles=tls1", - "--policy=AND ('Org1MSP.member','Org2MSP.member')", + "--signature-policy=AND ('Org1MSP.member','Org2MSP.member')", }) }) @@ -341,10 +341,54 @@ var _ = Describe("ApproverForMyOrg", func() { Expect(err.Error()).To(ContainSubstring("failed to retrieve endorser client")) }) - Context("when the policy is invalid", func() { + Context("when the channel config policy is specified", func() { BeforeEach(func() { + approveForMyOrgCmd = chaincode.ApproveForMyOrgCmd(nil) approveForMyOrgCmd.SetArgs([]string{ - "--policy=notapolicy", + "--channel-config-policy=/Channel/Application/Readers", + "--channelID=testchannel", + "--name=testcc", + "--version=testversion", + "--package-id=testpackageid", + "--sequence=1", + "--peerAddresses=querypeer1", + "--tlsRootCertFiles=tls1", + }) + }) + + It("sets up the approver for my org and attempts to approve the chaincode definition", func() { + err := approveForMyOrgCmd.Execute() + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("failed to retrieve endorser client")) + }) + }) + + Context("when a signature policy and channel config policy are both specified", func() { + BeforeEach(func() { + approveForMyOrgCmd.SetArgs([]string{ + "--signature-policy=a_policy", + "--channel-config-policy=anotha_policy", + "--channelID=testchannel", + "--name=testcc", + "--version=testversion", + "--package-id=testpackageid", + "--sequence=1", + "--peerAddresses=querypeer1", + "--tlsRootCertFiles=tls1", + }) + }) + + It("returns an error", func() { + err := approveForMyOrgCmd.Execute() + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal("cannot specify both \"--signature-policy\" and \"--channel-config-policy\"")) + }) + }) + + Context("when the signature policy is invalid", func() { + BeforeEach(func() { + approveForMyOrgCmd.SetArgs([]string{ + "--signature-policy=notapolicy", "--channelID=testchannel", "--name=testcc", "--version=testversion", diff --git a/internal/peer/lifecycle/chaincode/chaincode.go b/internal/peer/lifecycle/chaincode/chaincode.go index 4d5a35873d3..c5b29e23a38 100644 --- a/internal/peer/lifecycle/chaincode/chaincode.go +++ b/internal/peer/lifecycle/chaincode/chaincode.go @@ -58,12 +58,11 @@ var ( channelID string chaincodeVersion string packageLabel string - policy string + signaturePolicy string + channelConfigPolicy string escc string vscc string - policyMarshalled []byte collectionsConfigFile string - collectionConfigBytes []byte peerAddresses []string tlsRootCertFiles []string connectionProfilePath string @@ -100,7 +99,8 @@ func ResetFlags() { flags.StringVarP(&chaincodeVersion, "version", "v", "", "Version of the chaincode") flags.StringVarP(&packageLabel, "label", "", "", "The package label contains a human-readable description of the package") flags.StringVarP(&channelID, "channelID", "C", "", "The channel on which this command should be executed") - flags.StringVarP(&policy, "policy", "P", "", "The endorsement policy associated to this chaincode") + flags.StringVarP(&signaturePolicy, "signature-policy", "", "", "The endorsement policy associated to this chaincode specified as a signature policy") + flags.StringVarP(&channelConfigPolicy, "channel-config-policy", "", "", "The endorsement policy associated to this chaincode specified as a channel config policy reference") flags.StringVarP(&escc, "escc", "E", common.UndefinedParamValue, fmt.Sprint("The name of the endorsement system chaincode to be used for this chaincode")) flags.StringVarP(&vscc, "vscc", "V", common.UndefinedParamValue, diff --git a/internal/peer/lifecycle/chaincode/commit.go b/internal/peer/lifecycle/chaincode/commit.go index 54fc0ba3533..e6d2b832a13 100644 --- a/internal/peer/lifecycle/chaincode/commit.go +++ b/internal/peer/lifecycle/chaincode/commit.go @@ -13,7 +13,6 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/internal/peer/chaincode" "github.com/hyperledger/fabric/internal/peer/common" "github.com/hyperledger/fabric/internal/peer/common/api" @@ -77,14 +76,6 @@ func (c *CommitInput) Validate() error { return errors.New("The required parameter 'sequence' is empty. Rerun the command with --sequence flag") } - if c.EndorsementPlugin == "" { - c.EndorsementPlugin = "escc" - } - - if c.ValidationPlugin == "" { - c.ValidationPlugin = "vscc" - } - return nil } @@ -143,7 +134,8 @@ func CommitCmd(c *Committer) *cobra.Command { "sequence", "escc", "vscc", - "policy", + "signature-policy", + "channel-config-policy", "init-required", "collections-config", "peerAddresses", @@ -252,31 +244,14 @@ func (c *Committer) Commit() error { // createInput creates the input struct based on the CLI flags func (c *Committer) createInput() (*CommitInput, error) { - var ( - policyBytes []byte - ccp *cb.CollectionConfigPackage - ) - - if policy != "" { - signaturePolicyEnvelope, err := cauthdsl.FromString(policy) - if err != nil { - return nil, errors.Errorf("invalid signature policy: %s", policy) - } - - applicationPolicy := &pb.ApplicationPolicy{ - Type: &pb.ApplicationPolicy_SignaturePolicy{ - SignaturePolicy: signaturePolicyEnvelope, - }, - } - policyBytes = protoutil.MarshalOrPanic(applicationPolicy) + policyBytes, err := createPolicyBytes(signaturePolicy, channelConfigPolicy) + if err != nil { + return nil, err } - if collectionsConfigFile != "" { - var err error - ccp, _, err = chaincode.GetCollectionConfigFromFile(collectionsConfigFile) - if err != nil { - return nil, errors.WithMessage(err, fmt.Sprintf("invalid collection configuration in file %s", collectionsConfigFile)) - } + ccp, err := createCollectionConfigPackage(collectionsConfigFile) + if err != nil { + return nil, err } input := &CommitInput{ diff --git a/internal/peer/lifecycle/chaincode/commit_test.go b/internal/peer/lifecycle/chaincode/commit_test.go index 6a6c9ec4acc..96b3d3fc50b 100644 --- a/internal/peer/lifecycle/chaincode/commit_test.go +++ b/internal/peer/lifecycle/chaincode/commit_test.go @@ -325,7 +325,7 @@ var _ = Describe("Commit", func() { "--sequence=1", "--peerAddresses=querypeer1", "--tlsRootCertFiles=tls1", - "--policy=AND ('Org1MSP.member','Org2MSP.member')", + "--signature-policy=AND ('Org1MSP.member','Org2MSP.member')", }) }) @@ -342,7 +342,7 @@ var _ = Describe("Commit", func() { Context("when the policy is invalid", func() { BeforeEach(func() { commitCmd.SetArgs([]string{ - "--policy=notapolicy", + "--signature-policy=notapolicy", "--channelID=testchannel", "--name=testcc", "--version=testversion", diff --git a/internal/peer/lifecycle/chaincode/common.go b/internal/peer/lifecycle/chaincode/common.go index 5f39186d94c..e3b23b404fe 100644 --- a/internal/peer/lifecycle/chaincode/common.go +++ b/internal/peer/lifecycle/chaincode/common.go @@ -8,10 +8,15 @@ package chaincode import ( "context" + "fmt" "github.com/golang/protobuf/proto" + "github.com/hyperledger/fabric/common/cauthdsl" + "github.com/hyperledger/fabric/internal/peer/chaincode" ccapi "github.com/hyperledger/fabric/internal/peer/chaincode/api" + cb "github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric/protos/peer" + "github.com/hyperledger/fabric/protoutil" "github.com/pkg/errors" "google.golang.org/grpc" ) @@ -59,3 +64,52 @@ func signProposal(proposal *pb.Proposal, signer Signer) (*pb.SignedProposal, err Signature: signature, }, nil } + +func createPolicyBytes(signaturePolicy, channelConfigPolicy string) ([]byte, error) { + if signaturePolicy == "" && channelConfigPolicy == "" { + // no policy, no problem + return nil, nil + } + + if signaturePolicy != "" && channelConfigPolicy != "" { + // mo policies, mo problems + return nil, errors.New("cannot specify both \"--signature-policy\" and \"--channel-config-policy\"") + } + + var applicationPolicy *pb.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{ + SignaturePolicy: signaturePolicyEnvelope, + }, + } + } + + if channelConfigPolicy != "" { + applicationPolicy = &pb.ApplicationPolicy{ + Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{ + ChannelConfigPolicyReference: channelConfigPolicy, + }, + } + } + + policyBytes := protoutil.MarshalOrPanic(applicationPolicy) + return policyBytes, nil +} + +func createCollectionConfigPackage(collectionsConfigFile string) (*cb.CollectionConfigPackage, error) { + var ccp *cb.CollectionConfigPackage + if collectionsConfigFile != "" { + var err error + ccp, _, err = chaincode.GetCollectionConfigFromFile(collectionsConfigFile) + if err != nil { + return nil, errors.WithMessage(err, fmt.Sprintf("invalid collection configuration in file %s", collectionsConfigFile)) + } + } + return ccp, nil +} diff --git a/internal/peer/lifecycle/chaincode/queryapprovalstatus.go b/internal/peer/lifecycle/chaincode/queryapprovalstatus.go index 075f46acd51..32e05cd4e27 100644 --- a/internal/peer/lifecycle/chaincode/queryapprovalstatus.go +++ b/internal/peer/lifecycle/chaincode/queryapprovalstatus.go @@ -14,8 +14,6 @@ import ( "os" "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric/common/cauthdsl" - "github.com/hyperledger/fabric/internal/peer/chaincode" "github.com/hyperledger/fabric/internal/pkg/identity" cb "github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric/protos/peer" @@ -111,11 +109,11 @@ func queryApprovalStatusCmd(a *QueryApprovalStatus) *cobra.Command { "channelID", "name", "version", - "package-id", "sequence", "escc", "vscc", - "policy", + "signature-policy", + "channel-config-policy", "init-required", "collections-config", "peerAddresses", @@ -199,31 +197,14 @@ func printQueryApprovalStatusResponse(proposalResponse *pb.ProposalResponse, out // setInput sets the input struct based on the CLI flags func (a *QueryApprovalStatus) setInput() error { - var ( - policyBytes []byte - ccp *cb.CollectionConfigPackage - ) - - if policy != "" { - signaturePolicyEnvelope, err := cauthdsl.FromString(policy) - if err != nil { - return errors.Errorf("invalid signature policy: %s", policy) - } - - applicationPolicy := &pb.ApplicationPolicy{ - Type: &pb.ApplicationPolicy_SignaturePolicy{ - SignaturePolicy: signaturePolicyEnvelope, - }, - } - policyBytes = protoutil.MarshalOrPanic(applicationPolicy) + policyBytes, err := createPolicyBytes(signaturePolicy, channelConfigPolicy) + if err != nil { + return err } - if collectionsConfigFile != "" { - var err error - ccp, _, err = chaincode.GetCollectionConfigFromFile(collectionsConfigFile) - if err != nil { - return errors.WithMessage(err, fmt.Sprintf("invalid collection configuration in file %s", collectionsConfigFile)) - } + ccp, err := createCollectionConfigPackage(collectionsConfigFile) + if err != nil { + return err } a.Input = &QueryApprovalStatusInput{ diff --git a/internal/peer/lifecycle/chaincode/queryapprovalstatus_test.go b/internal/peer/lifecycle/chaincode/queryapprovalstatus_test.go index d8de0b27953..d394983c4d4 100644 --- a/internal/peer/lifecycle/chaincode/queryapprovalstatus_test.go +++ b/internal/peer/lifecycle/chaincode/queryapprovalstatus_test.go @@ -128,7 +128,7 @@ func TestQueryApprovalStatusCmd(t *testing.T) { assert.Contains(t, err.Error(), "The required parameter 'sequence' is empty. Rerun the command with --sequence flag") sequence = 35 - policy = "MAD" + signaturePolicy = "MAD" cmd = queryApprovalStatusCmd(&QueryApprovalStatus{ Signer: &mockSigner{}, EndorserClient: me, @@ -140,7 +140,7 @@ func TestQueryApprovalStatusCmd(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "invalid signature policy: MAD") - policy = "AND('A.member', 'B.member')" + signaturePolicy = "AND('A.member', 'B.member')" cmd = queryApprovalStatusCmd(&QueryApprovalStatus{ EndorserClient: me, }) @@ -151,7 +151,7 @@ func TestQueryApprovalStatusCmd(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "error creating signed proposal: nil signer provided") - policy = "AND('A.member', 'B.member')" + signaturePolicy = "AND('A.member', 'B.member')" collectionsConfigFile = "not.there" cmd = queryApprovalStatusCmd(&QueryApprovalStatus{ Signer: &mockSigner{},