Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/devfile/library
go 1.13

require (
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403
github.com/devfile/api/v2 v2.0.0-20210630155427-a72fb9eb4afa
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gobwas/glob v0.2.3
github.com/golang/mock v1.5.0
github.com/google/go-cmp v0.5.2
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403 h1:5Cyt6BucdDKwaW1LaftbJt6P2tpR1GjF/b9GpO5NFmg=
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403/go.mod h1:QNzaIVQnCsYfXed+QZOn1uvEQFzyhvpi/uc3g/b2ws0=
github.com/devfile/api/v2 v2.0.0-20210630155427-a72fb9eb4afa h1:Emb+OilQp9eLktgIKc/Kwq5erHwoDL7PbbAEvQDEJMk=
github.com/devfile/api/v2 v2.0.0-20210630155427-a72fb9eb4afa/go.mod h1:QNzaIVQnCsYfXed+QZOn1uvEQFzyhvpi/uc3g/b2ws0=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand All @@ -102,8 +102,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/context/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"unicode"

"github.com/devfile/library/pkg/util"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
"k8s.io/klog"
"sigs.k8s.io/yaml"
)

// Every JSON document starts with "{"
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
devfileCtx "github.com/devfile/library/pkg/devfile/parser/context"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/testingutil"
"github.com/ghodss/yaml"
"github.com/kylelemons/godebug/pretty"
kubev1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

const schemaV200 = "2.0.0"
Expand Down
23 changes: 0 additions & 23 deletions pkg/devfile/parser/writer.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
package parser

import (
"encoding/json"

"sigs.k8s.io/yaml"

"github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/pkg/errors"
"k8s.io/klog"
)

// WriteJsonDevfile creates a devfile.json file
func (d *DevfileObj) WriteJsonDevfile() error {

// Encode data into JSON format
jsonData, err := json.MarshalIndent(d.Data, "", " ")
if err != nil {
return errors.Wrapf(err, "failed to marshal devfile object into json")
}

// Write to devfile.json
fs := d.Ctx.GetFs()
err = fs.WriteFile(d.Ctx.GetAbsPath(), jsonData, 0644)
if err != nil {
return errors.Wrapf(err, "failed to create devfile json file")
}

// Successful
klog.V(2).Infof("devfile json created at: '%s'", OutputDevfileJsonPath)
return nil
}

// WriteYamlDevfile creates a devfile.yaml file
func (d *DevfileObj) WriteYamlDevfile() error {

Expand Down
33 changes: 1 addition & 32 deletions pkg/devfile/parser/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,13 @@ import (
"github.com/devfile/library/pkg/testingutil/filesystem"
)

func TestWriteJsonDevfile(t *testing.T) {
func TestWriteYamlDevfile(t *testing.T) {

var (
schemaVersion = "2.0.0"
testName = "TestName"
)

t.Run("write json devfile", func(t *testing.T) {

// Use fakeFs
fs := filesystem.NewFakeFs()

// DevfileObj
devfileObj := DevfileObj{
Ctx: devfileCtx.FakeContext(fs, OutputDevfileJsonPath),
Data: &v2.DevfileV2{
Devfile: v1.Devfile{
DevfileHeader: devfilepkg.DevfileHeader{
SchemaVersion: schemaVersion,
Metadata: devfilepkg.DevfileMetadata{
Name: testName,
},
},
},
},
}

// test func()
err := devfileObj.WriteJsonDevfile()
if err != nil {
t.Errorf("unexpected error: '%v'", err)
}

if _, err := fs.Stat(OutputDevfileJsonPath); err != nil {
t.Errorf("unexpected error: '%v'", err)
}
})

t.Run("write yaml devfile", func(t *testing.T) {

// Use fakeFs
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func HTTPGetRequest(request HTTPRequestParams, cacheFor int) ([]byte, error) {

// We have a non 1xx / 2xx status, return an error
if (resp.StatusCode - 300) > 0 {
return nil, errors.Errorf("fail to retrive %s, %v: %s", request.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
return nil, errors.Errorf("failed to retrieve %s, %v: %s", request.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
}

// Process http response
Expand Down Expand Up @@ -1033,7 +1033,7 @@ func DownloadFileInMemory(url string) ([]byte, error) {
}
// We have a non 1xx / 2xx status, return an error
if (resp.StatusCode - 300) > 0 {
return nil, errors.Errorf("fail to retrive %s, %v: %s", url, resp.StatusCode, http.StatusText(resp.StatusCode))
return nil, errors.Errorf("failed to retrieve %s, %v: %s", url, resp.StatusCode, http.StatusText(resp.StatusCode))
}
defer resp.Body.Close()

Expand Down