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

Check allowed values for fields #771

Merged
merged 10 commits into from
Jun 9, 2022
Merged

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Mar 31, 2022

Fields can include a list of allowed values. Check that the values of
these fields are between the allowed ones.

For arrays, validation is now done for all fields, as we not only need
to validate their type but also their values.

Part of #615.

@jsoriano jsoriano self-assigned this Mar 31, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 31, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-08T16:01:56.292+0000

  • Duration: 35 min 31 sec

Test stats 🧪

Test Results
Failed 0
Passed 723
Skipped 0
Total 723

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@jsoriano jsoriano requested a review from a team March 31, 2022 18:11
internal/fields/validate.go Outdated Show resolved Hide resolved
@jsoriano jsoriano requested a review from mtojek April 6, 2022 10:30

// ensureAllowedValues validates that the document's field value
// is one of the allowed values.
func ensureAllowedValues(key, value string, allowedValues AllowedValues) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: in theory, you don't need to pass key here as it's just used to render the error message :)

Copy link
Member Author

@jsoriano jsoriano Apr 6, 2022

Choose a reason for hiding this comment

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

Umm, but error message is rendered here, key is used in this function for that.

I would be fine with refactoring this error generation, but in a different PR, making the other ensure methods consistent with this.

@jsoriano
Copy link
Member Author

jsoriano commented Apr 6, 2022

Blocked till elastic/integrations#3016 is solved.

@elasticmachine
Copy link
Collaborator

elasticmachine commented May 10, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (30/30) 💚
Files 64.22% (70/109) 👍
Classes 58.553% (89/152) 👍 0.274
Methods 46.523% (281/604) 👍 0.267
Lines 31.425% (2552/8121) 👍 0.146
Conditionals 100.0% (0/0) 💚

@jsoriano jsoriano mentioned this pull request May 30, 2022
@jsoriano
Copy link
Member Author

I have moved the changes to check values in arrays to #835, so we can start benefiting of this in other cases as with IP validation (elastic/integrations#3408).

@jsoriano jsoriano marked this pull request as ready for review June 8, 2022 17:04
@jsoriano jsoriano requested a review from mtojek June 8, 2022 17:04
@jsoriano
Copy link
Member Author

jsoriano commented Jun 8, 2022

Opening this for final review as blockers in elastic/integrations#3016 are close to be completed.

@mtojek could you please take another look?

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Ship it!

@jsoriano jsoriano merged commit 79c22bc into elastic:main Jun 9, 2022
@jsoriano jsoriano deleted the check-allowed-values branch June 9, 2022 08:51
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.

3 participants