Skip to content

Commit f85c02e

Browse files
author
Jason Yellick
committed
FAB-16166 Remove old metadata filename
This is yet another CR in the back-and-forth series between the peer and the SDKs to clean up some of the chaincode packaging. Particularly, this CR removes the fallback of the old metadata file name now that: https://gerrit.hyperledger.org/r/c/fabric-sdk-java/+/32770 https://gerrit.hyperledger.org/r/c/fabric-sdk-node/+/32769 have been merged. Additionally, it removes the annotations from the metadata struct, which causes the unmarshaling to treat the keys in a case insensitive way. This will allow a transition period for the SDKs to continue working with upper-case metadata keys, while we transition them to lower case. Once the transition is complete, we will add back correct annotations. Change-Id: Ifbc4f13bbcfb2f4e5454bb7208113164481726f5 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent d3145d9 commit f85c02e

File tree

9 files changed

+27
-28
lines changed

9 files changed

+27
-28
lines changed

core/chaincode/persistence/chaincode_package.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ import (
3131
// seems like a good step.
3232

3333
const (
34-
// PreferredChaincodePackageMetadataFile is the first name we check
35-
// for the chaincode metadata before falling back to ChaincodePackageMetadataFile
36-
// The latter will be removed before release
37-
PreferredChaincodePackageMetadataFile = "metadata.json"
34+
// MetadataFile is the expected location of the metadata json document
35+
// in the top level of the chaincode package.
36+
MetadataFile = "metadata.json"
3837

3938
// CodePackageFile is the expected location of the code package in the
4039
// top level of the chaincode package
4140
CodePackageFile = "code.tar.gz"
42-
43-
// ChaincodePackageMetadataFile contains the name
44-
// of the file that contains metadata for a chaincode pacakge.
45-
ChaincodePackageMetadataFile = "Chaincode-Package-Metadata.json"
4641
)
4742

4843
//go:generate counterfeiter -o mock/legacy_cc_package_locator.go --fake-name LegacyCCPackageLocator . LegacyCCPackageLocator
@@ -105,7 +100,7 @@ func (cps *ChaincodePackageStreamer) Exists() bool {
105100
}
106101

107102
func (cps *ChaincodePackageStreamer) Metadata() (*ChaincodePackageMetadata, error) {
108-
tarFileStream, err := cps.File(PreferredChaincodePackageMetadataFile)
103+
tarFileStream, err := cps.File(MetadataFile)
109104
if err != nil {
110105
return nil, errors.WithMessage(err, "could not get metadata file")
111106
}
@@ -198,10 +193,12 @@ type ChaincodePackage struct {
198193

199194
// ChaincodePackageMetadata contains the information necessary to understand
200195
// the embedded code package.
196+
// Note: annotations for the names need to be added back, but, we're making it
197+
// case insensitive for now to allow SDKs to transition. TODO, add annotations back
201198
type ChaincodePackageMetadata struct {
202-
Type string `json:"Type"`
203-
Path string `json:"Path"`
204-
Label string `json:"Label"`
199+
Type string
200+
Path string
201+
Label string
205202
}
206203

207204
// MetadataProvider provides the means to retrieve metadata
@@ -262,25 +259,13 @@ func (ccpp ChaincodePackageParser) Parse(source []byte) (*ChaincodePackage, erro
262259

263260
switch header.Name {
264261

265-
case PreferredChaincodePackageMetadataFile:
262+
case MetadataFile:
266263
ccPackageMetadata = &ChaincodePackageMetadata{}
267264
err := json.Unmarshal(fileBytes, ccPackageMetadata)
268265
if err != nil {
269-
return nil, errors.Wrapf(err, "could not unmarshal %s as json", ChaincodePackageMetadataFile)
266+
return nil, errors.Wrapf(err, "could not unmarshal %s as json", MetadataFile)
270267
}
271268

272-
case ChaincodePackageMetadataFile:
273-
// XXX this is a temporary compatibility hack to allow the SDKs a few days to transition
274-
// to the new filename without breaking everything
275-
if ccPackageMetadata != nil {
276-
// We must have already loaded the metadata from the preferred location
277-
continue
278-
}
279-
ccPackageMetadata = &ChaincodePackageMetadata{}
280-
err := json.Unmarshal(fileBytes, ccPackageMetadata)
281-
if err != nil {
282-
return nil, errors.Wrapf(err, "could not unmarshal %s as json", ChaincodePackageMetadataFile)
283-
}
284269
case CodePackageFile:
285270
codePackage = fileBytes
286271
default:
@@ -293,7 +278,7 @@ func (ccpp ChaincodePackageParser) Parse(source []byte) (*ChaincodePackage, erro
293278
}
294279

295280
if ccPackageMetadata == nil {
296-
return nil, errors.Errorf("did not find any package metadata (missing %s)", PreferredChaincodePackageMetadataFile)
281+
return nil, errors.Errorf("did not find any package metadata (missing %s)", MetadataFile)
297282
}
298283

299284
if err := validateLabel(ccPackageMetadata.Label); err != nil {

core/chaincode/persistence/chaincode_package_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package persistence_test
88

99
import (
10+
"encoding/json"
1011
"io/ioutil"
1112

1213
"github.com/hyperledger/fabric/core/chaincode/persistence"
@@ -178,7 +179,7 @@ var _ = Describe("ChaincodePackageParser", func() {
178179
Expect(err).NotTo(HaveOccurred())
179180

180181
_, err = ccpp.Parse(data)
181-
Expect(err).To(MatchError("could not unmarshal Chaincode-Package-Metadata.json as json: invalid character '\\n' in string literal"))
182+
Expect(err).To(MatchError("could not unmarshal metadata.json as json: invalid character '\\n' in string literal"))
182183
})
183184
})
184185

@@ -397,3 +398,16 @@ var _ = Describe("ChaincodePackageStreamer", func() {
397398
})
398399
})
399400
})
401+
402+
var _ = Describe("ChaincodePackageMetadata", func() {
403+
It("works around upper case keys by unmarshaling in a case insensitive way", func() {
404+
md := persistence.ChaincodePackageMetadata{}
405+
err := json.Unmarshal([]byte(`{"Type": "fake-type", "Label": "fake-label", "Path": "fake-path"}`), &md)
406+
Expect(err).NotTo(HaveOccurred())
407+
Expect(md).To(Equal(persistence.ChaincodePackageMetadata{
408+
Type: "fake-type",
409+
Path: "fake-path",
410+
Label: "fake-label",
411+
}))
412+
})
413+
})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)