JSON input / output for CLI utilities

Andrew Walker awalker at ixsystems.com
Mon May 31 01:14:22 UTC 2021


On Fri, May 28, 2021 at 11:15 AM Ralph Boehme <slow at samba.org> wrote:

> Am 27.05.21 um 23:42 schrieb Andrew Walker via samba-technical:
> > I know we've added JSON output to a few of the CLI utils. Over the past
> > year or so I've added this to various utils in FreeNAS (using
> libjansson).
> > Is there an overall strategy for this? I'd be happy to upstream what I
> have.
>
> I guess as what you have worked for FreeNAS/TrueNAS and unless it's
> somehow tailored to specific usecases, it should be good as is. :)
>
> > Also is there an effort to add support for JSON input to them?
>
> Not that I know of, but that sounds like a nice addition for some tools.
> For which tools do you have JSON input support?
>

I'm in the process of adding support for pdbedit, net groupmap, and net
conf. I see one of major advantages of JSON input support for some of these
is we can trivially add support for batch operations. Libjansson is quite
easy to work with for doing json input via json_loads().

Example:
root at debian:/CODE/samba# bin/default/source3/utils/net --json groupmap
batch_json data='{"DEL": [{"nt_name": "acltester"}, {"nt_name":
"scanner"}]}'
{"version": {"major": 1, "minor": 0}, "groupmap": [{"nt_name": "awalker",
"sid": "S-1-5-21-1908376751-3950050175-4123529826-1004", "gid": 1000,
"group_type_int": 2}]}

root at debian:/CODE/samba# bin/default/source3/utils/net --json groupmap
batch_json data='{"ADD": [{"nt_name": "acltester", "gid": 1001},
{"nt_name": "scanner", "gid": 114}]}'
{"version": {"major": 1, "minor": 0}, "groupmap": [{"nt_name": "acltester",
"sid": "S-1-5-21-1908376751-3950050175-4123529826-1009", "gid": 1001,
"group_type_int": 2}, {"nt_name": "scanner", "sid":
"S-1-5-21-1908376751-3950050175-4123529826-1010", "gid": 114,
"group_type_int": 2}, {"nt_name": "awalker", "sid":
"S-1-5-21-1908376751-3950050175-4123529826-1004", "gid": 1000,
"group_type_int": 2}]}

(note above batch command gives net_groupmap_list() output after completion)

So in this case, I can submit `{"ADD": [{<groupmap 3>}, {<groupmap 4>},
{<groupmap 5>}], "MOD": [{<groupmap 2>}], "DEL": [{<groupmap 1>}]}` and
make all the requested changes in a single command.


More information about the samba-technical mailing list