Closed daethnir closed 3 weeks ago
grouptree is ignored when formatjson is specified gam info user user@example.com grouptree formatjson | jq . > /tmp/grouptree
groups is allowed when formatjson is specified; it just gives the direct memberships gam info user user@example.com groups formatjson | jq . > /tmp/grouptree
What's your objective?
My objective is to get that great great great grouptree data in a programatic way, and json is very good for making data available to tools, while unformatted text is not as reliable or forward-proof.
Send me a Meet/Zoom invitation to discuss.
What would you want the JSON to look like?
Say this was your group hierarchy for a user:
groups:
foo-team@example.com: Foo Team
bar-team@example.com: Bar Team
misc-ord@example.com: Chicago Misc
misc-us@example.com: US Misc
everyone@example.com: Everyone
role-contractor@example.com: Role Contractor
role-people@example.com: All People
contractors-announce@example.com: Announce list for contractors
then I think this would make sense for the json:
{
"groups": {
"foo-team@example.com": {},
"bar-team@example.com": {},
"misc-ord@example.com": {
"misc-us@example.com": {
"everyone@example.com": {}
}
},
"role-contractor@example.com": {
"role-people@example.com": {},
"contractors-announce@example.com": {}
}
}
}
You don't care about ordering, but you do care about composition. So use dictionaries everywhere. An empty dict as a value means there are no parents of that group. If there is a dict value then it's the parent (potentially multiple layers deep) of the group in question.
The group email address is important, the name could be just discarded.
$ gam select jay info user ross quick grouptree primaryemail User: ross@s.jaylee.us Settings: Group Membership Tree: admins@s.jaylee.us: Admin Group rossgroup@s.jaylee.us: Ross Group testgroup2@s.jaylee.us: Test Group 2 rossgroup@s.jaylee.us: Ross Group testgroup@s.jaylee.us: Test Group rossgroup@s.jaylee.us: Ross Group testgroup2@s.jaylee.us: Test Group 2 rossgroup@s.jaylee.us: Ross Group
Run the output thru jq $ gam select jay info user ross quick grouptree primaryemail formatjson {"groups": [{"email": "admins@s.jaylee.us", "name": "Admin Group", "parents": []}, {"email": "rossgroup@s.jaylee.us", "name": "Ross Group", "parents": []}, {"email": "testgroup2@s.jaylee.us", "name": "Test Group 2", "parents": [{"email": "rossgroup@s.jaylee.us", "name": "Ross Group", "parents": []}]}, {"email": "testgroup@s.jaylee.us", "name": "Test Group", "parents": [{"email": "rossgroup@s.jaylee.us", "name": "Ross Group", "parents": []}, {"email": "testgroup2@s.jaylee.us", "name": "Test Group 2", "parents": [{"email": "rossgroup@s.jaylee.us", "name": "Ross Group", "parents": []}]}]}], "primaryEmail": "ross@s.jaylee.us"}
Yeah, that's a good format, and it includes the metadata some folks might like, and empty parents array is more intuitive than empty dict. I like it.
IIRC there's a "gam show grouptree" that could also use formatjson magic.
6.65.05 - all grouptree commands now have formatjson
Example:
gam info user user@example.com formatjson | jq . > /tmp/nogrouptree
vsgam info user user@example.com grouptree formatjson | jq . > /tmp/grouptree
The latter does not include any group section at all