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

Disallow dotted fields #591

Merged
merged 5 commits into from
Sep 12, 2023
Merged

Disallow dotted fields #591

merged 5 commits into from
Sep 12, 2023

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Sep 12, 2023

What does this PR do?

This PR disallows to use fields with dots. For instance:

conditions:
  kibana.version: ^8.8.0

Those files should be updated to:

conditions:
  kibana:
    version: ^8.8.0

Why is it important?

Allowing dotted fields leads to ambiguous specifications.

Checklist

Related issues

@mrodm mrodm self-assigned this Sep 12, 2023
@mrodm mrodm marked this pull request as ready for review September 12, 2023 08:46
@mrodm mrodm requested a review from a team as a code owner September 12, 2023 08:46
jsoriano
jsoriano previously approved these changes Sep 12, 2023
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added a couple of nitpicks.

@@ -72,24 +73,26 @@ func (s *FileSchema) Validate(fsys fs.FS, filePath string) ve.ValidationErrors {
return nil // item content is valid according to the loaded schema
}

func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType) ([]byte, error) {
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion *semver.Version) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass by pointer here, right?

Suggested change
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion *semver.Version) ([]byte, error) {
func loadItemSchema(fsys fs.FS, path string, contentType *spectypes.ContentType, specVersion semver.Version) ([]byte, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it can be passed by value. I'll change it

}
if contentType != nil && contentType.MediaType == "application/x-yaml" {
return convertYAMLToJSON(data)
return convertYAMLToJSON(data, specVersion.LessThan(semver.MustParse("3.0.0")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Consider extracting the parsed version to a constant.

@elasticmachine
Copy link

💚 Build Succeeded

History

cc @mrodm

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrodm mrodm merged commit 6bbaece into elastic:main Sep 12, 2023
@mrodm mrodm deleted the disallow_dotted_fields branch September 12, 2023 14:35
@andrewkroh
Copy link
Member

Awesome! 🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal] Disallow dotted YAML key names
4 participants