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

Command line argument for custom validators #202

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jhe-iqbis
Copy link

First of all, thank you for this great tool. It is a crucial part of our build pipeline to maintain code quality and therefore incredibly useful to our project.

As Yamale already features a modular design, able to be extended by custom validators, my pull request aims to allow this using command line arguments.

There are no breaking changes in my pull request and I wrote a test that completes successfully for python 3.6, 3.8 and (with a newer pytest version) 3.10 on my system.

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2022

This pull request introduces 1 alert when merging 09b7479 into d7f9657 - view on LGTM.com

new alerts:

  • 1 for Syntax error

if not os.path.isfile(include):
raise ValueError("Python include file '{}' not found.".format(include))
from importlib.machinery import SourceFileLoader
SourceFileLoader(os.path.basename(include), include).load_module()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this step allows users of the yamale CLI to load arbitrary python code, the README.md warning may need to be broadened.

@mildebrandt
Copy link

Thanks for your contribution! We usually like to have a discussion in an issue first to ensure not too much coding happens in the wrong direction. This seems pretty contained though, so not a problem. Just to keep in mind for the future.

I'll be out for a week, so it'll take a while for me to get to this. Initially, on the surface, it does look good though.

@mechie
Copy link
Contributor

mechie commented Aug 12, 2022

If this is accepted/merged, the new flag should be documented in the README, probably along with a section that links to the example custom validators and a shows how to use it.

@mechie
Copy link
Contributor

mechie commented Aug 12, 2022

Just going to quote from #166 (comment) here, since that issue is the mirror of this one (custom validators inlined in schemas), and the concerns mostly apply:

Some things to think about:

  • What happens when the user mistakenly adds two validators with the same tag? Is that an error or a warning?
  • What happens when the user attempts to override an existing validator?
  • Will this work in conjunction with loading a separate custom validator via code?
  • Keep in mind the other implementation in case we'd like to do that in the future as well. I'd hate to totally rewrite this to fit the other implementation.
  • Tests, tests, tests....someone else will be maintaining your code.

@mildebrandt
Copy link

I appreciate the reminder of the previous concerns. I believe this is a little different since it's not embedding the validators in the schema itself, but it's in a separate python file that is pointed to within the command line options. This makes it far less dangerous as well, and shouldn't require an extra warning in the README.

However, I've only looked at this for 5 minutes, so please let me know if I missed something. :)

@mechie
Copy link
Contributor

mechie commented Aug 12, 2022

Ah yep, same, just did an initial read and the non-technical concerns popped in my head, will need to come back and look deeper. I consume yamale only as a library, so the concern is not personal.

I'm not sure what promises/guarantees the CLI makes (is there an implicit "only the schema flag is dangerous" due to the warning?). From a user POV it's "I give flag A file X, and flag B file Y" so warning about A (schema) but not B (includes) when both can lead to undefined behavior (schema via ast exploits, includes via it being loaded as a python module) seems odd.

@mildebrandt
Copy link

The danger comes from offering Yamale as a service. If that service is accepting a schema/data pair and offering back a result, there are concerns that processing uncontrolled schema would leave the service open to malicious attacks.

When limited to command line, the caller of the yamale executable has full control over the additional validators that are imported via the command line option.

I understand your concern, and I don't mind putting a line in the README saying to "ensure the imported validators come from trusted sources" or something similar.

@mildebrandt
Copy link

I wanted to do a little check in here. Work is really busy at the moment. This hasn't been forgotten, but will take a bit for me to get to....my apologies.

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