Skip to content

Commit

Permalink
Merge pull request #61 from yangcao77/validation-2
Browse files Browse the repository at this point in the history
add starterproject validation back
  • Loading branch information
yangcao77 authored Feb 16, 2021
2 parents 951fc2a + 1ce14ae commit 3066a89
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/devfile/library
go 1.13

require (
github.com/devfile/api/v2 v2.0.0-20210202172954-6424f4139ac7
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gobwas/glob v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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-20210202172954-6424f4139ac7 h1:bQGUVLEGQtVkvS94K4gQbu57Rk/npcZQmgORmCWYNy8=
github.com/devfile/api/v2 v2.0.0-20210202172954-6424f4139ac7/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af h1:egbFAAS/CWJMAqa4zIm8Cik3+iCqTAfLPfCj6PLEG5Y=
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/v2/common/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type DevfileOptions struct {

// FilterDevfileObject filters devfile attributes with the given options
func FilterDevfileObject(attributes apiAttributes.Attributes, options DevfileOptions) (bool, error) {
var err error
filterIn := true
for key, value := range options.Filter {
var err error
currentFilterIn := false
attrValue := attributes.Get(key, &err)
var keyNotFoundErr = &apiAttributes.KeyNotFoundError{Key: key}
Expand Down
69 changes: 40 additions & 29 deletions pkg/devfile/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package validate

import (
"fmt"
"github.com/devfile/api/v2/pkg/validation"
v2Validation "github.com/devfile/api/v2/pkg/validation"
devfileData "github.com/devfile/library/pkg/devfile/parser/data"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"strings"
)
Expand All @@ -23,43 +24,53 @@ func ValidateDevfileData(data devfileData.DevfileData) error {
if err != nil {
return err
}
//starterProjects, err := data.GetStarterProjects(common.DevfileOptions{})
//if err != nil {
// return err
//}

var errstrings []string
// validate components
err = validation.ValidateComponents(components)
starterProjects, err := data.GetStarterProjects(common.DevfileOptions{})
if err != nil {
errstrings = append(errstrings, err.Error())
return err
}

// validate commands
err = validation.ValidateCommands(commands, components)
if err != nil {
errstrings = append(errstrings, err.Error())
}
var errstrings []string
switch d := data.(type) {
case *v2.DevfileV2:
// validate components
err = v2Validation.ValidateComponents(components)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = validation.ValidateEvents(data.GetEvents(), commands)
if err != nil {
errstrings = append(errstrings, err.Error())
}
// validate commands
err = v2Validation.ValidateCommands(commands, components)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = validation.ValidateProjects(projects)
if err != nil {
errstrings = append(errstrings, err.Error())
}
err = v2Validation.ValidateEvents(data.GetEvents(), commands)
if err != nil {
errstrings = append(errstrings, err.Error())
}

//err = validation.ValidateStarterProjects(starterProjects)
//if err != nil {
// errstrings = append(errstrings, err.Error())
//}
err = v2Validation.ValidateProjects(projects)
if err != nil {
errstrings = append(errstrings, err.Error())
}

err = v2Validation.ValidateStarterProjects(starterProjects)
if err != nil {
errstrings = append(errstrings, err.Error())
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
} else {
return nil
}
default:
return fmt.Errorf("unknown devfile type %T", d)
}

if len(errstrings) > 0 {
return fmt.Errorf(strings.Join(errstrings, "\n"))
} else {
return nil
}

return nil
}

0 comments on commit 3066a89

Please sign in to comment.