Skip to content

Commit adca953

Browse files
author
Jason Yellick
committed
FAB-10826 Change ValidateSpec to ValidatePath
This is part of a CR series to remove the explicit dependency of the chaincode spec and deployment spec from the platforms package. Ultimately, these messages were designed for fabric v0.5/v0.6 and would not have been recycled given more time. This is a step in allowing us to use a different, more fabric v1.0 natural format for describing chaincodes. Change-Id: Ibbd20f3ce85f226e4c2cc03b3e2fd70081815ba6 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 613e845 commit adca953

File tree

11 files changed

+85
-102
lines changed

11 files changed

+85
-102
lines changed

core/chaincode/platforms/car/platform.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package car
@@ -40,10 +30,10 @@ func (carPlatform *Platform) Name() string {
4030
return pb.ChaincodeSpec_CAR.String()
4131
}
4232

43-
// ValidateSpec validates the chaincode specification for CAR types to satisfy
33+
// ValidatePath validates the chaincode path for CAR types to satisfy
4434
// the platform interface. This chaincode type currently doesn't
4535
// require anything specific so we just implicitly approve any spec
46-
func (carPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
36+
func (carPlatform *Platform) ValidatePath(path string) error {
4737
return nil
4838
}
4939

core/chaincode/platforms/golang/platform.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package golang
@@ -104,8 +94,8 @@ func (goPlatform *Platform) Name() string {
10494
}
10595

10696
// ValidateSpec validates Go chaincodes
107-
func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
108-
path, err := url.Parse(spec.ChaincodeId.Path)
97+
func (goPlatform *Platform) ValidatePath(rawPath string) error {
98+
path, err := url.Parse(rawPath)
10999
if err != nil || path == nil {
110100
return fmt.Errorf("invalid path: %s", err)
111101
}
@@ -118,7 +108,7 @@ func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
118108
if err != nil {
119109
return err
120110
}
121-
pathToCheck := filepath.Join(gopath, "src", spec.ChaincodeId.Path)
111+
pathToCheck := filepath.Join(gopath, "src", rawPath)
122112
exists, err := pathExists(pathToCheck)
123113
if err != nil {
124114
return fmt.Errorf("error validating chaincode path: %s", err)

core/chaincode/platforms/golang/platform_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,24 @@ func Test_decodeUrl(t *testing.T) {
236236
}
237237
}
238238

239-
func TestValidateSpec(t *testing.T) {
239+
func TestValidatePath(t *testing.T) {
240240
platform := &Platform{}
241241

242242
var tests = []struct {
243-
spec *pb.ChaincodeSpec
243+
path string
244244
succ bool
245245
}{
246-
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "http://github.com/hyperledger/fabric/examples/chaincode/go/map"}}, succ: true},
247-
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "https://github.com/hyperledger/fabric/examples/chaincode/go/map"}}, succ: true},
248-
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map"}}, succ: true},
249-
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/bad/chaincode/go/map"}}, succ: false},
250-
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: ":github.com/hyperledger/fabric/examples/chaincode/go/map"}}, succ: false},
246+
{path: "http://github.com/hyperledger/fabric/examples/chaincode/go/map", succ: true},
247+
{path: "https://github.com/hyperledger/fabric/examples/chaincode/go/map", succ: true},
248+
{path: "github.com/hyperledger/fabric/examples/chaincode/go/map", succ: true},
249+
{path: "github.com/hyperledger/fabric/bad/chaincode/go/map", succ: false},
250+
{path: ":github.com/hyperledger/fabric/examples/chaincode/go/map", succ: false},
251251
}
252252

253253
for _, tst := range tests {
254-
err := platform.ValidateSpec(tst.spec)
254+
err := platform.ValidatePath(tst.path)
255255
if err = testerr(err, tst.succ); err != nil {
256-
t.Errorf("Error validating chaincode spec: %s, %s", tst.spec.ChaincodeId.Path, err)
256+
t.Errorf("Error validating chaincode spec: %s, %s", tst.path, err)
257257
}
258258
}
259259
}

core/chaincode/platforms/java/java_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@ var spec = &pb.ChaincodeSpec{
3636
Input: &pb.ChaincodeInput{
3737
Args: [][]byte{[]byte("f")}}}
3838

