Skip to content

Commit

Permalink
Fill deprecated license field with the value of the new subscription …
Browse files Browse the repository at this point in the history
…condition (#826)

Add a compatibility layer to copy the new value into the old field.
  • Loading branch information
jsoriano authored Jul 19, 2022
1 parent b764e3b commit 2013a47
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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"`
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions packages/testdata/marshaler/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand All @@ -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",
Expand Down Expand Up @@ -1544,6 +1547,9 @@
"conditions": {
"kibana": {
"version": "\u003e6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand All @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion testdata/generated/package/example/1.2.0-rc1/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand All @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion testdata/generated/package/longdocs/1.0.4/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-category-custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-category-datastore-prerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-category-datastore.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-category-web-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-category-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-kibana721.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-kibana800.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
6 changes: 6 additions & 0 deletions testdata/generated/search-package-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand Down Expand Up @@ -356,6 +359,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search-package-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
6 changes: 6 additions & 0 deletions testdata/generated/search-package-prerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
"conditions": {
"kibana": {
"version": "^7.16.0 || ^8.0.0"
},
"elastic": {
"subscription": "gold"
}
},
"owner": {
Expand Down Expand Up @@ -356,6 +359,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
3 changes: 3 additions & 0 deletions testdata/generated/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"conditions": {
"kibana": {
"version": ">6.7.0"
},
"elastic": {
"subscription": "gold"
}
},
"categories": [
Expand Down
2 changes: 2 additions & 0 deletions testdata/package/example/1.2.0-rc1/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion testdata/package/longdocs/1.0.4/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2013a47

Please sign in to comment.