diff --git a/CHANGELOG.md b/CHANGELOG.md index 071daa4b7..20c382eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Add validation check that Kibana min/max are valid semver versions. [#99](https://github.com/elastic/integrations-registry/pull/99) + ### Changed ### Deprecated diff --git a/go.mod b/go.mod index 015388dcb..2db4d5d07 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/elastic/go-ucfg v0.7.0 github.com/gorilla/mux v1.7.2 github.com/magefile/mage v1.8.0 + github.com/pkg/errors v0.8.1 github.com/stretchr/testify v1.4.0 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 1e5fd5e7e..32741823c 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/magefile/mage v1.8.0 h1:mzL+xIopvPURVBwHG9A50JcjBO+xV3b5iZ7khFRI+5E= github.com/magefile/mage v1.8.0/go.mod h1:IUDi13rsHje59lecXokTfGX0QIzO45uVPlXnJYsXepA= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/magefile.go b/magefile.go index 875b56cb7..830d0d8c1 100644 --- a/magefile.go +++ b/magefile.go @@ -125,7 +125,7 @@ func buildPackage(packagesBasePath, path string) error { // Build package endpoint p, err := util.NewPackage(".", path) if err != nil { - return err + return fmt.Errorf("Error creating package: %s: %s", path, err) } // Checks if the package is valid diff --git a/util/package.go b/util/package.go index 941841a33..de2990727 100644 --- a/util/package.go +++ b/util/package.go @@ -7,6 +7,8 @@ import ( "path/filepath" "strings" + "github.com/pkg/errors" + "github.com/blang/semver" "gopkg.in/yaml.v2" @@ -19,20 +21,24 @@ type Package struct { Title *string `yaml:"title,omitempty" json:"title,omitempty"` Version string `yaml:"version" json:"version"` versionSemVer semver.Version - Description string `yaml:"description" json:"description"` - Type string `yaml:"type" json:"type"` - Categories []string `yaml:"categories" json:"categories"` - Requirement struct { - Kibana struct { - Min string `yaml:"version.min" json:"version.min"` - Max string `yaml:"version.max" json:"version.max"` - minSemVer semver.Version - maxSemVer semver.Version - } `yaml:"kibana" json:"kibana"` - } `yaml:"requirement" json:"requirement"` - Screenshots []Image `yaml:"screenshots,omitempty" json:"screenshots,omitempty"` - Icons []Image `yaml:"icons,omitempty" json:"icons,omitempty"` - Assets []string `yaml:"assets,omitempty" json:"assets,omitempty"` + Description string `yaml:"description" json:"description"` + Type string `yaml:"type" json:"type"` + Categories []string `yaml:"categories" json:"categories"` + Requirement Requirement `yaml:"requirement" json:"requirement"` + Screenshots []Image `yaml:"screenshots,omitempty" json:"screenshots,omitempty"` + Icons []Image `yaml:"icons,omitempty" json:"icons,omitempty"` + Assets []string `yaml:"assets,omitempty" json:"assets,omitempty"` +} + +type Requirement struct { + Kibana Kibana `yaml:"kibana" json:"kibana"` +} + +type Kibana struct { + Min string `yaml:"version.min" json:"version.min"` + Max string `yaml:"version.max" json:"version.max"` + minSemVer semver.Version + maxSemVer semver.Version } type Image struct { @@ -80,14 +86,14 @@ func NewPackage(basePath, packageName string) (*Package, error) { if p.Requirement.Kibana.Max != "" { p.Requirement.Kibana.maxSemVer, err = semver.Parse(p.Requirement.Kibana.Max) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "invalid Kibana max version: %s", p.Requirement.Kibana.Max) } } if p.Requirement.Kibana.Min != "" { p.Requirement.Kibana.minSemVer, err = semver.Parse(p.Requirement.Kibana.Min) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "invalid Kibana min version: %s", p.Requirement.Kibana.Min) } } @@ -197,5 +203,19 @@ func (p *Package) Validate() error { return fmt.Errorf("no description set") } + if p.Requirement.Kibana.Max != "" { + _, err := semver.Parse(p.Requirement.Kibana.Max) + if err != nil { + return fmt.Errorf("invalid max kibana version: %s, %s", p.Requirement.Kibana.Max, err) + } + } + + if p.Requirement.Kibana.Min != "" { + _, err := semver.Parse(p.Requirement.Kibana.Min) + if err != nil { + return fmt.Errorf("invalid min Kibana version: %s, %s", p.Requirement.Kibana.Min, err) + } + } + return nil } diff --git a/util/package_test.go b/util/package_test.go index 8c6c77461..929435464 100644 --- a/util/package_test.go +++ b/util/package_test.go @@ -26,10 +26,42 @@ var packageTests = []struct { false, "missing description", }, + { + Package{ + Title: &title, + Requirement: Requirement{ + Kibana{ + Min: "1.2.3", + Max: "bar", + }, + }, + }, + false, + "invalid Kibana max version", + }, + { + Package{ + Title: &title, + Requirement: Requirement{ + Kibana{ + Min: "foo", + Max: "4.5.6", + }, + }, + }, + false, + "invalid Kibana min version", + }, { Package{ Title: &title, Description: "my description", + Requirement: Requirement{ + Kibana{ + Min: "1.2.3", + Max: "4.5.6", + }, + }, }, true, "complete",