39-
func TestValidateSpec(t *testing.T) {
39+
func TestValidatePath(t *testing.T) {
4040
platform := java.Platform{}
4141

42-
err := platform.ValidateSpec(spec)
43-
assert.NoError(t, err)
44-
}
45-
46-
func TestValidateDeploymentSpec(t *testing.T) {
47-
platform := java.Platform{}
48-
err := platform.ValidateSpec(spec)
42+
err := platform.ValidatePath(spec.ChaincodeId.Path)
4943
assert.NoError(t, err)
5044
}
5145

core/chaincode/platforms/java/platform.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func (javaPlatform *Platform) Name() string {
2828
return pb.ChaincodeSpec_JAVA.String()
2929
}
3030

31-
//ValidateSpec validates the java chaincode specs
32-
func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
33-
path, err := url.Parse(spec.ChaincodeId.Path)
31+
//ValidatePath validates the java chaincode paths
32+
func (javaPlatform *Platform) ValidatePath(rawPath string) error {
33+
path, err := url.Parse(rawPath)
3434
if err != nil || path == nil {
3535
return fmt.Errorf("invalid path: %s", err)
3636
}

core/chaincode/platforms/mock/platform.go

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/chaincode/platforms/node/platform.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ func (nodePlatform *Platform) Name() string {
4949
}
5050

5151
// ValidateSpec validates Go chaincodes
52-
func (nodePlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
53-
path, err := url.Parse(spec.ChaincodeId.Path)
52+
func (nodePlatform *Platform) ValidatePath(rawPath string) error {
53+
path, err := url.Parse(rawPath)
5454
if err != nil || path == nil {
5555
return fmt.Errorf("invalid path: %s", err)
5656
}
5757

5858
//Treat empty scheme as a local filesystem path
5959
if path.Scheme == "" {
60-
pathToCheck, err := filepath.Abs(spec.ChaincodeId.Path)
60+
pathToCheck, err := filepath.Abs(rawPath)
6161
if err != nil {
6262
return fmt.Errorf("error obtaining absolute path of the chaincode: %s", err)
6363
}
@@ -67,7 +67,7 @@ func (nodePlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
6767
return fmt.Errorf("error validating chaincode path: %s", err)
6868
}
6969
if !exists {
70-
return fmt.Errorf("path to chaincode does not exist: %s", spec.ChaincodeId.Path)
70+
return fmt.Errorf("path to chaincode does not exist: %s", rawPath)
7171
}
7272
}
7373
return nil

core/chaincode/platforms/node/platform_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ import (
2626

2727
var platform = &Platform{}
2828

29-
func TestValidateSpec(t *testing.T) {
30-
ccSpec := &peer.ChaincodeSpec{
31-
Type: peer.ChaincodeSpec_NODE,
32-
ChaincodeId: &peer.ChaincodeID{Path: "there/is/no/way/this/path/exists"},
33-
Input: &peer.ChaincodeInput{Args: [][]byte{[]byte("invoke")}}}
34-
35-
err := platform.ValidateSpec(ccSpec)
29+
func TestValidatePath(t *testing.T) {
30+
err := platform.ValidatePath("there/is/no/way/this/path/exists")
3631
if err == nil {
3732
t.Fatalf("should have returned an error on non-existent chaincode path")
3833
} else if !strings.HasPrefix(err.Error(), "path to chaincode does not exist") {
3934
t.Fatalf("should have returned an error about chaincode path not existent, but got '%v'", err)
4035
}
4136

42-
ccSpec.ChaincodeId.Path = "http://something bad/because/it/has/the/space"
43-
err = platform.ValidateSpec(ccSpec)
37+
err = platform.ValidatePath("http://something bad/because/it/has/the/space")
4438
if err == nil {
4539
t.Fatalf("should have returned an error on an empty chaincode path")
4640
} else if !strings.HasPrefix(err.Error(), "invalid path") {

core/chaincode/platforms/platforms.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// the given platform
2626
type Platform interface {
2727
Name() string
28-
ValidateSpec(spec *pb.ChaincodeSpec) error
28+
ValidatePath(path string) error
2929
ValidateDeploymentSpec(spec *pb.ChaincodeDeploymentSpec) error
3030
GetDeploymentPayload(spec *pb.ChaincodeSpec) ([]byte, error)
3131
GenerateDockerfile(spec *pb.ChaincodeDeploymentSpec) (string, error)
@@ -69,7 +69,7 @@ func (r *Registry) ValidateSpec(spec *pb.ChaincodeSpec) error {
6969
if !ok {
7070
return fmt.Errorf("Unknown chaincodeType: %s", spec.Type)
7171
}
72-
return platform.ValidateSpec(spec)
72+
return platform.ValidatePath(spec.Path())
7373
}
7474

7575
func (r *Registry) ValidateDeploymentSpec(spec *pb.ChaincodeDeploymentSpec) error {

core/chaincode/platforms/platforms_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ var _ = Describe("Platforms", func() {
4141
Describe("pass through functions", func() {
4242
Describe("ValidateSpec", func() {
4343
It("returns the result of the underlying platform", func() {
44-
fakePlatform.ValidateSpecReturns(errors.New("fake-error"))
44+
fakePlatform.ValidatePathReturns(errors.New("fake-error"))
4545
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG}
4646
err := registry.ValidateSpec(spec)
4747
Expect(err).To(MatchError(errors.New("fake-error")))
48-
Expect(fakePlatform.ValidateSpecCallCount()).To(Equal(1))
49-
Expect(fakePlatform.ValidateSpecArgsForCall(0)).To(Equal(spec))
48+
Expect(fakePlatform.ValidatePathCallCount()).To(Equal(1))
49+
Expect(fakePlatform.ValidatePathArgsForCall(0)).To(Equal(spec.Path()))
5050
})
5151

5252
Context("when the platform is unknown", func() {

0 commit comments

Comments
 (0)