Re: [nft PATCH v2 1/2] py: Implement JSON validation in nftables module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 17, 2019 at 10:17:57PM +0200, Phil Sutter wrote:
> Using jsonschema it is possible to validate any JSON input to make sure
> it formally conforms with libnftables JSON API requirements.
> 
> Implement a simple validator class for use within a new Nftables class
> method 'json_validate' and ship a minimal schema definition along with
> the package.
> 
> Signed-off-by: Phil Sutter <phil@xxxxxx>
> ---
>  py/Makefile.am |  2 +-
>  py/nftables.py | 30 ++++++++++++++++++++++++++++++
>  py/schema.json | 17 +++++++++++++++++
>  py/setup.py    |  1 +
>  4 files changed, 49 insertions(+), 1 deletion(-)
>  create mode 100644 py/schema.json
> 
[..]
> diff --git a/py/nftables.py b/py/nftables.py
> index 33cd2dfd736d4..db0f502b2951f 100644
> --- a/py/nftables.py
> +++ b/py/nftables.py
> @@ -17,9 +17,24 @@
>  import json
>  from ctypes import *
>  import sys
> +import os
>  
>  NFTABLES_VERSION = "0.1"
>  
> +class SchemaValidator:
> +    """Libnftables JSON validator using jsonschema"""
> +
> +    def __init__(self):
> +        schema_path = os.path.join(os.path.dirname(__file__), "schema.json")
> +        schema_file = file(schema_path)

file() doesn't exist in python3. You should use open().



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux