Added option addcsvdata <FieldName> <String> to gam print cros

This commit is contained in:
Ross Scroggs
2024-03-05 16:14:18 -08:00
parent 7c8a87673a
commit 63d7b5568b
8 changed files with 58 additions and 14 deletions

View File

@ -551,6 +551,7 @@ gam print cros [todrive <ToDriveAttribute>*]
[start <Date>] [end <Date>] [listlimit <Number>]
[reverselists <CrOSListFieldNameList>]
[timerangeorder ascending|descending] [showdvrsfp]
(addcsvdata <FieldName> <String>)*
[sortheaders]
[formatjson [quotechar <Character>]]
```
@ -593,6 +594,9 @@ otherwise, the remaining field names will appear in the order specified.
- `timerangeorder descending` - Change the `activetimeranges` order from ascending (oldest to newest) to descending (newest to oldest); this makes it easy to get the `N` most recent values with `timeranges listlimit N timerangeorder descending`.
- `showdvrsfp` - Display a field `diskVolumeReports.volumeInfo.storageFreePercentage` which is calculated as: `(diskVolumeReports.volumeInfo.storageFree/diskVolumeReports.volumeInfo.storageTotal)*100`
Add additional columns of data from the command line to the output
* `addcsvdata <FieldName> <String>`
By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format:
- `formatjson` - Display the fields in JSON format.
@ -615,6 +619,7 @@ gam <CrOSTypeEntity> print cros [todrive <ToDriveAttribute>*]
[start <Date>] [end <Date>] [listlimit <Number>]
[reverselists <CrOSListFieldNameList>]
[timerangeorder ascending|descending] [showdvrsfp]
(addcsvdata <FieldName> <String>)*
[sortheaders]
[formatjson [quotechar <Character>]]
@ -643,6 +648,9 @@ otherwise, the remaining field names will appear in the order specified.
- `timerangeorder descending` - Change the `activetimeranges` order from ascending (oldest to newest) to descending (newest to oldest); this makes it easy to get the `N` most recent values with `timeranges listlimit N timerangeorder descending`.
- `showdvrsfp` - Display a field `diskVolumeReports.volumeInfo.storageFreePercentage` which is calculated as: `(diskVolumeReports.volumeInfo.storageFree/diskVolumeReports.volumeInfo.storageTotal)*100`
Add additional columns of data from the command line to the output
* `addcsvdata <FieldName> <String>`
By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format:
- `formatjson` - Display the fields in JSON format.

View File

@ -10,6 +10,12 @@ Add the `-s` option to the end of the above commands to suppress creating the `g
See [Downloads](https://github.com/taers232c/GAMADV-XTD3/wiki/Downloads) for Windows or other options, including manual installation
### 6.71.11
Added option `addcsvdata <FieldName> <String>` to `gam print cros` that adds
additional columns of data to the CSV file output. Typically, you would read CSV file of device IDs/serial numbers
to generate a CSV file of results and copy data from the input CSV to the outout CSV.
### 6.71.10
Reverted change made in 6.71.09 to `gam <UserTypeEntity> print filelist` when `showmimetype` and `filepath|fullpath`

View File

@ -334,7 +334,7 @@ writes the credentials into the file oauth2.txt.
admin@server:/Users/admin/bin/gamadv-xtd3$ rm -f /Users/admin/GAMConfig/oauth2.txt
admin@server:/Users/admin/bin/gamadv-xtd3$ ./gam version
WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found
GAMADV-XTD3 6.71.10 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.71.11 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -1006,7 +1006,7 @@ writes the credentials into the file oauth2.txt.
C:\GAMADV-XTD3>del C:\GAMConfig\oauth2.txt
C:\GAMADV-XTD3>gam version
WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found
GAMADV-XTD3 6.71.10 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.71.11 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
Windows-10-10.0.17134 AMD64

View File

@ -3,7 +3,7 @@
Print the current version of Gam with details
```
gam version
GAMADV-XTD3 6.71.10 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.71.11 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -15,7 +15,7 @@ Time: 2023-06-02T21:10:00-07:00
Print the current version of Gam with details and time offset information
```
gam version timeoffset
GAMADV-XTD3 6.71.10 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.71.11 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -27,7 +27,7 @@ Your system time differs from www.googleapis.com by less than 1 second
Print the current version of Gam with extended details and SSL information
```
gam version extended
GAMADV-XTD3 6.71.10 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.71.11 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -64,7 +64,7 @@ MacOS High Sierra 10.13.6 x86_64
Path: /Users/Admin/bin/gamadv-xtd3
Version Check:
Current: 5.35.08
Latest: 6.71.10
Latest: 6.71.11
echo $?
1
```
@ -72,7 +72,7 @@ echo $?
Print the current version number without details
```
gam version simple
6.71.10
6.71.11
```
In Linux/MacOS you can do:
```
@ -82,7 +82,7 @@ echo $VER
Print the current version of Gam and address of this Wiki
```
gam help
GAM 6.71.10 - https://github.com/taers232c/GAMADV-XTD3
GAM 6.71.11 - https://github.com/taers232c/GAMADV-XTD3
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64

View File

@ -2309,6 +2309,7 @@ gam print cros [todrive <ToDriveAttribute>*]
[start <Date>] [end <Date>] [listlimit <Number>]
[reverselists <CrOSListFieldNameList>]
[timerangeorder ascending|descending] [showdvrsfp]
(addcsvdata <FieldName> <String>)*
[sortheaders]
[formatjson [quotechar <Character>]]
[showitemcountonly]
@ -2333,6 +2334,7 @@ gam <CrOSTypeEntity> print cros [todrive <ToDriveAttribute>*]
[start <Date>] [end <Date>] [listlimit <Number>]
[reverselists <CrOSListFieldNameList>]
[timerangeorder ascending|descending] [showdvrsfp]
(addcsvdata <FieldName> <String>)*
[sortheaders]
[formatjson [quotechar <Character>]]
[showitemcountonly]

View File

@ -2,6 +2,12 @@
Merged GAM-Team version
6.71.11
Added option `addcsvdata <FieldName> <String>` to `gam print cros` that adds
additional columns of data to the CSV file output. Typically, you would read CSV file of device IDs/serial numbers
to generate a CSV file of results and copy data from the input CSV to the outout CSV.
6.71.10
Reverted change made in 6.71.09 to `gam <UserTypeEntity> print filelist` when `showmimetype` and `filepath|fullpath`

View File

@ -23649,6 +23649,7 @@ CROS_INDEXED_TITLES = ['activeTimeRanges', 'recentUsers', 'deviceFiles',
# [start <Date>] [end <Date>] [listlimit <Number>]
# [reverselists <CrOSListFieldNameList>]
# [timerangeorder ascending|descending] [showdvrsfp]
# (addcsvdata <FieldName> <String>)*
# [sortheaders]
# [formatjson [quotechar <Character>]]
# [showitemcountonly]
@ -23664,6 +23665,8 @@ def doPrintCrOSDevices(entityList=None):
cros[field].reverse()
if 'orgUnitId' in cros:
cros['orgUnitId'] = f"id:{cros['orgUnitId']}"
if addCSVData:
cros.update(addCSVData)
if FJQC.formatJSON:
if (not csvPF.rowFilter and not csvPF.rowDropFilter) or csvPF.CheckRowTitles(flattenJSON(cros, listLimit=listLimit, timeObjects=CROS_TIME_OBJECTS)):
csvPF.WriteRowNoFilter({'deviceId': cros['deviceId'],
@ -23703,6 +23706,8 @@ def doPrintCrOSDevices(entityList=None):
row[attrib] = cros[attrib]
else:
row[attrib] = formatLocalTime(cros[attrib])
if addCSVData:
row.update(addCSVData)
if noLists or (not activeTimeRanges and not recentUsers and not deviceFiles and
not cpuStatusReports and not diskVolumeReports and not lastKnownNetworks and not screenshotFiles and not systemRamFreeReports):
csvPF.WriteRowTitles(row)
@ -23787,6 +23792,7 @@ def doPrintCrOSDevices(entityList=None):
allFields = noLists = oneRow = showDVRstorageFreePercentage = sortHeaders = False
activeTimeRangesOrder = 'ASCENDING'
showItemCountOnly = False
addCSVData = {}
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if myarg == 'todrive':
@ -23858,6 +23864,9 @@ def doPrintCrOSDevices(entityList=None):
showDVRstorageFreePercentage = True
elif myarg == 'showitemcountonly':
showItemCountOnly = True
elif csvPF and myarg == 'addcsvdata':
k = getString(Cmd.OB_STRING)
addCSVData[k] = getString(Cmd.OB_STRING, minLen=0)
else:
FJQC.GetFormatJSONQuoteChar(myarg, False)
if selectedLists:
@ -62766,16 +62775,18 @@ SHOW_NO_PERMISSIONS_DRIVES_CHOICE_MAP = {
# [matchname <RegularExpression>] [orgunit|org|ou <OrgUnitPath>]
# [user|group <EmailAddress> [checkgroups]] (role|roles <SharedDriveACLRoleList>)*
# <PermissionMatch>* [<PermissionMatchAction>] [pmselect]
# [oneitemperrow] [<DrivePermissionsFieldName>*|(fields <DrivePermissionsFieldNameList>)]
# [oneitemperrow] [maxitems <Integer>]
# [shownopermissionsdrives false|true|only]
# [<DrivePermissionsFieldName>*|(fields <DrivePermissionsFieldNameList>)]
# [formatjson [quotechar <Character>]]
# gam [<UserTypeEntity>] show shareddriveacls
# [adminaccess|asadmin] [shareddriveadminquery|query <QuerySharedDrive>]
# [matchname <RegularExpression>] [orgunit|org|ou <OrgUnitPath>]
# [user|group <EmailAddress> [checkgroups]] (role|roles <SharedDriveACLRoleList>)*
# <PermissionMatch>* [<PermissionMatchAction>] [pmselect]
# [oneitemperrow] [<DrivePermissionsFieldName>*|(fields <DrivePermissionsFieldNameList>)]
# [oneitemperrow] [maxitems <Integer>]
# [shownopermissionsdrives false|true|only]
# [<DrivePermissionsFieldName>*|(fields <DrivePermissionsFieldNameList>)]
# [formatjsn]
def printShowSharedDriveACLs(users, useDomainAdminAccess=False):
def _printPermissionRow(baserow, permission):
@ -62797,6 +62808,7 @@ def printShowSharedDriveACLs(users, useDomainAdminAccess=False):
fieldsList = []
cd = emailAddress = orgUnitId = query = matchPattern = permtype = None
PM = PermissionMatch()
maxItems = 0
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if csvPF and myarg == 'todrive':
@ -62823,6 +62835,8 @@ def printShowSharedDriveACLs(users, useDomainAdminAccess=False):
checkGroups = True
elif myarg == 'oneitemperrow':
oneItemPerRow = True
elif myarg == 'maxitems':
maxItems = getInteger(minVal=0)
elif getDriveFilePermissionsFields(myarg, fieldsList):
pass
elif myarg in ADMIN_ACCESS_OPTIONS:
@ -62920,10 +62934,11 @@ def printShowSharedDriveACLs(users, useDomainAdminAccess=False):
useDomainAdminAccess=useDomainAdminAccess,
fileId=shareddrive['id'], fields=fields, supportsAllDrives=True)
if not permissions:
if showNoPermissionsDrives == 0:
if showNoPermissionsDrives == 0: # no permissions and showNoPermissionDrives False - ignore
continue
matchFeed.append(shareddrive)
elif showNoPermissionsDrives < 0:
matchFeed.append(shareddrive) # no permissions and showNoPermissionDrives Only/True - keep
continue
if showNoPermissionsDrives < 0: # permissions and showNoPermissionDrives Only/True - ignore
continue
if pmselect:
if not PM.CheckPermissionMatches(permissions):
@ -62941,6 +62956,9 @@ def printShowSharedDriveACLs(users, useDomainAdminAccess=False):
elif checkGroups and permission['emailAddress'] in groupsSet:
shareddrive['permissions'].append(permission)
if shareddrive['permissions']:
numItems = len(shareddrive['permissions'])
if numItems > maxItems > 0:
shareddrive['permissions'] = shareddrive['permissions'][0:maxItems]
matchFeed.append(shareddrive)
except (GAPI.fileNotFound, GAPI.forbidden, GAPI.internalError,
GAPI.insufficientAdministratorPrivileges, GAPI.insufficientFilePermissions,

View File

@ -67,6 +67,7 @@ DOMAIN_CANNOT_USE_APIS = 'domainCannotUseApis'
DOMAIN_NOT_FOUND = 'domainNotFound'
DOMAIN_NOT_VERIFIED_SECONDARY = 'domainNotVerifiedSecondary'
DOMAIN_POLICY = 'domainPolicy'
DOWNLOAD_QUOTA_EXCEEDED = 'downloadQuotaExceeded'
DUPLICATE = 'duplicate'
EVENT_DURATION_EXCEEDS_LIMIT = 'eventDurationExceedsLimit'
FAILED_PRECONDITION = 'failedPrecondition'
@ -206,7 +207,7 @@ DRIVE_ACCESS_THROW_REASONS = DRIVE_USER_THROW_REASONS+[FILE_NOT_FOUND, FORBIDDEN
DRIVE_COPY_THROW_REASONS = DRIVE_ACCESS_THROW_REASONS+[CANNOT_COPY_FILE, BAD_REQUEST, RESPONSE_PREPARATION_FAILURE, TEAMDRIVES_SHARING_RESTRICTION_NOT_ALLOWED,
FIELD_NOT_WRITABLE, RATE_LIMIT_EXCEEDED, USER_RATE_LIMIT_EXCEEDED,
STORAGE_QUOTA_EXCEEDED, TEAMDRIVE_FILE_LIMIT_EXCEEDED, TEAMDRIVE_HIERARCHY_TOO_DEEP]
DRIVE_GET_THROW_REASONS = DRIVE_USER_THROW_REASONS+[FILE_NOT_FOUND]
DRIVE_GET_THROW_REASONS = DRIVE_USER_THROW_REASONS+[FILE_NOT_FOUND, DOWNLOAD_QUOTA_EXCEEDED]
DRIVE3_CREATE_ACL_THROW_REASONS = [BAD_REQUEST, INVALID, INVALID_SHARING_REQUEST, OWNERSHIP_CHANGE_ACROSS_DOMAIN_NOT_PERMITTED, CANNOT_SET_EXPIRATION,
NOT_FOUND, TEAMDRIVE_DOMAIN_USERS_ONLY_RESTRICTION, TEAMDRIVE_TEAM_MEMBERS_ONLY_RESTRICTION,
TARGET_USER_ROLE_LIMITED_BY_LICENSE_RESTRICTION, INSUFFICIENT_ADMINISTRATOR_PRIVILEGES, SHARING_RATE_LIMIT_EXCEEDED,
@ -435,6 +436,8 @@ class domainNotVerifiedSecondary(Exception):
pass
class domainPolicy(Exception):
pass
class downloadQuotaExceeded(Exception):
pass
class duplicate(Exception):
pass
class eventDurationExceedsLimit(Exception):
@ -696,6 +699,7 @@ REASON_EXCEPTION_MAP = {
DOMAIN_NOT_FOUND: domainNotFound,
DOMAIN_NOT_VERIFIED_SECONDARY: domainNotVerifiedSecondary,
DOMAIN_POLICY: domainPolicy,
DOWNLOAD_QUOTA_EXCEEDED: downloadQuotaExceeded,
DUPLICATE: duplicate,
EVENT_DURATION_EXCEEDS_LIMIT: eventDurationExceedsLimit,
FAILED_PRECONDITION: failedPrecondition,