Skip to content

Commit

Permalink
Adjust API output for Kibana compatibility version (#134)
Browse files Browse the repository at this point in the history
Previously the json output for the compatible Kibana version looked as following:

```
"kibana": {
  "version.min": "7.0.0"
}
```

As this causes troubles on the JS side, it is changed to:

```
"kibana": {
  "version": {
    "min": "7.0.0"
  }
}
```

This should make it easier to parse.

To make it for package creators still possible to use the short notation in the manifest file, go-ucfg is used to read the manifest file so we get this functioanlity for free.

An additional change which happened in this PR is that if a max or min version are empty, it is not part of the API output anymore.

Closes #44
  • Loading branch information
ruflin authored Oct 24, 2019
1 parent 93b46f7 commit dad16af
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking changes

* Package Kibana compatiblity version is changed to `"kibana": { "max": "1.2.3"}` [#134](https://github.com/elastic/integrations-registry/pull/134)


### Bugfixes

* Change empty /search API output from `null` to `[]`. [#111](https://github.com/elastic/integrations-registry/pull/111)
Expand Down
5 changes: 3 additions & 2 deletions docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
],
"requirement": {
"kibana": {
"version.min": "7.0.0",
"version.max": ""
"version": {
"min": "7.0.0"
}
}
},
"screenshots": [
Expand Down
5 changes: 3 additions & 2 deletions testdata/package/example-0.0.2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
],
"requirement": {
"kibana": {
"version.min": "6.0.0",
"version.max": ""
"version": {
"min": "6.0.0"
}
}
},
"assets": [
Expand Down
5 changes: 3 additions & 2 deletions testdata/package/example-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
],
"requirement": {
"kibana": {
"version.min": "7.0.0",
"version.max": ""
"version": {
"min": "7.0.0"
}
}
},
"screenshots": [
Expand Down
5 changes: 3 additions & 2 deletions testdata/package/foo-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
],
"requirement": {
"kibana": {
"version.min": "7.0.0",
"version.max": ""
"version": {
"min": "7.0.0"
}
}
},
"assets": [
Expand Down
3 changes: 1 addition & 2 deletions testdata/package/internal-1.2.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"categories": [],
"requirement": {
"kibana": {
"version.min": "",
"version.max": ""
"version": {}
}
},
"assets": [
Expand Down
48 changes: 25 additions & 23 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ package util

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"

"github.com/blang/semver"

"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/yaml"
)

const defaultType = "integration"
Expand Down Expand Up @@ -45,12 +46,16 @@ type Requirement struct {
}

type Kibana struct {
Min string `yaml:"version.min" json:"version.min"`
Max string `yaml:"version.max" json:"version.max"`
Version Version `yaml:"version,omitempty" json:"version,omitempty"`
minSemVer semver.Version
maxSemVer semver.Version
}

type Version struct {
Min string `yaml:"min,omitempty" json:"min,omitempty"`
Max string `yaml:"max,omitempty" json:"max,omitempty"`
}

type Image struct {
Src string `yaml:"src" json:"src,omitempty"`
Title string `yaml:"title" json:"title,omitempty"`
Expand All @@ -66,13 +71,10 @@ func (i Image) getPath(p *Package) string {
// The package name passed contains the version of the package.
func NewPackage(basePath, packageName string) (*Package, error) {

manifest, err := ioutil.ReadFile(basePath + "/" + packageName + "/manifest.yml")
if err != nil {
return nil, err
}
manifest, err := yaml.NewConfigWithFile(basePath+"/"+packageName+"/manifest.yml", ucfg.PathSep("."))

var p = &Package{}
err = yaml.Unmarshal(manifest, p)
err = manifest.Unpack(p)
if err != nil {
return nil, err
}
Expand All @@ -93,17 +95,17 @@ func NewPackage(basePath, packageName string) (*Package, error) {
}
}

if p.Requirement.Kibana.Max != "" {
p.Requirement.Kibana.maxSemVer, err = semver.Parse(p.Requirement.Kibana.Max)
if p.Requirement.Kibana.Version.Max != "" {
p.Requirement.Kibana.maxSemVer, err = semver.Parse(p.Requirement.Kibana.Version.Max)
if err != nil {
return nil, errors.Wrapf(err, "invalid Kibana max version: %s", p.Requirement.Kibana.Max)
return nil, errors.Wrapf(err, "invalid Kibana max version: %s", p.Requirement.Kibana.Version.Max)
}
}

if p.Requirement.Kibana.Min != "" {
p.Requirement.Kibana.minSemVer, err = semver.Parse(p.Requirement.Kibana.Min)
if p.Requirement.Kibana.Version.Min != "" {
p.Requirement.Kibana.minSemVer, err = semver.Parse(p.Requirement.Kibana.Version.Min)
if err != nil {
return nil, errors.Wrapf(err, "invalid Kibana min version: %s", p.Requirement.Kibana.Min)
return nil, errors.Wrapf(err, "invalid Kibana min version: %s", p.Requirement.Kibana.Version.Min)
}
}

Expand Down Expand Up @@ -142,13 +144,13 @@ func (p *Package) HasCategory(category string) bool {

func (p *Package) HasKibanaVersion(version *semver.Version) bool {
if version != nil {
if p.Requirement.Kibana.Max != "" {
if p.Requirement.Kibana.Version.Max != "" {
if version.GT(p.Requirement.Kibana.maxSemVer) {
return false
}
}

if p.Requirement.Kibana.Min != "" {
if p.Requirement.Kibana.Version.Min != "" {
if version.LT(p.Requirement.Kibana.minSemVer) {
return false
}
Expand Down Expand Up @@ -228,17 +230,17 @@ func (p *Package) Validate() error {
return fmt.Errorf("no description set")
}

if p.Requirement.Kibana.Max != "" {
_, err := semver.Parse(p.Requirement.Kibana.Max)
if p.Requirement.Kibana.Version.Max != "" {
_, err := semver.Parse(p.Requirement.Kibana.Version.Max)
if err != nil {
return fmt.Errorf("invalid max kibana version: %s, %s", p.Requirement.Kibana.Max, err)
return fmt.Errorf("invalid max kibana version: %s, %s", p.Requirement.Kibana.Version.Max, err)
}
}

if p.Requirement.Kibana.Min != "" {
_, err := semver.Parse(p.Requirement.Kibana.Min)
if p.Requirement.Kibana.Version.Min != "" {
_, err := semver.Parse(p.Requirement.Kibana.Version.Min)
if err != nil {
return fmt.Errorf("invalid min Kibana version: %s, %s", p.Requirement.Kibana.Min, err)
return fmt.Errorf("invalid min Kibana version: %s, %s", p.Requirement.Kibana.Version.Min, err)
}
}

Expand Down
18 changes: 12 additions & 6 deletions util/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ var packageTests = []struct {
Title: &title,
Requirement: Requirement{
Kibana{
Min: "1.2.3",
Max: "bar",
Version: Version{
Min: "1.2.3",
Max: "bar",
},
},
},
},
Expand All @@ -48,8 +50,10 @@ var packageTests = []struct {
Title: &title,
Requirement: Requirement{
Kibana{
Min: "foo",
Max: "4.5.6",
Version: Version{
Min: "foo",
Max: "4.5.6",
},
},
},
},
Expand All @@ -62,8 +66,10 @@ var packageTests = []struct {
Description: "my description",
Requirement: Requirement{
Kibana{
Min: "1.2.3",
Max: "4.5.6",
Version: Version{
Min: "1.2.3",
Max: "4.5.6",
},
},
},
Categories: []string{"metrics", "logs", "foo"},
Expand Down

0 comments on commit dad16af

Please sign in to comment.