-
Notifications
You must be signed in to change notification settings - Fork 87
Support deprecated packages or individual features
#1053
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
Open
teresaromero
wants to merge
9
commits into
elastic:main
Choose a base branch
from
teresaromero:1032-support-deprecated-field
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
78f83c6
add 'deprecation' type to changelog specification
teresaromero b8b4c88
add deprecation field to manifest specifications and remove it in pat…
teresaromero 10e0a01
add test cases to validator test with deprecation features
teresaromero 76bf701
update changelog
teresaromero db73bd9
add semantic validation for integration inputs deprecation
teresaromero 9e72515
add comment to clarify validation logic for deprecated integration in…
teresaromero 79d7a2c
reorder import statements for consistency
teresaromero 3e74508
update link for deprecation support enhancement in changelog
teresaromero 4fa64a2
Merge branch 'main' of github.com:elastic/package-spec into 1032-supp…
teresaromero 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
76 changes: 76 additions & 0 deletions
76
code/go/internal/validator/semantic/validate_integration_inputs_deprecated.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,76 @@ | ||
| // 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 ( | ||
| "io/fs" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
|
|
||
| "github.com/elastic/package-spec/v3/code/go/internal/fspath" | ||
| "github.com/elastic/package-spec/v3/code/go/pkg/specerrors" | ||
| ) | ||
|
|
||
| // ValidateIntegrationInputsDeprecation checks that if all inputs in an integration package are deprecated, | ||
| // then the integration package itself must be marked as deprecated. | ||
| func ValidateIntegrationInputsDeprecation(fsys fspath.FS) specerrors.ValidationErrors { | ||
|
|
||
| type manifest struct { | ||
| Type string `yaml:"type,omitempty"` | ||
| Deprecated *struct { | ||
| Since string `yaml:"since,omitempty"` | ||
| Description string `yaml:"description,omitempty"` | ||
| } `yaml:"deprecated,omitempty"` | ||
| PolicyTemplates []struct { | ||
| Inputs []struct { | ||
| Deprecated *struct { | ||
| Since string `yaml:"since,omitempty"` | ||
| Description string `yaml:"description,omitempty"` | ||
| } `yaml:"deprecated,omitempty"` | ||
| } `yaml:"inputs,omitempty"` | ||
| } `yaml:"policy_templates,omitempty"` | ||
| } | ||
|
|
||
| manifestPath := "manifest.yml" | ||
| data, err := fs.ReadFile(fsys, manifestPath) | ||
| if err != nil { | ||
| return specerrors.ValidationErrors{ | ||
| specerrors.NewStructuredErrorf("file \"%s\" is invalid: %w", fsys.Path(manifestPath), err)} | ||
| } | ||
|
|
||
| var m manifest | ||
| err = yaml.Unmarshal(data, &m) | ||
| if err != nil { | ||
| return specerrors.ValidationErrors{ | ||
| specerrors.NewStructuredErrorf("file \"%s\" is invalid: %w", fsys.Path(manifestPath), err)} | ||
| } | ||
| // skip if not an integration package | ||
| if m.Type != packageTypeIntegration { | ||
| return nil | ||
| } | ||
|
|
||
| // if package is deprecated, skip checks | ||
| if m.Deprecated != nil { | ||
| return nil | ||
| } | ||
|
|
||
| total := 0 | ||
| deprecated := 0 | ||
| for _, pt := range m.PolicyTemplates { | ||
| for _, input := range pt.Inputs { | ||
| total++ | ||
| if input.Deprecated != nil { | ||
| deprecated++ | ||
| } | ||
| } | ||
| } | ||
| if deprecated == total && total > 0 { | ||
| return specerrors.ValidationErrors{ | ||
| specerrors.NewStructuredErrorf("file \"%s\" is invalid: all inputs are deprecated but the integration package is not marked as deprecated", fsys.Path(manifestPath)), | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
137 changes: 137 additions & 0 deletions
137
code/go/internal/validator/semantic/validate_integration_inputs_deprecated_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,137 @@ | ||
| // 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 ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/elastic/package-spec/v3/code/go/internal/fspath" | ||
| ) | ||
|
|
||
| func TestValidateIntegrationInputsDeprecation(t *testing.T) { | ||
|
|
||
| t.Run("integration_deprecated_all_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| deprecated: | ||
| since: '1.0.0' | ||
| description: 'This integration is deprecated.' | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| deprecated: | ||
| since: '0.5.0' | ||
| description: 'This input is deprecated.' | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.Empty(t, errs, "expected no validation errors") | ||
|
|
||
| }) | ||
|
|
||
| t.Run("integration_deprecated_none_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| deprecated: | ||
| since: '1.0.0' | ||
| description: 'This integration is deprecated.' | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.Empty(t, errs, "expected no validation errors") | ||
| }) | ||
|
|
||
| t.Run("integration_deprecated_partial_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| deprecated: | ||
| since: '1.0.0' | ||
| description: 'This integration is deprecated.' | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| deprecated: | ||
| since: '0.5.0' | ||
| description: 'This input is deprecated.' | ||
| - type: tcp | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.Empty(t, errs, "expected no validation errors") | ||
| }) | ||
|
|
||
| t.Run("integration_not_deprecated_all_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| deprecated: | ||
| since: '0.5.0' | ||
| description: 'This input is deprecated.' | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.NotEmpty(t, errs, "expected validation errors") | ||
| require.Len(t, errs, 1) | ||
| assert.ErrorContains(t, errs[0], "all inputs are deprecated but the integration package is not marked as deprecated") | ||
|
|
||
| }) | ||
|
|
||
| t.Run("integration_not_deprecated_none_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.Empty(t, errs, "expected no validation errors") | ||
| }) | ||
|
|
||
| t.Run("integration_not_deprecated_partial_inputs_deprecated", func(t *testing.T) { | ||
| d := t.TempDir() | ||
|
|
||
| err := os.WriteFile(filepath.Join(d, "manifest.yml"), []byte(` | ||
| type: integration | ||
| policy_templates: | ||
| - inputs: | ||
| - type: udp | ||
| deprecated: | ||
| since: '0.5.0' | ||
| description: 'This input is deprecated.' | ||
| - type: tcp | ||
| `), 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| errs := ValidateIntegrationInputsDeprecation(fspath.DirFS(d)) | ||
| require.Empty(t, errs, "expected no validation errors") | ||
| }) | ||
|
|
||
| } |
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.
This semantic rule needs to be added to
package-spec/code/go/internal/validator/spec.go
Line 230 in 0001437
in order to be taken into account for the packages.