Skip to content

Commit

Permalink
conditions updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Jun 17, 2020
1 parent 95f9150 commit 81a6c40
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"versions": "\u003e=7.0.0 \u003c=7.5.0"
}
},
"Conditions": {
"elasticsearch": "~7.9.0"
"conditions": {
"kibana.version": "~7.9.0"
},
"screenshots": [
{
Expand Down
10 changes: 5 additions & 5 deletions docs/api/search-kibana721.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"version": "0.0.2"
},
{
"description": "This is the example integration",
"download": "/epr/example/example-1.0.0.tar.gz",
"description": "This is the example integration.",
"download": "/epr/example/example-0.0.2.tar.gz",
"name": "example",
"path": "/package/example/1.0.0",
"title": "Example Integration",
"path": "/package/example/0.0.2",
"title": "Example",
"type": "integration",
"version": "1.0.0"
"version": "0.0.2"
},
{
"description": "This is the foo integration",
Expand Down
2 changes: 1 addition & 1 deletion testdata/package/example/1.0.0/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type: integration
release: ga

conditions:
kibana.version: "~7.9.0"
kibana.version: "~7.0.0"

requirement:
elasticsearch:
Expand Down
34 changes: 32 additions & 2 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Package struct {
Release string `config:"release,omitempty" json:"release,omitempty"`
Removable bool `config:"removable" json:"removable"`
Requirement Requirement `config:"requirement" json:"requirement"`
Conditions Conditions `config:"conditions"`
Conditions Conditions `config:"conditions" json:"conditions"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Assets []string `config:"assets,omitempty" json:"assets,omitempty" yaml:"assets,omitempty"`
Expand Down Expand Up @@ -71,7 +71,8 @@ type Requirement struct {
}

type Conditions struct {
KibanaVersion string `config:"kibana.version" json:"elasticsearch,omitempty" yaml:"elasticsearch"`
KibanaVersion string `config:"kibana.version,omitempty" json:"kibana.version,omitempty" yaml:"kibana.version,omitempty"`
kibanaVersion *semver.Constraints
}

type ProductRequirement struct {
Expand Down Expand Up @@ -147,6 +148,13 @@ func NewPackage(basePath string) (*Package, error) {
}
}

if p.Conditions.KibanaVersion != "" {
p.Conditions.kibanaVersion, err = semver.NewConstraint(p.Conditions.KibanaVersion)
if err != nil {
return nil, errors.Wrapf(err, "invalid Kibana versions range: %s", p.Requirement.Kibana.Versions)
}
}

if p.Requirement.Kibana.Versions != "" {
p.Requirement.Kibana.semVerRange, err = semver.NewConstraint(p.Requirement.Kibana.Versions)
if err != nil {
Expand Down Expand Up @@ -219,11 +227,17 @@ func (p *Package) HasCategory(category string) bool {

func (p *Package) HasKibanaVersion(version *semver.Version) bool {

if p.Conditions.kibanaVersion != nil {
return p.HasKibanaVersion2(version)
}

// If the version is not specified, it is for all versions
if p.Requirement.Kibana.Versions == "" {
return true
}

log.Println(p.Conditions.kibanaVersion)

if version != nil {
if !p.Requirement.Kibana.semVerRange.Check(version) {
return false
Expand All @@ -232,6 +246,22 @@ func (p *Package) HasKibanaVersion(version *semver.Version) bool {
return true
}

func (p *Package) HasKibanaVersion2(version *semver.Version) bool {
// If the version is not specified, it is for all versions
if p.Conditions.KibanaVersion == "" {
return true
}

log.Println(p.Conditions.kibanaVersion)

if version != nil {
if !p.Conditions.kibanaVersion.Check(version) {
return false
}
}
return true
}

func (p *Package) IsNewer(pp Package) bool {
return p.versionSemVer.GreaterThan(pp.versionSemVer)
}
Expand Down

0 comments on commit 81a6c40

Please sign in to comment.