Skip to content

Commit 84845ff

Browse files
author
Jason Yellick
committed
FAB-17170 Peer CLI should encode mdata lowercase
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 <[email protected]>
1 parent b1d37c6 commit 84845ff

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

internal/peer/lifecycle/chaincode/package.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ func writeBytesToPackage(tw *tar.Writer, name string, payload []byte) error {
211211

212212
// PackageMetadata holds the path and type for a chaincode package
213213
type PackageMetadata struct {
214-
Path string `json:"Path"`
215-
Type string `json:"Type"`
216-
Label string `json:"Label"`
214+
Path string `json:"path"`
215+
Type string `json:"type"`
216+
Label string `json:"label"`
217217
}
218218

219219
func toJSON(path, ccType, label string) ([]byte, error) {

internal/peer/lifecycle/chaincode/package_test.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ package chaincode_test
88

99
import (
1010
"archive/tar"
11+
"bytes"
1112
"compress/gzip"
12-
"encoding/json"
1313
"io"
14+
"io/ioutil"
1415
"os"
1516
"path/filepath"
1617

@@ -21,7 +22,6 @@ import (
2122

2223
. "github.com/onsi/ginkgo"
2324
. "github.com/onsi/gomega"
24-
"github.com/onsi/gomega/gbytes"
2525
)
2626

2727
var _ = Describe("Package", func() {
@@ -77,11 +77,7 @@ var _ = Describe("Package", func() {
7777

7878
metadata, err := readMetadataFromBytes(pkgTarGzBytes)
7979
Expect(err).NotTo(HaveOccurred())
80-
Expect(metadata).To(Equal(&chaincode.PackageMetadata{
81-
Path: "normalizedPath",
82-
Type: "testType",
83-
Label: "testLabel",
84-
}))
80+
Expect(metadata).To(MatchJSON(`{"path":"normalizedPath","type":"testType","label":"testLabel"}`))
8581
})
8682

8783
Context("when the path is not provided", func() {
@@ -211,8 +207,8 @@ var _ = Describe("Package", func() {
211207
})
212208
})
213209

214-
func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, error) {
215-
buffer := gbytes.BufferWithBytes(pkgTarGzBytes)
210+
func readMetadataFromBytes(pkgTarGzBytes []byte) ([]byte, error) {
211+
buffer := bytes.NewBuffer(pkgTarGzBytes)
216212
gzr, err := gzip.NewReader(buffer)
217213
Expect(err).NotTo(HaveOccurred())
218214
defer gzr.Close()
@@ -226,10 +222,7 @@ func readMetadataFromBytes(pkgTarGzBytes []byte) (*chaincode.PackageMetadata, er
226222
return nil, err
227223
}
228224
if header.Name == "metadata.json" {
229-
jsonDecoder := json.NewDecoder(tr)
230-
metadata := &chaincode.PackageMetadata{}
231-
err := jsonDecoder.Decode(metadata)
232-
return metadata, err
225+
return ioutil.ReadAll(tr)
233226
}
234227
}
235228
return nil, errors.New("metadata.json not found")

0 commit comments

Comments
 (0)