From 2013a47d68b5bd87100483d2e3d59e2c469b699d Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 19 Jul 2022 13:49:22 +0200 Subject: [PATCH] Fill deprecated license field with the value of the new subscription condition (#826) Add a compatibility layer to copy the new value into the old field. --- CHANGELOG.md | 2 ++ packages/package.go | 15 +++++++++++++-- packages/testdata/marshaler/packages.json | 10 ++++++++-- .../package/example/1.2.0-rc1/index.json | 5 ++++- .../generated/package/longdocs/1.0.4/index.json | 5 ++++- testdata/generated/search-all.json | 3 +++ testdata/generated/search-category-custom.json | 3 +++ .../search-category-datastore-prerelease.json | 3 +++ testdata/generated/search-category-datastore.json | 3 +++ testdata/generated/search-category-web-all.json | 3 +++ testdata/generated/search-category-web.json | 3 +++ testdata/generated/search-kibana721.json | 3 +++ testdata/generated/search-kibana800.json | 3 +++ .../generated/search-package-experimental.json | 6 ++++++ testdata/generated/search-package-internal.json | 3 +++ testdata/generated/search-package-prerelease.json | 6 ++++++ testdata/generated/search.json | 3 +++ testdata/package/example/1.2.0-rc1/manifest.yml | 2 ++ testdata/package/longdocs/1.0.4/manifest.yml | 3 ++- 19 files changed, 77 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee406da4..8c107d426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Add `elastic.subscription` condition to package index metadata, use this value for backwards compatibility with previous `license` field. [#826](https://github.com/elastic/package-registry/pull/826) + ### Deprecated ### Known Issues diff --git a/packages/package.go b/packages/package.go index 083019e5e..0a5d347c5 100644 --- a/packages/package.go +++ b/packages/package.go @@ -122,7 +122,8 @@ type PolicyTemplate struct { } type Conditions struct { - Kibana *KibanaConditions `config:"kibana,omitempty" json:"kibana,omitempty" yaml:"kibana,omitempty"` + Kibana *KibanaConditions `config:"kibana,omitempty" json:"kibana,omitempty" yaml:"kibana,omitempty"` + Elastic *ElasticConditions `config:"elastic,omitempty" json:"elastic,omitempty" yaml"elastic,omitempty"` } // KibanaConditions defines conditions for Kibana (e.g. required version). @@ -131,6 +132,11 @@ type KibanaConditions struct { constraint *semver.Constraints } +// ElasticConditions defines conditions related to Elastic subscriptions or partnerships. +type ElasticConditions struct { + Subscription string `config:"subscription" json:"subscription" yaml:"subscription"` +} + type Version struct { Min string `config:"min,omitempty" json:"min,omitempty"` Max string `config:"max,omitempty" json:"max,omitempty"` @@ -251,7 +257,12 @@ func NewPackage(basePath string, fsBuilder FileSystemBuilder) (*Package, error) // If not license is set, basic is assumed if p.License == "" { - p.License = DefaultLicense + // Keep compatibility with deprecated license field. + if p.Conditions != nil && p.Conditions.Elastic != nil && p.Conditions.Elastic.Subscription != "" { + p.License = p.Conditions.Elastic.Subscription + } else { + p.License = DefaultLicense + } } err = p.setRuntimeFields() diff --git a/packages/testdata/marshaler/packages.json b/packages/testdata/marshaler/packages.json index f05bffdb0..f0cf5f958 100644 --- a/packages/testdata/marshaler/packages.json +++ b/packages/testdata/marshaler/packages.json @@ -806,6 +806,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { @@ -818,7 +821,7 @@ ], "format_version": "1.0.0", "readme": "/package/example/1.2.0-rc1/docs/README.md", - "license": "basic", + "license": "gold", "screenshots": [ { "src": "/img/kibana-envoyproxy.jpg", @@ -1544,6 +1547,9 @@ "conditions": { "kibana": { "version": "\u003e6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ @@ -1552,7 +1558,7 @@ ], "format_version": "1.0.0", "readme": "/package/longdocs/1.0.4/docs/README.md", - "license": "basic", + "license": "gold", "assets": [ "/package/longdocs/1.0.4/manifest.yml", "/package/longdocs/1.0.4/docs/README.md", diff --git a/testdata/generated/package/example/1.2.0-rc1/index.json b/testdata/generated/package/example/1.2.0-rc1/index.json index 0ece178ab..44560cfe0 100644 --- a/testdata/generated/package/example/1.2.0-rc1/index.json +++ b/testdata/generated/package/example/1.2.0-rc1/index.json @@ -10,6 +10,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { @@ -22,7 +25,7 @@ ], "format_version": "1.0.0", "readme": "/package/example/1.2.0-rc1/docs/README.md", - "license": "basic", + "license": "gold", "screenshots": [ { "src": "/img/kibana-envoyproxy.jpg", diff --git a/testdata/generated/package/longdocs/1.0.4/index.json b/testdata/generated/package/longdocs/1.0.4/index.json index 51d518028..abf6229b8 100644 --- a/testdata/generated/package/longdocs/1.0.4/index.json +++ b/testdata/generated/package/longdocs/1.0.4/index.json @@ -17,6 +17,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ @@ -25,7 +28,7 @@ ], "format_version": "1.0.0", "readme": "/package/longdocs/1.0.4/docs/README.md", - "license": "basic", + "license": "gold", "assets": [ "/package/longdocs/1.0.4/manifest.yml", "/package/longdocs/1.0.4/docs/README.md", diff --git a/testdata/generated/search-all.json b/testdata/generated/search-all.json index 1315e5880..2dccecaf4 100644 --- a/testdata/generated/search-all.json +++ b/testdata/generated/search-all.json @@ -267,6 +267,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-category-custom.json b/testdata/generated/search-category-custom.json index 09c53d2c2..9c6db1595 100644 --- a/testdata/generated/search-category-custom.json +++ b/testdata/generated/search-category-custom.json @@ -171,6 +171,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-category-datastore-prerelease.json b/testdata/generated/search-category-datastore-prerelease.json index 254ce6900..0e68967a2 100644 --- a/testdata/generated/search-category-datastore-prerelease.json +++ b/testdata/generated/search-category-datastore-prerelease.json @@ -59,6 +59,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { diff --git a/testdata/generated/search-category-datastore.json b/testdata/generated/search-category-datastore.json index 254ce6900..0e68967a2 100644 --- a/testdata/generated/search-category-datastore.json +++ b/testdata/generated/search-category-datastore.json @@ -59,6 +59,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { diff --git a/testdata/generated/search-category-web-all.json b/testdata/generated/search-category-web-all.json index 5e5cbf1f4..b57e69a6f 100644 --- a/testdata/generated/search-category-web-all.json +++ b/testdata/generated/search-category-web-all.json @@ -18,6 +18,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-category-web.json b/testdata/generated/search-category-web.json index a6311242c..f67329901 100644 --- a/testdata/generated/search-category-web.json +++ b/testdata/generated/search-category-web.json @@ -18,6 +18,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-kibana721.json b/testdata/generated/search-kibana721.json index 51ad1339c..45ebc1e60 100644 --- a/testdata/generated/search-kibana721.json +++ b/testdata/generated/search-kibana721.json @@ -124,6 +124,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-kibana800.json b/testdata/generated/search-kibana800.json index 460038fc1..403494c74 100644 --- a/testdata/generated/search-kibana800.json +++ b/testdata/generated/search-kibana800.json @@ -167,6 +167,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-package-experimental.json b/testdata/generated/search-package-experimental.json index 2404a50ee..fc6b04d27 100644 --- a/testdata/generated/search-package-experimental.json +++ b/testdata/generated/search-package-experimental.json @@ -164,6 +164,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { @@ -356,6 +359,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-package-internal.json b/testdata/generated/search-package-internal.json index 26272b697..62019e324 100644 --- a/testdata/generated/search-package-internal.json +++ b/testdata/generated/search-package-internal.json @@ -203,6 +203,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search-package-prerelease.json b/testdata/generated/search-package-prerelease.json index 938966453..78c9cda56 100644 --- a/testdata/generated/search-package-prerelease.json +++ b/testdata/generated/search-package-prerelease.json @@ -164,6 +164,9 @@ "conditions": { "kibana": { "version": "^7.16.0 || ^8.0.0" + }, + "elastic": { + "subscription": "gold" } }, "owner": { @@ -356,6 +359,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/generated/search.json b/testdata/generated/search.json index 26272b697..62019e324 100644 --- a/testdata/generated/search.json +++ b/testdata/generated/search.json @@ -203,6 +203,9 @@ "conditions": { "kibana": { "version": ">6.7.0" + }, + "elastic": { + "subscription": "gold" } }, "categories": [ diff --git a/testdata/package/example/1.2.0-rc1/manifest.yml b/testdata/package/example/1.2.0-rc1/manifest.yml index 3c81bbe97..ddec4a8ba 100644 --- a/testdata/package/example/1.2.0-rc1/manifest.yml +++ b/testdata/package/example/1.2.0-rc1/manifest.yml @@ -13,6 +13,8 @@ owner.github: "ruflin" conditions: kibana: version: "^7.16.0 || ^8.0.0" + elastic: + subscription: "gold" screenshots: - src: /img/kibana-envoyproxy.jpg diff --git a/testdata/package/longdocs/1.0.4/manifest.yml b/testdata/package/longdocs/1.0.4/manifest.yml index 7f46d8b57..161c61fc9 100644 --- a/testdata/package/longdocs/1.0.4/manifest.yml +++ b/testdata/package/longdocs/1.0.4/manifest.yml @@ -11,11 +11,12 @@ description: > version: 1.0.4 categories: ["custom", "web"] release: ga -license: basic conditions: kibana: version: ">6.7.0" + elastic: + subscription: "gold" icons: - src: "/img/icon.svg"