Support json (and pretty) output - #1610
Conversation
The intention here is to be more API friendly and do some exploration of this capabilities
- Introduced `json.sh` for JSON output support. - Updated `common.sh` to source the new JSON library.
|
Rebase to use the new 'lib' directory |
|
Works for me. Good to see the new LIBDIR. Perhaps it's better to use "${bastille_sharedir}/lib/json.sh" so it's dynamic. |
You're right. I'll also created another PR #1614 in order to update the other scripts in the common.sh file. I'll wait @cedwards and @bmac2 comments before continuing adding other commands support. Mainly to be sure the design is good enough so I can start adding more code. |
|
I'd like to start with merging this as a first. I've got an idea about moving supported parameters or config into a lib/config file so we don't have to pollute the config.sh subcommand. But let's wait until bmac and cedwards ok the format here. |
This is a draft and only
config getis supported as a test case scenario. Opening this draft to discuss the design decisions and get feedback. The intention here is to be more API friendly and do some exploration of this capabilities.Many FreeBSD base tools support machine-readable output via libxo's --libxo=json (jls, netstat, ps, arp, mount, vmstat, …). Bastille today has only one JSON output at the moment:
bastille list -j, which is hand-rolled inlist.shwithawkand asedpretty-printer.Every libxo JSON document is a single top-level object shaped like:
{ ["__version": "N",] "<domain>": { "<singular-element>": [ {record}, {record}, … ] } }The idea here for Bastille is to stay as close as possible to that format. Nevertheless, I find adding a "type" because some commands can be executed at different target-types. Like
bootstrapsubcommand can do releases or templates. This can be discussed if really needed or not depending if we are going to support a json output forbootstrap.So the Bastille output is something like:
{"bastille":{"type":"<entity>","<entity>":[ {record}, ... ]}}How to test this
For json output:
# bastille -j config TARGET get securelevelFor json (pretty) output:
# bastille -p config TARGET get securelevelALLis supported as target.Both print all jails with its jid, name, and securelevel or whatever config you are testing.
If the jail is not running, the
jidwill simply saynull