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
2 changes: 1 addition & 1 deletion pkg/devfile/parser/context/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *DevfileCtx) SetDevfileContent() error {
if d.url != "" {
data, err = util.DownloadFileInMemory(d.url)
if err != nil {
return errors.Wrap(err, "error getting parent info from url")
return errors.Wrap(err, "error getting devfile info from url")
}
} else if d.absPath != "" {
// Read devfile
Expand Down
29 changes: 26 additions & 3 deletions pkg/devfile/parser/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package parser
import (
"fmt"
"net/url"
"os"
"path"
"path/filepath"
"strings"

"github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/devfile/library/pkg/util"
Expand Down Expand Up @@ -69,7 +73,17 @@ func (d *DevfileCtx) populateDevfile() (err error) {

// Populate fills the DevfileCtx struct with relevant context info
func (d *DevfileCtx) Populate() (err error) {

if !strings.HasSuffix(d.relPath, ".yaml") {
if _, err := os.Stat(filepath.Join(d.relPath, "devfile.yaml")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(d.relPath, ".devfile.yaml")); os.IsNotExist(err) {
return fmt.Errorf("the provided path is not a valid yaml filepath, and devfile.yaml or .devfile.yaml not found in the provided path : %s", d.relPath)
} else {
d.relPath = filepath.Join(d.relPath, ".devfile.yaml")
}
} else {
d.relPath = filepath.Join(d.relPath, "devfile.yaml")
}
}
if err := d.SetAbsPath(); err != nil {
return err
}
Expand All @@ -90,11 +104,20 @@ func (d *DevfileCtx) Populate() (err error) {

// PopulateFromURL fills the DevfileCtx struct with relevant context info
func (d *DevfileCtx) PopulateFromURL() (err error) {

_, err = url.ParseRequestURI(d.url)
u, err := url.ParseRequestURI(d.url)
if err != nil {
return err
}
if !strings.HasSuffix(d.url, ".yaml") {
u.Path = path.Join(u.Path, "devfile.yaml")
if _, err = util.DownloadFileInMemory(u.String()); err != nil {
u.Path = path.Join(path.Dir(u.Path), ".devfile.yaml")
if _, err = util.DownloadFileInMemory(u.String()); err != nil {
return fmt.Errorf("the provided url is not a valid yaml filepath, and devfile.yaml or .devfile.yaml not found in the provided path : %s", d.url)
}
}
d.url = u.String()
}
if d.uriMap == nil {
d.uriMap = make(map[string]bool)
}
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 @@ -2390,7 +2390,7 @@ func Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI(t *testing.T
defer testServer3.Close()
t.Run("it should error out if URI is recursively referenced with multiple references", func(t *testing.T) {
err := parseParentAndPlugin(devFileObj)
expectedErr := fmt.Sprintf("URI %v%v is recursively referenced", httpPrefix, uri1)
expectedErr := fmt.Sprintf("URI %v%v/devfile.yaml is recursively referenced", httpPrefix, uri1)
// Unexpected error
if err == nil || !reflect.DeepEqual(expectedErr, err.Error()) {
t.Errorf("Test_parseParentAndPlugin_RecursivelyReference_withMultipleURI() unexpected error = %v", err)
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,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: %s", request.URL, http.StatusText(resp.StatusCode))
return nil, errors.Errorf("fail to retrive %s, %v: %s", request.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
}

// Process http response
Expand Down Expand Up @@ -1030,6 +1030,10 @@ func DownloadFileInMemory(url string) ([]byte, error) {
if err != nil {
return nil, err
}
// 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))
}
defer resp.Body.Close()

return ioutil.ReadAll(resp.Body)
Expand Down