Skip to content

Commit

Permalink
FAB-17170 Peer CLI should encode mdata lowercase
Browse files Browse the repository at this point in the history
Once upon a time, the JSON fields in the chaincode package metadata.json
were upper case.  The peer CLI was written to reflect this fact.  When
they were changed to lower-case, the peer CLI was not updated, but
because of the fuzzy JSON matching rules in the golang JSON decoded it
was not noticed.  However, for external builders, the inconsistency is
more likely to be noticed as tools like jq etc. may not default to this
same fuzzy case-insensitive matching.

This change simply modifies the peer CLI to encode the metadata fields
as lower case.

Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Dec 10, 2019
1 parent b1d37c6 commit 84845ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/peer/lifecycle/chaincode/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func writeBytesToPackage(tw *tar.Writer, name string, payload []byte) error {

// PackageMetadata holds the path and type for a chaincode package
type PackageMetadata struct {
Path string `json:"Path"`
Type string `json:"Type"`
Label string `json:"Label"`
Path string `json:"path"`
Type string `json:"type"`
Label string `json:"label"`
}

func toJSON(path, ccType, label string) ([]byte, error) {
Expand Down
19 changes: 6 additions & 13 deletions internal/peer/lifecycle/chaincode/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package chaincode_test

import (
"archive/tar"
"bytes"
"compress/gzip"
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -21,7 +22,6 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)

var _ = Describe("Package", func() {
Expand Down Expand Up @@ -77,11 +77,7 @@ var _ = Describe("Package", func() {

metadata, err := readMetadataFromBytes(pkgTarGzBytes)
Expect(err).NotTo(HaveOccurred())
Expect(metadata).To(Equal(&chaincode.PackageMetadata{
Path: "normalizedPath",
Type: "testType",
Label: "testLabel",
}))
Expect(metadata).To(MatchJSON(`{"path":"normalizedPath","type":"testType","label":"testLabel"}`))
})

Context("when the path is not provided", func() {
Expand Down Expand Up @@ -211,8 +207,8 @@ var _ = Describe("Package", func() {
})
})

func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, error) {
buffer := gbytes.BufferWithBytes(pkgTarGzBytes)
func readMetadataFromBytes(pkgTarGzBytes []byte) ([]byte, error) {
buffer := bytes.NewBuffer(pkgTarGzBytes)
gzr, err := gzip.NewReader(buffer)
Expect(err).NotTo(HaveOccurred())
defer gzr.Close()
Expand All @@ -226,10 +222,7 @@ func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, er
return nil, err
}
if header.Name == "metadata.json" {
jsonDecoder := json.NewDecoder(tr)
metadata := &chaincode.PackageMetadata{}
err := jsonDecoder.Decode(metadata)
return metadata, err
return ioutil.ReadAll(tr)
}
}
return nil, errors.New("metadata.json not found")
Expand Down

0 comments on commit 84845ff

Please sign in to comment.