Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

762 create endpoints for v2index #106

Merged
merged 7 commits into from
Mar 14, 2022
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
4 changes: 0 additions & 4 deletions index/generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
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-20210917193329-089a48011460 h1:cmd+3poyUwevcWchYdvE02YT1nQU4SJpA5/wrdLrpWE=
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed h1:OXF9l+MlJrirXAqKN6EZUVaHB0FKm7nh0EjpktwnBig=
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/library v1.2.0 h1:OT1Irwg5EZhlCpsAFkjIzd3bqyzbLG0JmFPMHeE1e7M=
github.com/devfile/library v1.2.0/go.mod h1:gyiQS+ZImnM4/d+wFUl3gJmIozOSXMenl0WX8cx4zu4=
github.com/devfile/library v1.2.1-0.20211104222135-49d635cb492f h1:kKsBWkFiD7tSIpzwfmz7TH89U1U3yRxSJ9UPOo2OH1s=
github.com/devfile/library v1.2.1-0.20211104222135-49d635cb492f/go.mod h1:uFZZdTuRqA68FVe/JoJHP92CgINyQkyWnM2Qyiim+50=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down
30 changes: 18 additions & 12 deletions index/generator/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
devfile = "devfile.yaml"
devfileHidden = ".devfile.yaml"
extraDevfileEntries = "extraDevfileEntries.yaml"
stackYaml = "stack.yaml"
stackYaml = "stack.yaml"
)

