netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Eric Garver <eric@garver.life>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	netfilter-devel@vger.kernel.org, Eric Leblond <eric@regit.org>,
	Florian Westphal <fw@strlen.de>
Subject: Re: [nft PATCH RFC 0/2] JSON schema for nftables.py
Date: Fri, 26 Apr 2019 09:45:44 +0200	[thread overview]
Message-ID: <20190426074544.GT31599@orbyte.nwl.cc> (raw)
In-Reply-To: <20190425163546.zpm7tfhpolyfmtoe@egarver.localdomain>

Hi Eric,

On Thu, Apr 25, 2019 at 12:35:46PM -0400, Eric Garver wrote:
> On Thu, Apr 25, 2019 at 04:05:00PM +0200, Phil Sutter wrote:
[...]
> > Keeping the schema in a "pure" JSON file makes things a bit complex: It
> > has to be shipped as data file and loaded by the validator using
> > json.load(). OTOH the content may be fed into json_verify and my editor
> > provides nicer syntax highlighting. An alternative would be to name it
> > schema.py, prefix the content with 'nftschema = ' and simply import it
> > into nftables.py. I don't think inlining the content is a good option
> > simply due to how large the file will get once definitions for all
> > statements and expressions are in there.
> 
> I very much prefer the external JSON file. Other projects can then use
> it to validate the JSON they generate without going through libnftables.

Valid point, although the file will be hidden in
/lib64/python2.7/site-packages/nftables/schema.json after installation.

> > Introducing that SchemaValidator class is not really required, either.
> > Though squeezing everything into json_validate() method felt clumsy.
> > Also I wanted to avoid the explicit schema loading mentioned above upon
> > each call to json_validate(), so having an instance of a validator class
> > seemed like how one is supposed to do things in an object-oriented
> > language.
> > 
> > Note that SchemaValidator imports jsonschema upon instantiation. This
> > may be a bad idea to begin with, but the intention is to not introduce a
> > hard dependency on jsonschema in nftables.py. Same argument holds for
> > conditional import of traceback module in nft-test.py, although
> > validator errors are practically useless without it.
> 
> I agree with the optional jsonschema dependency.
> 
> traceback is part of the python standard library. No reason to make it a
> conditional import unless you're worried about the cost of importing it.

Thanks for pointing this out! For the testsuite, unconditionally
importing traceback should be perfectly fine.

Thanks, Phil

      reply	other threads:[~2019-04-26  7:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 14:05 [nft PATCH RFC 0/2] JSON schema for nftables.py Phil Sutter
2019-04-25 14:05 ` [nft PATCH RFC 1/2] py: Implement JSON validation in nftables module Phil Sutter
2019-04-25 14:05 ` [nft PATCH RFC 2/2] tests/py: Support JSON validation Phil Sutter
2019-04-25 16:35 ` [nft PATCH RFC 0/2] JSON schema for nftables.py Eric Garver
2019-04-26  7:45   ` Phil Sutter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190426074544.GT31599@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=eric@garver.life \
    --cc=eric@regit.org \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).