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

De-dot 'kibana.version' in /package JSON responses #733

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking changes

* Change format of responses to `/package` to make `{"constraint": {"kibana.version": "7.16.0"}}` be `{"constraint": {"kibana": {"version": "7.16.0"}}}`. [#733](https://github.com/elastic/package-registry/pull/733)

### Bugfixes

### Added
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"azure"
],
"conditions": {
"kibana.version": "~7.x.x"
"kibana": {
"version": "~7.x.x"
}
},
"screenshots": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/example/0.0.2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/example/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"azure"
],
"conditions": {
"kibana.version": "~7.x.x"
"kibana": {
"version": "~7.x.x"
}
},
"screenshots": [
{
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/foo/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/hidden/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/ilm_policy/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/input_groups/0.0.1/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"cloud"
],
"conditions": {
"kibana.version": "~7.x.x"
"kibana": {
"version": "~7.x.x"
}
},
"screenshots": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/longdocs/1.0.4/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"web"
],
"conditions": {
"kibana.version": "\u003e6.7.0"
"kibana": {
"version": "\u003e6.7.0"
}
},
"assets": [
"/package/longdocs/1.0.4/manifest.yml",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/multiversion/1.0.3/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"web"
],
"conditions": {
"kibana.version": "\u003e6.7.0"
"kibana": {
"version": "\u003e6.7.0"
}
},
"assets": [
"/package/multiversion/1.0.3/changelog.yml",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/multiversion/1.0.4/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"web"
],
"conditions": {
"kibana.version": "\u003e6.7.0"
"kibana": {
"version": "\u003e6.7.0"
}
},
"assets": [
"/package/multiversion/1.0.4/changelog.yml",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/multiversion/1.1.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"web"
],
"conditions": {
"kibana.version": "\u003e6.7.0"
"kibana": {
"version": "\u003e6.7.0"
}
},
"assets": [
"/package/multiversion/1.1.0/changelog.yml",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/reference/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion testdata/generated/package/traces/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"monitoring"
],
"conditions": {
"kibana.version": "~7.x.x"
"kibana": {
"version": "~7.x.x"
}
},
"assets": [
"/package/fakeapm/1.0.0/manifest.yml",
Expand Down
20 changes: 12 additions & 8 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions util/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var packageTests = []struct {
Title: &title,
},
Conditions: &Conditions{
KibanaVersion: "bar",
Kibana: &KibanaConditions{Version: "bar"},
},
},
false,
Expand All @@ -53,7 +53,7 @@ var packageTests = []struct {
Description: "my description",
},
Conditions: &Conditions{
KibanaVersion: ">=1.2.3 <=4.5.6",
Kibana: &KibanaConditions{Version: ">=1.2.3 <=4.5.6"},
},
Categories: []string{"custom", "foo"},
},
Expand Down Expand Up @@ -190,7 +190,9 @@ func TestHasKibanaVersion(t *testing.T) {

p := Package{
Conditions: &Conditions{
kibanaConstraint: constraint,
Kibana: &KibanaConditions{
constraint: constraint,
},
},
}

Expand Down