// MissingArchError is an error if the architecture list is empty
Expand Down Expand Up @@ -103,7 +103,7 @@ func validateIndexComponent(indexComponent schema.Schema, componentType schema.D
if version.Links == nil || len(version.Links) == 0 {
return fmt.Errorf("index component version %s: links are empty", version.Version)
}
if version.Resources == nil || len(version.Resources) == 0 {
if version.Resources == nil || len(version.Resources) == 0 {
return fmt.Errorf("index component version %s: resources are empty", version.Version)
}
if version.Default {
Expand All @@ -119,7 +119,7 @@ func validateIndexComponent(indexComponent schema.Schema, componentType schema.D
}
}
} else if componentType == schema.SampleDevfileType {
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
defaultFound := false
for _, version := range indexComponent.Versions {
if version.Version == "" {
Expand Down Expand Up @@ -176,8 +176,8 @@ func fileExists(filepath string) bool {

func dirExists(dirpath string) error {
dir, err := os.Stat(dirpath)
if os.IsNotExist(err){
return fmt.Errorf("path: %s does not exist: %w",dirpath, err)
if os.IsNotExist(err) {
return fmt.Errorf("path: %s does not exist: %w", dirpath, err)
}
if !dir.IsDir() {
return fmt.Errorf("%s is not a directory", dirpath)
Expand Down Expand Up @@ -213,7 +213,7 @@ func parseDevfileRegistry(registryDirPath string, force bool) ([]schema.Schema,
}
}

i:= 0
i := 0
for i < len(indexComponent.Versions) {
versionComponent := indexComponent.Versions[i]
if versionComponent.Git != nil {
Expand All @@ -231,6 +231,14 @@ func parseDevfileRegistry(registryDirPath string, force bool) ([]schema.Schema,
indexComponent.Versions[i] = versionComponent
i++
}

for _, version := range indexComponent.Versions {
// if a particular version supports all architectures, the top architecture List should be empty (support all) as well
if version.Architectures == nil || len(version.Architectures) == 0 {
indexComponent.Architectures = nil
break
}
}
} else { // if stack.yaml not exist, old stack repo struct, directly lookfor & parse devfile.yaml
versionComponent := schema.Version{}
err := parseStackDevfile(stackFolderPath, stackFolderDir.Name(), force, &versionComponent, &indexComponent)
Expand Down Expand Up @@ -276,7 +284,7 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers

if !force {
// Devfile validation
devfileObj,_, err := devfileParser.ParseDevfileAndValidate(parser.ParserArgs{Path: devfilePath})
devfileObj, _, err := devfileParser.ParseDevfileAndValidate(parser.ParserArgs{Path: devfilePath})
if err != nil {
return fmt.Errorf("%s devfile is not valid: %v", devfileDirPath, err)
}
Expand All @@ -292,7 +300,6 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers
return fmt.Errorf("failed to read %s: %v", devfilePath, err)
}


var devfile schema.Devfile
err = yaml.Unmarshal(bytes, &devfile)
if err != nil {
Expand Down Expand Up @@ -412,7 +419,7 @@ func parseExtraDevfileEntries(registryDirPath string, force bool) ([]schema.Sche
// Can't handle during registry build since we don't have access to devfile library/parser
if indexComponent.Type == schema.SampleDevfileType && validateSamples {
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
for _, version := range indexComponent.Versions{
for _, version := range indexComponent.Versions {
sampleVersonDirPath := filepath.Join(samplesDir, devfileEntry.Name, version.Version)
devfilePath := filepath.Join(sampleVersonDirPath, "devfile.yaml")
_, err := os.Stat(filepath.Join(devfilePath))
Expand Down Expand Up @@ -497,7 +504,7 @@ func checkForRequiredMetadata(devfileObj parser.DevfileObj) []error {
return metadataErrors
}

func validateStackInfo (stackInfo schema.Schema, stackfolderDir string) []error {
func validateStackInfo(stackInfo schema.Schema, stackfolderDir string) []error {
var errors []error

if stackInfo.Name == "" {
Expand Down Expand Up @@ -537,7 +544,6 @@ func validateStackInfo (stackInfo schema.Schema, stackfolderDir string) []error
return errors
}


// In checks if the value is in the array
func inArray(arr []string, value string) bool {
for _, item := range arr {
Expand All @@ -546,4 +552,4 @@ func inArray(arr []string, value string) bool {
}
}
return false
}
}
48 changes: 24 additions & 24 deletions index/generator/library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestValidateIndexComponent(t *testing.T) {
Name: "nodejs",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Resources: []string{
"devfile.yaml",
Expand All @@ -73,7 +73,7 @@ func TestValidateIndexComponent(t *testing.T) {
Name: "nodejs",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Links: map[string]string{
"self": "devfile-catalog/java-maven:latest",
Expand Down Expand Up @@ -103,18 +103,18 @@ func TestValidateIndexComponent(t *testing.T) {
SupportUrl: "http://testurl/support.md",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Links: map[string]string{
"self": "devfile-catalog/java-maven:1.0.0",
"self": "devfile-catalog/java-maven:1.0.0",
},
Resources: []string{
"devfile.yaml",
},
},
{
Version: "1.1.0",
Version: "1.1.0",
SchemaVersion: "2.1.0",
Links: map[string]string{
"self": "devfile-catalog/java-maven:2.1.0",
Expand Down Expand Up @@ -181,9 +181,9 @@ func TestValidateIndexComponent(t *testing.T) {
Name: "nodejs",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Links: map[string]string{
"self": "devfile-catalog/java-maven:latest",
},
Expand All @@ -206,9 +206,9 @@ func TestValidateIndexComponent(t *testing.T) {
Name: "nodejs",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Links: map[string]string{
"self": "devfile-catalog/java-maven:latest",
},
Expand All @@ -228,7 +228,7 @@ func TestValidateIndexComponent(t *testing.T) {
{
"Case 11: empty version list",
schema.Schema{
Name: "nodejs",
Name: "nodejs",
Versions: []schema.Version{},
},
schema.StackDevfileType,
Expand All @@ -245,7 +245,7 @@ func TestValidateIndexComponent(t *testing.T) {
SupportUrl: "http://testurl/support.md",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Links: map[string]string{
"self": "devfile-catalog/java-maven:latest",
Expand Down Expand Up @@ -308,9 +308,9 @@ func TestValidateIndexComponent(t *testing.T) {
SupportUrl: "http://testurl/support.md",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Links: map[string]string{
"self": "devfile-catalog/java-maven:1.0.0",
},
Expand All @@ -319,9 +319,9 @@ func TestValidateIndexComponent(t *testing.T) {
},
},
{
Version: "1.1.0",
Version: "1.1.0",
SchemaVersion: "2.1.0",
Default: true,
Default: true,
Links: map[string]string{
"self": "devfile-catalog/java-maven:1.1.0",
},
Expand All @@ -340,17 +340,17 @@ func TestValidateIndexComponent(t *testing.T) {
Name: "nodejs",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Git: &schema.Git{
Remotes: map[string]string{
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs",
},
},
},
{
Version: "1.1.0",
Version: "1.1.0",
SchemaVersion: "2.1.0",
Git: &schema.Git{
Remotes: map[string]string{
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestValidateIndexComponent(t *testing.T) {
SupportUrl: "http://testurl/support.md",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Git: &schema.Git{
Remotes: map[string]string{
Expand Down Expand Up @@ -439,19 +439,19 @@ func TestValidateIndexComponent(t *testing.T) {
SupportUrl: "http://testurl/support.md",
Versions: []schema.Version{
{
Version: "1.0.0",
Version: "1.0.0",
SchemaVersion: "2.0.0",
Default: true,
Default: true,
Git: &schema.Git{
Remotes: map[string]string{
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs",
},
},
},
{
Version: "1.1.0",
Version: "1.1.0",
SchemaVersion: "2.1.0",
Default: true,
Default: true,
Git: &schema.Git{
Remotes: map[string]string{
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs-2.1.0",
Expand Down
46 changes: 23 additions & 23 deletions index/generator/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ type StarterProject struct {
type Devfile struct {
Meta Schema `yaml:"metadata,omitempty" json:"metadata,omitempty"`
StarterProjects []StarterProject `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
}

// Git stores the information of remote repositories
type Git struct {
Remotes map[string]string `yaml:"remotes,omitempty" json:"remotes,omitempty"`
Url string `yaml:"url,omitempty" json:"url,omitempty"`
RemoteName string `yaml:"remoteName,omitempty" json:"remoteName,omitempty"`
SubDir string `yaml:"subDir,omitempty" json:"subDir,omitempty"`
Revision string `yaml:"revision,omitempty" json:"revision,omitempty"`
Remotes map[string]string `yaml:"remotes,omitempty" json:"remotes,omitempty"`
Url string `yaml:"url,omitempty" json:"url,omitempty"`
RemoteName string `yaml:"remoteName,omitempty" json:"remoteName,omitempty"`
SubDir string `yaml:"subDir,omitempty" json:"subDir,omitempty"`
Revision string `yaml:"revision,omitempty" json:"revision,omitempty"`
}

// ExtraDevfileEntries is the extraDevfileEntries structure that is used by index component
Expand All @@ -177,24 +177,24 @@ type ExtraDevfileEntries struct {

// Version stores the top-level stack information defined within stack.yaml
type StackInfo struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
}

// Version stores the information for each stack version
type Version struct {
Version string `yaml:"version,omitempty" json:"version,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
}
Version string `yaml:"version,omitempty" json:"version,omitempty"`
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
}
1 change: 1 addition & 0 deletions index/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/devfile/registry-support/index/generator v0.0.0-20220222194908-7a90a4214f3e
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/mux v1.7.3 // indirect
github.com/hashicorp/go-version v1.4.0
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
github.com/opencontainers/image-spec v1.0.1
github.com/prometheus/client_golang v1.11.0
Expand Down
Loading