taers232c / GAMADV-XTD3

Command line tool to manage Google Workspace
691 stars 86 forks source link

[BUG] csv_output_header_force is doing partial matches instead of exact matches #343

Closed jay-eleven closed 1 year ago

jay-eleven commented 1 year ago

I was curious as to how csv_output_header_force worked because I could find very little information on it and no examples.

According to GAM documentation, csv_output_header_force:

is a list of \<Strings> to be the exact list of headers to be included in the CSV file written by a gam print command.

Let's try it with a simple command to get a sense of what it does:

jay@cloudshell:~$ gam print domains
domainName,parentDomainName,creationTime,type,verified
s.com,,2011-10-13T22:02:57+00:00,primary,True
c.com,s.com,2022-12-07T15:12:54+00:00,alias,True
g.com,,2013-01-13T00:04:10+00:00,secondary,True

Adding csv_output_header_force should only output the headers that I specify, so:

jay@cloudshell:~$ gam config csv_output_header_force "domainName" print domains
domainName
s.com
c.com
g.com

or even

jay@cloudshell:~$ gam config csv_output_header_force "h1,h2,h3" print domains
h1,h2,h3
,,
,,
,,

work perfectly, but:

jay@cloudshell:~$ gam config csv_output_header_force "a,b,c" print domains
a,b,c,creationTime
,,,2011-10-13T22:02:57+00:00
,,,2022-12-07T15:12:54+00:00
,,,2013-01-13T00:04:10+00:00

Hmmmm... why is it showing creationTime? Let's add a new header d and this will become clear:

jay@cloudshell:~$ gam config csv_output_header_force "a,b,c,d" print domains
a,b,c,d,domainName,creationTime
,,,,s.com,2011-10-13T22:02:57+00:00
,,,,c.com,2022-12-07T15:12:54+00:00
,,,,g.com,2013-01-13T00:04:10+00:00

Hmmm... domainName is shown now.

Again, let's add a new header v:

jay@cloudshell:~$ gam config csv_output_header_force "a,b,c,d,v" print domains
a,b,c,d,v,domainName,verified,creationTime
,,,,,s.com,True,2011-10-13T22:02:57+00:00
,,,,,c.com,True,2022-12-07T15:12:54+00:00
,,,,,g.com,True,2013-01-13T00:04:10+00:00

And now verified is also shown.

Looks like it's doing some kind of partial match instead of an exact match.

This is not an issue for a gam print domains command, but it might be for a command that has many headers. For example:

jay@cloudshell:~$ gam config csv_output_header_force "s" print users allfields
Getting all Users, may take some time on a large Google Workspace Account...
Got x Users: a@s.com - w@s.com
s,sshPublicKeys,sshPublicKeys.0.expirationTimeUsec,sshPublicKeys.0.fingerprint,sshPublicKeys.0.key,suspended,suspensionReason
,,,,,False,
,,,,,False,
,,,,,False,
,,,,,False,
,,,,,False,

So, the moral of the story might be to use the full header name. 😀

But even if you add the exact header name you want, you may get more than you expected because of the partial matching behaviour on gam commands that output a lot of headers:

jay@cloudshell:~$ gam config csv_output_header_force "whoCanAdd" print groups allfields
whoCanAdd,whoCanAddReferences
ALL_OWNERS_CAN_ADD,NONE
ALL_MANAGERS_CAN_ADD,NONE
ALL_OWNERS_CAN_ADD,NONE

whoCanAdd partially matches whoCanAddReferences... 😁

taers232c commented 1 year ago

I finally figured this out, will fix later today.

Ross

taers232c commented 1 year ago

Fixed 6.57.11

Thanks for various Wiki cleanups.

jay-eleven commented 1 year ago

Fixed! Thanks Ross!!