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

Add Kibana min/max validation #99

Merged
merged 2 commits into from
Sep 11, 2019
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 36 additions & 16 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"

"github.com/blang/semver"

"gopkg.in/yaml.v2"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
32 changes: 32 additions & 0 deletions util/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down