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

Example BGP custom data validator not working #113

Open
Glynn608 opened this issue Sep 16, 2021 · 5 comments
Open

Example BGP custom data validator not working #113

Glynn608 opened this issue Sep 16, 2021 · 5 comments

Comments

@Glynn608
Copy link

Environment

  • Python version:
$ python3 --version
Python 3.9.6
  • schema-enforcer version:
jsonschema==3.2.0
schema-enforcer==1.1.0

Expected Behavior

The schema should load and validate data against the validate function with exits of self.add_validation_error() and self.add_validation_pass()

Observed Behavior

The schema appears to be registering but doesn't action anything in the script.

Steps to Reproduce

  1. Install the dependancies
  2. Follow this guide - https://blog.networktocode.com/post/schema-enforcer-custom-validators/
  3. https://github.com/networktocode/schema-enforcer/blob/develop/docs/custom_validators.md

Side note, the example4 folder doesn't seems to exist like in the blog post, does anyone have a working example of custom validators using https://github.com/networktocode/schema-enforcer/blob/develop/docs/custom_validators.md#basevalidation?

Maybe I'm missing something in the .toml file? Any examples?

@chipn
Copy link
Contributor

chipn commented Sep 16, 2021

Thanks for submitting this issue, @Glynn608.

We may have introduced a breaking change which impacted the CheckARIN example. I'm working through that now, but in that case, the validator fails completely. It sounds like you may be seeing something different.

Can you confirm which example you tried to use? Was it the CheckARIN example or your own code?

@Glynn608
Copy link
Author

Initially it was my own code. It didn't fail it, just seemed to not do anything. No errors, no logs.

I moved onto the CheckARIN example as I assumed I was missing something but also had no luck with that either 🙂

Can you tag me in the PR with working example when you get round to it please.

@chipn
Copy link
Contributor

chipn commented Sep 16, 2021

I've updated the example from the blog and submitted PR #114. Give that a try and let me know if you have any issues.

I'll update the documentation and tests separately, but that PR will give you a starting point.

Also, the default behavior of schema-enforcer is to only output errors. You can use the --show-pass flag to see the files that pass.

@Glynn608
Copy link
Author

This was a great help I have it functioning now. My config wasn't finding the validators folder :(

Follow up question, is it intended that the validators folder lives in the schema/ main dir or the dir where the CLI command is executed? Currently the default is the dir where the command is executed.

gwindebank@gwindeban35-mac [chipn/validator-example]example4
$ tree
.
├── host_vars
│   ├── az_rtr_01
│   │   └── peers.yml
│   └── az_rtr_02
│       └── peers.yml
├── schema
│   ├── definitions
│   ├── schemas
│   ├── tests
│   └── validators
└── validators
    ├── __pycache__
    │   └── check_arin.cpython-39.pyc
    └── check_arin.py

It might be nice to add an example .toml file and other folders to example 4 and update the defaults for validators in the docs https://github.com/networktocode/schema-enforcer/blob/main/docs/configuration.md#default-configuration-settings

@chipn
Copy link
Contributor

chipn commented Sep 17, 2021

The default is validators in the current directory which is why the default doc doesn't include the language about being nested in main_directory. You can configure it to be nested by adding this to your pyproject.toml file:

[tool.schema_enforcer]
validator_directory = "schema/validators"

I'm open to switching the default to being nested in the main_directory along with the others though.

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

No branches or pull requests

2 participants