diff --git a/testdata/generated/package.json b/testdata/generated/package.json index 302d396d0..a6ebcc669 100644 --- a/testdata/generated/package.json +++ b/testdata/generated/package.json @@ -15,7 +15,9 @@ "azure" ], "conditions": { - "kibana.version": "~7.x.x" + "kibana": { + "version": "~7.x.x" + } }, "screenshots": [ { diff --git a/testdata/generated/package/elasticsearch_privileges/1.0.0/index.json b/testdata/generated/package/elasticsearch_privileges/1.0.0/index.json index fc14d4112..aef74f17b 100644 --- a/testdata/generated/package/elasticsearch_privileges/1.0.0/index.json +++ b/testdata/generated/package/elasticsearch_privileges/1.0.0/index.json @@ -14,7 +14,9 @@ "custom" ], "conditions": { - "kibana.version": "\u003e=7.16.0" + "kibana": { + "version": "\u003e=7.16.0" + } }, "assets": [ "/package/elasticsearch_privileges/1.0.0/manifest.yml", diff --git a/testdata/generated/package/example/0.0.2/index.json b/testdata/generated/package/example/0.0.2/index.json index c9a52c11f..9fd2ad39c 100644 --- a/testdata/generated/package/example/0.0.2/index.json +++ b/testdata/generated/package/example/0.0.2/index.json @@ -14,7 +14,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e=6.0.0" + "kibana": { + "version": "\u003e=6.0.0" + } }, "assets": [ "/package/example/0.0.2/manifest.yml", diff --git a/testdata/generated/package/example/1.0.0/index.json b/testdata/generated/package/example/1.0.0/index.json index 302d396d0..a6ebcc669 100644 --- a/testdata/generated/package/example/1.0.0/index.json +++ b/testdata/generated/package/example/1.0.0/index.json @@ -15,7 +15,9 @@ "azure" ], "conditions": { - "kibana.version": "~7.x.x" + "kibana": { + "version": "~7.x.x" + } }, "screenshots": [ { diff --git a/testdata/generated/package/foo/1.0.0/index.json b/testdata/generated/package/foo/1.0.0/index.json index 5e75dd1c8..2295b6f22 100644 --- a/testdata/generated/package/foo/1.0.0/index.json +++ b/testdata/generated/package/foo/1.0.0/index.json @@ -14,7 +14,9 @@ "custom" ], "conditions": { - "kibana.version": "\u003e=7.0.0" + "kibana": { + "version": "\u003e=7.0.0" + } }, "assets": [ "/package/foo/1.0.0/manifest.yml", diff --git a/testdata/generated/package/hidden/1.0.0/index.json b/testdata/generated/package/hidden/1.0.0/index.json index 7ce78e11c..04817d387 100644 --- a/testdata/generated/package/hidden/1.0.0/index.json +++ b/testdata/generated/package/hidden/1.0.0/index.json @@ -14,7 +14,9 @@ "custom" ], "conditions": { - "kibana.version": "\u003e=7.0.0" + "kibana": { + "version": "\u003e=7.0.0" + } }, "assets": [ "/package/hidden/1.0.0/manifest.yml", diff --git a/testdata/generated/package/ilm_policy/1.0.0/index.json b/testdata/generated/package/ilm_policy/1.0.0/index.json index 4914e8237..564016ce0 100644 --- a/testdata/generated/package/ilm_policy/1.0.0/index.json +++ b/testdata/generated/package/ilm_policy/1.0.0/index.json @@ -14,7 +14,9 @@ "custom" ], "conditions": { - "kibana.version": "\u003e=7.0.0" + "kibana": { + "version": "\u003e=7.0.0" + } }, "assets": [ "/package/ilmpolicy/1.0.0/manifest.yml", diff --git a/testdata/generated/package/input_groups/0.0.1/index.json b/testdata/generated/package/input_groups/0.0.1/index.json index 275cc2d81..8004ff89b 100644 --- a/testdata/generated/package/input_groups/0.0.1/index.json +++ b/testdata/generated/package/input_groups/0.0.1/index.json @@ -24,7 +24,9 @@ "cloud" ], "conditions": { - "kibana.version": "~7.x.x" + "kibana": { + "version": "~7.x.x" + } }, "screenshots": [ { diff --git a/testdata/generated/package/input_level_templates/1.0.0/index.json b/testdata/generated/package/input_level_templates/1.0.0/index.json index 39afc403f..68c4bd7af 100644 --- a/testdata/generated/package/input_level_templates/1.0.0/index.json +++ b/testdata/generated/package/input_level_templates/1.0.0/index.json @@ -14,7 +14,9 @@ "custom" ], "conditions": { - "kibana.version": "\u003e=7.11.0" + "kibana": { + "version": "\u003e=7.11.0" + } }, "assets": [ "/package/input_level_templates/1.0.0/manifest.yml", diff --git a/testdata/generated/package/longdocs/1.0.4/index.json b/testdata/generated/package/longdocs/1.0.4/index.json index 47ff00db1..4ebf9aad4 100644 --- a/testdata/generated/package/longdocs/1.0.4/index.json +++ b/testdata/generated/package/longdocs/1.0.4/index.json @@ -22,7 +22,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e6.7.0" + "kibana": { + "version": "\u003e6.7.0" + } }, "assets": [ "/package/longdocs/1.0.4/manifest.yml", diff --git a/testdata/generated/package/multiversion/1.0.3/index.json b/testdata/generated/package/multiversion/1.0.3/index.json index 7809fccb1..c305a4b99 100644 --- a/testdata/generated/package/multiversion/1.0.3/index.json +++ b/testdata/generated/package/multiversion/1.0.3/index.json @@ -22,7 +22,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e6.7.0" + "kibana": { + "version": "\u003e6.7.0" + } }, "assets": [ "/package/multiversion/1.0.3/changelog.yml", diff --git a/testdata/generated/package/multiversion/1.0.4/index.json b/testdata/generated/package/multiversion/1.0.4/index.json index 87b4f24a5..6b5fd1dfb 100644 --- a/testdata/generated/package/multiversion/1.0.4/index.json +++ b/testdata/generated/package/multiversion/1.0.4/index.json @@ -22,7 +22,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e6.7.0" + "kibana": { + "version": "\u003e6.7.0" + } }, "assets": [ "/package/multiversion/1.0.4/changelog.yml", diff --git a/testdata/generated/package/multiversion/1.1.0/index.json b/testdata/generated/package/multiversion/1.1.0/index.json index ab9354aab..a6d572c99 100644 --- a/testdata/generated/package/multiversion/1.1.0/index.json +++ b/testdata/generated/package/multiversion/1.1.0/index.json @@ -22,7 +22,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e6.7.0" + "kibana": { + "version": "\u003e6.7.0" + } }, "assets": [ "/package/multiversion/1.1.0/changelog.yml", diff --git a/testdata/generated/package/reference/1.0.0/index.json b/testdata/generated/package/reference/1.0.0/index.json index 51d488c6d..84471bc05 100644 --- a/testdata/generated/package/reference/1.0.0/index.json +++ b/testdata/generated/package/reference/1.0.0/index.json @@ -23,7 +23,9 @@ "web" ], "conditions": { - "kibana.version": "\u003e6.7.0 \u003c7.6.0" + "kibana": { + "version": "\u003e6.7.0 \u003c7.6.0" + } }, "assets": [ "/package/reference/1.0.0/changelog.yml", diff --git a/testdata/generated/package/traces/1.0.0/index.json b/testdata/generated/package/traces/1.0.0/index.json index d8cee136a..2d3e45b89 100644 --- a/testdata/generated/package/traces/1.0.0/index.json +++ b/testdata/generated/package/traces/1.0.0/index.json @@ -14,7 +14,9 @@ "monitoring" ], "conditions": { - "kibana.version": "~7.x.x" + "kibana": { + "version": "~7.x.x" + } }, "assets": [ "/package/fakeapm/1.0.0/manifest.yml", diff --git a/util/package.go b/util/package.go index 417290941..99a254d5a 100644 --- a/util/package.go +++ b/util/package.go @@ -107,8 +107,13 @@ type PolicyTemplate struct { } type Conditions struct { - KibanaVersion string `config:"kibana.version,omitempty" json:"kibana.version,omitempty" yaml:"kibana.version,omitempty"` - kibanaConstraint *semver.Constraints + Kibana *KibanaConditions `config:"kibana,omitempty" json:"kibana,omitempty" yaml:"kibana,omitempty"` +} + +// KibanaConditions defines conditions for Kibana (e.g. required version). +type KibanaConditions struct { + Version string `config:"version" json:"version" yaml:"version"` + constraint *semver.Constraints } type Version struct { @@ -239,10 +244,10 @@ func NewPackage(basePath string) (*Package, error) { } } - if p.Conditions != nil && p.Conditions.KibanaVersion != "" { - p.Conditions.kibanaConstraint, err = semver.NewConstraint(p.Conditions.KibanaVersion) + if p.Conditions != nil && p.Conditions.Kibana != nil { + p.Conditions.Kibana.constraint, err = semver.NewConstraint(p.Conditions.Kibana.Version) if err != nil { - return nil, errors.Wrapf(err, "invalid Kibana versions range: %s", p.Conditions.KibanaVersion) + return nil, errors.Wrapf(err, "invalid Kibana versions range: %s", p.Conditions.Kibana.Version) } } @@ -299,13 +304,12 @@ func (p *Package) HasPolicyTemplateWithCategory(category string) bool { } func (p *Package) HasKibanaVersion(version *semver.Version) bool { - // If the version is not specified, it is for all versions - if p.Conditions == nil || version == nil || p.Conditions.kibanaConstraint == nil { + if p.Conditions == nil || p.Conditions.Kibana == nil || p.Conditions.Kibana.constraint == nil|| version == nil { return true } - return p.Conditions.kibanaConstraint.Check(version) + return p.Conditions.Kibana.constraint.Check(version) } func (p *Package) IsNewerOrEqual(pp Package) bool { diff --git a/util/package_test.go b/util/package_test.go index b9e294e76..9a08acb85 100644 --- a/util/package_test.go +++ b/util/package_test.go @@ -38,9 +38,9 @@ var packageTests = []struct { Package{ BasePackage: BasePackage{ Title: &title, - }, - Conditions: &Conditions{ - KibanaVersion: "bar", + Conditions: &Conditions{ + Kibana: &KibanaConditions{Version: "bar"}, + }, }, }, false, @@ -51,9 +51,9 @@ var packageTests = []struct { BasePackage: BasePackage{ Title: &title, Description: "my description", - }, - Conditions: &Conditions{ - KibanaVersion: ">=1.2.3 <=4.5.6", + Conditions: &Conditions{ + Kibana: &KibanaConditions{Version: ">=1.2.3 <=4.5.6"}, + }, }, Categories: []string{"custom", "foo"}, }, @@ -189,8 +189,12 @@ func TestHasKibanaVersion(t *testing.T) { assert.NoError(t, err) p := Package{ - Conditions: &Conditions{ - kibanaConstraint: constraint, + BasePackage: BasePackage{ + Conditions: &Conditions{ + Kibana: &KibanaConditions{ + constraint: constraint, + }, + }, }, }