- Notifications
You must be signed in to change notification settings - Fork 88
Release input package spec as GA #485
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits Select commit Hold shift + click to select a range
23779f4 ignore DS store files
hop-dev 195bece make input package spec GA
hop-dev 2f4f688 add new validator
hop-dev 8ff7bbb plumb in new validator + update tests
hop-dev b565ae4 updte changelog
hop-dev cf4fb0f make check
hop-dev 5d1ad36 add more unit tests
hop-dev 9840df4 allow nested keys for kibana version
hop-dev 3585867 revert changelog
hop-dev f761e13 use NewPackageFromFS to get vals
hop-dev 1d7a68d remove unused methods
hop-dev 784f2fd remove gitignore addition
hop-dev 17f86d1 Merge branch 'main' into make-input-pkg-spec-ga
hop-dev 33b135a re-add newline
hop-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions 121 code/go/internal/validator/semantic/validate_minimum_kibana_version.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
| | ||
| package semantic | ||
| | ||
| import ( | ||
| "regexp" | ||
| | ||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/pkg/errors" | ||
| | ||
| ve "github.com/elastic/package-spec/v2/code/go/internal/errors" | ||
| "github.com/elastic/package-spec/v2/code/go/internal/fspath" | ||
| "github.com/elastic/package-spec/v2/code/go/internal/packages" | ||
| "github.com/elastic/package-spec/v2/code/go/internal/pkgpath" | ||
| ) | ||
| | ||
| // ValidateMinimumKibanaVersion if the package is an input package, and the package version is >= 1.0.0, | ||
| // then the kibana version condition must be >= 8.8.0 | ||
| func ValidateMinimumKibanaVersion(fsys fspath.FS) ve.ValidationErrors { | ||
| pkg, err := packages.NewPackageFromFS(fsys.Path(), fsys) | ||
| if err != nil { | ||
| return ve.ValidationErrors{err} | ||
| } | ||
| | ||
| manifest, err := readManifest(fsys) | ||
| if err != nil { | ||
| return ve.ValidationErrors{err} | ||
| } | ||
| | ||
| kibanaVersionCondition, err := getKibanaVersionCondition(*manifest) | ||
| if err != nil { | ||
| return ve.ValidationErrors{err} | ||
| } | ||
| | ||
| err = validateMinimumKibanaVersion(pkg.Type, *pkg.Version, kibanaVersionCondition) | ||
| if err != nil { | ||
| return ve.ValidationErrors{err} | ||
| } | ||
| | ||
| return nil | ||
| } | ||
| | ||
| func validateMinimumKibanaVersion(packageType string, packageVersion semver.Version, kibanaVersionCondition string) error { | ||
| | ||
| if packageType != "input" { | ||
| return nil | ||
| } | ||
| | ||
| if packageVersion.LessThan(semver.MustParse("1.0.0")) { | ||
| return nil | ||
| } | ||
| | ||
| if kibanaVersionConditionIsGreaterThanOrEqualTo8_8_0(kibanaVersionCondition) { | ||
| return nil | ||
| } | ||
| | ||
| return errors.New("Warning: conditions.kibana.version must be ^8.8.0 or greater for non experimental input packages (version > 1.0.0)") | ||
| } | ||
| | ||
| func readManifest(fsys fspath.FS) (*pkgpath.File, error) { | ||
| manifestPath := "manifest.yml" | ||
| f, err := pkgpath.Files(fsys, manifestPath) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "can't locate manifest file") | ||
| } | ||
| | ||
| if len(f) != 1 { | ||
| return nil, errors.New("single manifest file expected") | ||
| } | ||
| | ||
| return &f[0], nil | ||
| } | ||
| | ||
| func getKibanaVersionCondition(manifest pkgpath.File) (string, error) { | ||
| | ||
| val, err := manifest.Values("$.conditions[\"kibana.version\"]") | ||
| if err != nil { | ||
| val, err = manifest.Values("$.conditions.kibana.version") | ||
| if err != nil { | ||
| return "", nil | ||
| } | ||
| } | ||
| | ||
| sVal, ok := val.(string) | ||
| if !ok { | ||
| return "", errors.New("manifest kibana version is not a string") | ||
| } | ||
| | ||
| return sVal, nil | ||
| } | ||
| | ||
| func kibanaVersionConditionIsGreaterThanOrEqualTo8_8_0(kibanaVersionCondition string) bool { | ||
hop-dev marked this conversation as resolved. Show resolved Hide resolved | ||
| if kibanaVersionCondition == "" { | ||
| return false | ||
| } | ||
| | ||
| if kibanaVersionCondition == "^8.8.0" { | ||
| return true | ||
| } | ||
| | ||
| // get all versions e.g 8.8.0, 8.8.1 from "^8.8.0 || ^8.8.1" and check if any of them is less than 8.8.0 | ||
| pattern := `(\d+\.\d+\.\d+)` | ||
| semver8_8_0 := semver.MustParse("8.8.0") | ||
| regex := regexp.MustCompile(pattern) | ||
| matches := regex.FindAllString(kibanaVersionCondition, -1) | ||
| | ||
| for _, match := range matches { | ||
| matchVersion, err := semver.NewVersion(match) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| | ||
| if matchVersion.LessThan(semver8_8_0) { | ||
| return false | ||
| } | ||
| } | ||
hop-dev marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| return true | ||
| } | ||
115 changes: 115 additions & 0 deletions 115 code/go/internal/validator/semantic/validate_minimum_kibana_version_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
| | ||
| package semantic | ||
| | ||
| import ( | ||
| "errors" | ||
| "testing" | ||
| | ||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
| | ||
| func TestValidateKibanaVersionGreaterThan(t *testing.T) { | ||
| var tests = []struct { | ||
| version string | ||
| expectedVal bool | ||
| }{ | ||
| { | ||
| "^8.8.0", | ||
| true, | ||
| }, | ||
| { | ||
| "^10.11.12", | ||
| true, | ||
| }, | ||
| { | ||
| "8.8.0", | ||
| true, | ||
| }, | ||
| { | ||
| "^8.8.0 || ^9.9.0", | ||
| true, | ||
| }, | ||
| { | ||
| "^8.8.0 || ^9.9.0 || ^10.11.12", | ||
| true, | ||
| }, | ||
| { | ||
| "^7.7.0", | ||
| false, | ||
| }, | ||
| { | ||
| "^7.7.0 || ^8.8.0", | ||
| false, | ||
| }, | ||
| { | ||
| "^7.7.0 || ^10.11.12", | ||
| false, | ||
| }, | ||
| { | ||
| "", | ||
| false, | ||
| }, | ||
| } | ||
| for _, test := range tests { | ||
| t.Run(test.version, func(t *testing.T) { | ||
| assert.Equal(t, kibanaVersionConditionIsGreaterThanOrEqualTo8_8_0(test.version), test.expectedVal) | ||
| }) | ||
| } | ||
| } | ||
| func TestValidateMinimumKibanaVersion(t *testing.T) { | ||
| | ||
| kbnVersionError := errors.New("Warning: conditions.kibana.version must be ^8.8.0 or greater for non experimental input packages (version > 1.0.0)") | ||
| var tests = []struct { | ||
| packageType string | ||
| packageVersion semver.Version | ||
| kibanaVersionCondition string | ||
| expectedErr error | ||
| }{ | ||
| { | ||
| "integration", | ||
| *semver.MustParse("1.0.0"), | ||
| "^7.14.0", | ||
| nil, | ||
| }, | ||
| { | ||
| "input", | ||
| *semver.MustParse("0.1.0"), | ||
| "^7.14.0", | ||
| nil, | ||
| }, | ||
| { | ||
| "input", | ||
| *semver.MustParse("1.0.0"), | ||
| "^7.14.0", | ||
| kbnVersionError, | ||
| }, | ||
| { | ||
| "input", | ||
| *semver.MustParse("1.0.0"), | ||
| "^8.8.0 || ^7.14.0", | ||
| kbnVersionError, | ||
| }, | ||
| { | ||
| "input", | ||
| *semver.MustParse("1.0.0"), | ||
| "^8.8.0", | ||
| nil, | ||
| }, | ||
| } | ||
| | ||
| for _, test := range tests { | ||
| t.Run(test.packageType+"--"+test.packageVersion.String()+"--"+test.kibanaVersionCondition, func(t *testing.T) { | ||
| res := validateMinimumKibanaVersion(test.packageType, test.packageVersion, test.kibanaVersionCondition) | ||
| | ||
| if test.expectedErr == nil { | ||
| assert.Nil(t, res) | ||
| } else { | ||
| assert.Equal(t, test.expectedErr.Error(), res.Error()) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to handle:
and
here? It seems the lib treats them differently, all packages use
kibana.versionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually looks like an issue with this
Valueshelper. The spec allows bothkibana.version, orversionas an attribute insidekibana.It should probably use ucfg to parse these files instead of plain yaml. See https://github.com/elastic/go-ucfg#dot-notations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a go at this 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both ways of defining Kibana version condition are used in the integrations repository. For instance:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have put a temporary workaround in this PR (9840df4)and have a draft PR for using ucfg https://github.com/elastic/package-spec/pull/487/files