Compare commits

...

55 Commits
v5.03 ... v5.07

Author SHA1 Message Date
ejochman
f301dac442 Add pre-commit config for formatting and linting (#1166)
Adds a pre-commit config for development that runs several fixers, including YAPF with
"google" style and pylint for static analysis.

Use of `requirements-dev.txt` appears to be a common pattern for this
type of work:
https://pypi.org/project/requirements-dev.txt/
2020-04-26 16:51:07 -04:00
Jay Lee
dae5cff728 focal doesn't work 2020-04-25 16:49:12 -04:00
Jay Lee
f605afb647 Merge branch 'master' of https://github.com/jay0lee/GAM 2020-04-24 19:34:06 -04:00
Jay Lee
ed832956ea Ubuntu 20.04 Focal 2020-04-24 19:33:54 -04:00
Jay Lee
402ff9e8d0 GAM 5.07 2020-04-24 14:00:13 -04:00
Jay Lee
2fc51dba17 remove whatsnew.txt from MSI 2020-04-24 12:48:15 -04:00
Jay Lee
fd8358af90 remove whatsnew.txt, keep lastupdatecheck.txt out of linux legacy package 2020-04-24 12:04:54 -04:00
Jay Lee
4cd835577a returnidonly 2020-04-24 11:35:54 -04:00
Jay Lee
bc1c11e650 Merge branch 'master' of https://github.com/jay0lee/GAM 2020-04-24 11:23:17 -04:00
Jay Lee
765f432ef2 make travis drive uploads world readable 2020-04-24 11:22:59 -04:00
Ross Scroggs
4cd92a1372 Document new ouath create form, make consistent with check serviceaccount (#1168) 2020-04-24 10:21:49 -04:00
Jay Lee
a2b3975c12 no drive upload for test python source vms 2020-04-24 06:29:58 -04:00
Jay Lee
4b6cca8dd8 Upload draft GAM builds to Drive 2020-04-23 22:25:26 -04:00
Jay Lee
55b43b6bc0 remove old build scripts 2020-04-23 21:24:50 -04:00
Jay Lee
c987861f02 fix tar on *nix 2020-04-23 19:46:07 -04:00
Jay Lee
f92c4d18db try another technique to package 2020-04-23 19:29:18 -04:00
Jay Lee
eeebf56a78 osx fix 2020-04-23 17:06:18 -04:00
Jay Lee
a04f231c9e macos and win travis fixes 2020-04-23 16:40:07 -04:00
Jay Lee
7df2293f1b os.path.join... 2020-04-23 15:56:06 -04:00
Jay Lee
7dfdf4cdbd fix svars-write.py 2020-04-23 15:39:56 -04:00
Jay Lee
62fa5fef79 more travis cleanup 2020-04-23 15:28:57 -04:00
Jay Lee
ce9fe17994 Travis cleanup after packaging changes 2020-04-23 15:08:36 -04:00
Jay Lee
ff54449d1d specify scopes for "oauth create", cleanup create vs. use project 2020-04-23 14:55:35 -04:00
Jay Lee
43a8900c24 Set consent on "use project", ignore 409 project exists 2020-04-23 14:23:06 -04:00
ejochman
e1660aa909 Refactor into Python package format (#1165)
* Refactor into a python module format

-Updates import statements to be absolute vs implicitly relative
-Uses import syntax that minimizes the need to update references in code
and/or reformat affected lines (e.g. `import gapi.directory` becomes `from gam.gapi import directory as
gapi_directory`)
-Adds a `__main__.py` such that the module can be executed on its own
using standard `python3 -m gam` syntax
-Replaces __main__ import hack with module import
-Updates the GAM path to be the module's parent dir

* Add gam.py to /src for backwards compatibility

A stub that calls gam.__main__.main() to be used by users who are not
with the syntax of calling a module implementation. It should also
provide immediate backwards-compatibility with existing scripts with
references to this file.

* Move build tools back to the main dir and out of the package

* Fix pylint errors

* Update build spec to use new package format

Incorporates @jay0lee's patch from
https://github.com/jay0lee/GAM/pull/1165#issuecomment-618430828
2020-04-23 14:06:30 -04:00
Ross Scroggs
5f6306911f Keep those Mac OS zsh people happy/Fix documentation (#1164)
* Keep those Mac OS zsh people happy

* Drop obsolete option
2020-04-22 12:21:07 -04:00
Jay Lee
268d07938a GAM 5.06 2020-04-21 13:22:31 -04:00
Ross Scroggs
42a4ce5006 Improve report usage (#1160)
Add date range to skipdates

Make report name match dates; indicate if no data

If only enddate is specified change time period
current: now-1 month to enddate
improved: enddate-1 month to enddate
2020-04-21 13:21:53 -04:00
Jay Lee
251b0a0a93 skip pyinstaller on source only test linux builds 2020-04-21 11:43:10 -04:00
Jay Lee
153aca30dc ignore collaborator output 2020-04-21 10:23:32 -04:00
Jay Lee
d9b9aa7de4 fix matterid capture 2020-04-21 10:10:59 -04:00
Jay Lee
003d41a496 travis store matterid to speed up vault tests, openssl 1.1.1g 2020-04-21 09:54:50 -04:00
Jay Lee
18bc459850 fix pyinstaller googleapiclient handling and unify spec files again 2020-04-21 09:12:53 -04:00
Jay Lee
97f6781d8a fix showing Google API client version 2020-04-21 08:12:20 -04:00
Jay Lee
7a33c5e18c GAM 5.05 2020-04-15 08:32:25 -04:00
Ross Scroggs
971e2ff76a Make it easy to capture created drive file ID (#1159)
Linux/MacOS
fileId=`gam user user@domain.com create drivefile ...`
Windows PowerShell
$fileId = & gam user user@domain.com create drivefile ...`
2020-04-14 18:31:14 -04:00
Ross Scroggs
007a378f2b Add GAM_CSV_HEADER_DROP_FILTER (#1158)
It may be simpler to list headers you don't want that headers you do want
2020-04-11 17:07:45 -04:00
Ross Scroggs
2f02148e36 Fix bugs, cleanup, improvements (#1155)
* Fix bugs

* Appease pylint

* More report usage cleanup

* More report usage cleanup

* More report usage cleanup

* More report usage cleanup
2020-04-11 15:16:47 -04:00
Ross Scroggs
475fb4fa2e Update both bash and zsh aliases (#1153) 2020-04-07 09:41:53 -04:00
ejochman
f3d2ef86f8 Make get_token_value refresh credentials on its own, when necessary (#1152)
Any other transaction utilizing credentials will already refresh them,
as necessary, through the use of AuthorizedHttp. `get_token_value` is
one unique case where we're not actually attaching the credentials to
the HTTP request, but rather using one if its attributes as the payload.
The request, itself, is unauthenticated, so it doesn't know to refresh
on its own. Rather, the caller needs to make sure that the id_token
payload is for a currently-valid set of credentials.
2020-04-06 21:05:31 -04:00
Jay Lee
35d2fd4cbc fix travis reports 2020-04-06 20:20:29 -04:00
Ross Scroggs
c4f1a7eb70 Standarize usage/usageparameters under gam report (#1151)
gam report usage customer|user ...
gam report usageparameters customer|user
2020-04-06 19:52:12 -04:00
Jay Lee
c83430a537 ensure get_admin_credentials only returns fresh creds 2020-04-06 14:18:37 -04:00
Jay Lee
c398d30f37 Merge branch 'master' of https://github.com/jay0lee/GAM 2020-04-06 12:44:39 -04:00
Jay Lee
f60246846f remove debug stuff from reports.py 2020-04-06 12:43:12 -04:00
Ross Scroggs
3184de1392 Credentials must be current to get token values (#1149) 2020-04-06 11:23:11 -04:00
Jay Lee
921324d968 GAM 5.04 2020-04-06 11:21:59 -04:00
Jay Lee
c74cdeb773 fix report orgUnitID 2020-04-06 10:28:38 -04:00
Jay Lee
64ecf51ad9 fix travis tests 2020-04-06 10:16:01 -04:00
Jay Lee
518ad04815 fix for orgUnits, add travis test 2020-04-06 09:14:09 -04:00
Jay Lee
12ca54f6ba gam usage and gam usageparameters commands
usageparameters prints the parameters reported for customer and user
usage. usage generates a CSV of specified parameters over a given date
range. From a Google Sheet it's useful to add a chart to get a nice
graph showing changes in G Suite service usage by users over time.
2020-04-06 08:48:00 -04:00
Jay Lee
0a0ca9ef03 http.request is a function, should be using http.credentials 2020-04-02 12:09:52 -04:00
Jay Lee
9ef7b2f80a Merge branch 'master' of https://github.com/jay0lee/GAM 2020-04-01 09:20:54 -04:00
Jay Lee
86b0ed0a04 handle unicode body in send_email 2020-04-01 09:20:38 -04:00
Ross Scroggs
65e77e07a8 Fix typo (#1144) 2020-03-31 21:23:45 -04:00
51 changed files with 12320 additions and 12726 deletions

27
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.7
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-docstring-first
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.29.0
hooks:
- id: yapf
args: [--style=google, --in-place]
- repo: https://github.com/PyCQA/pylint
rev: pylint-2.4.4
hooks:
- id: pylint
args: [--output-format=colorized]

View File

@@ -7,8 +7,8 @@ env:
global:
- BUILD_PYTHON_VERSION=3.8.2
- MIN_PYTHON_VERSION=3.8.2
- BUILD_OPENSSL_VERSION=1.1.1f
- MIN_OPENSSL_VERSION=1.1.1f
- BUILD_OPENSSL_VERSION=1.1.1g
- MIN_OPENSSL_VERSION=1.1.1g
- PATCHELF_VERSION=0.10
- PYINSTALLER_VERSION=3.5
- secure: "FSKvLaiqhKz21SVgAQZI3bSX34Ffyev4l+R2G//QXNDu6UVQcuFsykzw+eZEG7fkhotXr8BMDL7xIkookiL8eLwUtcd/Z95HCjPBBHcmCSQleyvuuJBxdrQ9xldmiGLzMCYiumSH9OH4uJhQ39Yjnjsa8TK+PlTci6a/BTzlYyBSyDYDf7Iv/uhfQPDHL3pNwrQPHf4fL6/jcvo+uaPcv83AVZkNzZjjyoi9Aa+uh9xlbyHg11jp44463qqxoxTdYik3pYuXRBPjknjOGcnFHqn+QOVSdRQoiwbmT8xVuYuCzTv9THhuJ//i5u7s4y3Xyl7u17B3tdm86UlMpQHy/w9EsYaSBPOU4oPNomRtOnTSugh0v9ZBwptP5XfbslII/iA+LQdzTHhchn0W0CRyDqjOMSestWlrsq5NZJtBJTYHbebllOhEI7xbj9tY+re1zFWSPMOPgHJP23ovsdk3hD9OT93AzRHInCx5IxL6QvEgRhAancRuGkf2rGP0g/vX9fQ0Il3rNMSQxHB5CyHUBtUJ9nhU79YkMDZicD0jFMEwjWJO3itAp3ynoLXRgktgQCYUfgc9SpdWKD5SXLCYnSo22JD3D1P6h2EertRHaoKRLb+CRXQC/lM8uh/W+BjA2Xe6Vut2I/72ndjM+10T7E2xk1CFyCH37a5p8cH26Fs="
@@ -185,12 +185,12 @@ script:
- if [ "$e2e" = true ]; then $gam calendar $gam_user printacl | $gam csv - gam calendar $gam_user delete id ~id; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user addevent summary "Travis test event" start $(date '+%FT%T.%N%:z' -d "now + 1 hour") end $(date '+%FT%T.%N%:z' -d "now + 2 hours") attendee $newgroup hangoutsmeet guestscanmodify true sendupdates all; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user printevents after -0d; fi
- if [ "$e2e" = true ]; then $gam create vaultmatter name "Travis matter $newbase" description "test matter" collaborators $newuser; fi
- if [ "$e2e" = true ]; then $gam create vaulthold matter "Travis matter $newbase" name "Travis hold $newbase" corpus mail accounts $newuser; fi
- if [ "$e2e" = true ]; then matterid=uid:$($gam create vaultmatter name "Travis matter $newbase" description "test matter" collaborators $newuser | head -1 | cut -d ' ' -f 3); fi
- if [ "$e2e" = true ]; then $gam create vaulthold matter $matterid name "Travis hold $newbase" corpus mail accounts $newuser; fi
- if [ "$e2e" = true ]; then $gam print vaultmatters matterstate open; fi
- if [ "$e2e" = true ]; then $gam print vaultholds matter "Travis matter $newbase"; fi
- if [ "$e2e" = true ]; then $gam create vaultexport matter "Travis matter $newbase" name "Travis export $newbase" corpus mail accounts $newuser; fi
- if [ "$e2e" = true ]; then $gam print exports matter "Travis matter $newbase" | $gam csv - gam info export id:~~matterId~~ id:~~id~~; fi
- if [ "$e2e" = true ]; then $gam print vaultholds matter $matterid; fi
- if [ "$e2e" = true ]; then $gam create vaultexport matter $matterid name "Travis export $newbase" corpus mail accounts $newuser; fi
- if [ "$e2e" = true ]; then $gam print exports matter $matterid | $gam csv - gam info export $matterid id:~~id~~; fi
- if [ "$e2e" = true ]; then $gam csv sample.csv gam user ~email add calendar id:$newresource; fi
- if [ "$e2e" = true ]; then $gam delete resource $newresource; fi
- if [ "$e2e" = true ]; then $gam delete feature Whiteboard-$newbase; fi
@@ -200,17 +200,25 @@ script:
- if [ "$e2e" = true ]; then $gam create alias $newalias user $newuser; fi
- if [ "$e2e" = true ]; then $gam whatis $newuser; fi
- if [ "$e2e" = true ]; then $gam user $gam_user show tokens; fi
- if [ "$e2e" = true ]; then $gam print exports matter "Travis matter $newbase" | $gam csv - gam download export id:~~matterId~~ id:~~id~~; fi
- if [ "$e2e" = true ]; then $gam delete hold "Travis hold $newbase" matter "Travis matter $newbase"; fi
- if [ "$e2e" = true ]; then $gam update matter "Travis matter $newbase" action close; fi
- if [ "$e2e" = true ]; then $gam update matter "Travis matter $newbase" action delete; fi
- if [ "$e2e" = true ]; then $gam print exports matter $matterid | $gam csv - gam download export $matterid id:~~id~~; fi
- if [ "$e2e" = true ]; then $gam delete hold "Travis hold $newbase" matter $matterid; fi
- if [ "$e2e" = true ]; then $gam update matter $matterid action close; fi
- if [ "$e2e" = true ]; then $gam update matter $matterid action delete; fi
- if [ "$e2e" = true ]; then $gam delete user $newuser; fi
- if [ "$e2e" = true ]; then $gam print users query "travis.jid=$jid" | $gam csv - gam delete user ~primaryEmail; fi
- if [ "$e2e" = true ]; then $gam print mobile; fi
- if [ "$e2e" = true ]; then $gam print cros allfields nolists; fi
- if [ "$e2e" = true ]; then $gam report usageparameters customer; fi
- if [ "$e2e" = true ]; then $gam report usage customer parameters gmail:num_emails_sent,accounts:num_1day_logins; fi
- if [ "$e2e" = true ]; then $gam report customer todrive; fi
- if [ "$e2e" = true ]; then $gam report users fulldatarequired accounts,gmail fields accounts:is_less_secure_apps_access_allowed,gmail:last_imap_time,gmail:last_pop_time filters "accounts:last_login_time>2019-01-01T00:00:00.000Z" todrive; fi
- if [ "$e2e" = true ]; then $gam report users fields accounts:is_less_secure_apps_access_allowed,gmail:last_imap_time,gmail:last_pop_time filters "accounts:last_login_time>2019-01-01T00:00:00.000Z" todrive; fi
- if [ "$e2e" = true ]; then $gam report admin start -3d todrive; fi
- if ([ "$e2e" = true ] && [[ "$TRAVIS_JOB_NAME" != *"Testing" ]]); then
for gamfile in gam-$GAMVERSION-*; do
fileid=$($gam user $gam_user add drivefile localfile $gamfile drivefilename $GAMVERSION-$TRAVIS_COMMIT-$gamfile parentid 1N2zbO33qzUQFsGM49-m9AQC1ijzd_ru1 returnidonly);
$gam user $gam_user add drivefileacl $fileid anyone role reader withlink;
done;
fi
before_deploy:
- export TRAVIS_TAG="preview"

2
src/.gitignore vendored
View File

@@ -64,7 +64,7 @@ nobrowser.txt
nocache.txt
noverifyssl.txt
gamcache/
gam/
dist/
gam-64/
*.zip
*.msi

View File

@@ -38,6 +38,7 @@ If an item contains spaces, it should be surrounded by ".
papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|
saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|
tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen
<DayOfWeek> ::= mon|tue|wed|thu|fri|sat|sun
<FileFormat> ::=
csv|html|txt|tsv|jpeg|jpg|png|svg|pdf|rtf|pptx|xlsx|docx|odt|ods|openoffice|ms|microsoft|micro$oft
<LabelColorHex> ::=
@@ -844,6 +845,7 @@ gam delete sakey|sakeys <ServiceAccountKeyList>+ [doit]
gam show sakey|sakeys [all|system|user]
gam oauth|oauth2 create|request [<EmailAddress>]
gam oauth|oauth2 create|request [admin <EmailAddress>] [scope|scopes <APIScopeURLList>]
gam oauth|oauth2 delete|revoke
gam oauth|oauth2 info|verify [accesstoken <AccessToken>] [idtoken <IDToken>] [showsecret]
gam oauth|oauth2 refresh
@@ -914,12 +916,28 @@ gam info resoldsubscriptions <CustomerID> [customer_auth_token <String>]
sites
<ReportsAppList> ::= "<ReportsApp>(,<ReportsApp>)*"
gam report users|user [todrive] [date <Date>] [fulldatarequired all|<ReportsAppList>]
[(user <UserItem>)|(orgunit|org|ou <OrgUnitPath>)] [filter|filters <String>] [fields|parameters <String>]
gam report customers|customer|domain [todrive] [date <Date>] [fulldatarequired all|<ReportsAppList>]
gam report usageparameters customer|user [todrive]
gam report usage user [todrive]
[<UserTypeItem>)|(orgunit|org|ou <OrgUnitPath>)]
[startdate <Date>] [enddate <Date>]
[skipdates <Date>[:<Date>](,<Date>[:<Date>])*] [skipdaysofweek <DayOfWeek>(,<DayOfWeek>)*]
[fields|parameters <String>]
gam report usage customer [todrive]
[startdate <Date>] [enddate <Date>]
[skipdates <Date>[:<Date>](,<Date>[:<Date>])*] [skipdaysofweek <DayOfWeek>(,<DayOfWeek>)*]
[fields|parameters <String>]
gam report users|user [todrive]
[(user <UserItem>)|(orgunit|org|ou <OrgUnitPath>)]
[date <Date>] [fulldatarequired all|<ReportsAppList>]
[filter|filters <String>] [fields|parameters <String>]
gam report customers|customer|domain [todrive]
[date <Date>] [fulldatarequired all|<ReportsAppList>]
[fields|parameters <String>]
gam report <ActivityApplicationName> [todrive]
[start <Time>] [end <Time>] [(user all|<UserItem>)] [event <String>] [filter|filters <String>] [ip <String>]
[user all|<UserItem>]
[start <Time>] [end <Time>]
[filter|filters <String>] [event <String>] [ip <String>]
gam create admin <UserItem> <RoleItem> customer|(org_unit <OrgUnitItem>)
gam delete admin <RoleAssignmentId>
@@ -1050,11 +1068,11 @@ gam calendar <CalendarItem> printevents <EventSelectProperty>* <EventDisplayProp
gam calendar <CalendarItem> modify <CalendarSettings>+
gam update cros <CrOSEntity> (<CrOSAttributes>+)|(action deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device|disable|reenable [acknowledge_device_touch_requirement])
gam info cros <CrOSEntity> [guessaue] [nolists] [listlimit <Number>] [start <Date>] [end <Date>]
gam info cros <CrOSEntity> [nolists] [listlimit <Number>] [start <Date>] [end <Date>]
[basic|full|allfields] <CrOSFieldName>* [fields <CrOSFieldNameList>] [downloadfile latest|<Time>] [targetfolder <FilePath>]
gam print cros [todrive] [(query <QueryCrOS>)|(queries <QueryCrOSList>)] [limittoou <OrgUnitItem>]
[orderby <CrOSOrderByFieldName> [ascending|descending]] [guessaue] [nolists|<CrOSListFieldName>*] [listlimit <Number>] [start <Date>] [end <Date>]
[orderby <CrOSOrderByFieldName> [ascending|descending]] [nolists|<CrOSListFieldName>*] [listlimit <Number>] [start <Date>] [end <Date>]
[basic|full|allfields] <CrOSFieldName>* [fields <CrOSFieldNameList>] [sortheaders]
gam <CrOSTypeEntity> print
@@ -1282,7 +1300,7 @@ gam <UserTypeEntity> show fileinfo <DriveFileID> [allfields|<DriveFieldName>*]
gam <UserTypeEntity> show filerevisions <DriveFileID>
gam <UserTypeEntity> show filetree [anyowner] (orderby <DriveOrderByFieldName> [ascending|descending])*
gam <UserTypeEntity> create|add drivefile [drivefilename <DriveFileName>] <DriveFileAddAttributes>* [csv] [todrive]
gam <UserTypeEntity> create|add drivefile [drivefilename <DriveFileName>] <DriveFileAddAttributes>* [csv] [todrive] [returnidonly]
gam <UserTypeEntity> update drivefile (id <DriveFileID)|(drivefilename <DriveFileName>)|(query <QueryDriveFile) [copy] [newfilename <DriveFileName>] <DriveFileUpdateAttributes>*
gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(drivefilename <DriveFileName>)|(query <QueryDriveFile>)
[revision <Number>] [(format <FileFormatList>)|(csvsheet <String>)]

View File

@@ -1,27 +0,0 @@
"""Authentication/Credentials general purpose and convenience methods."""
from . import oauth
from var import _FN_OAUTH2_TXT
from var import GC_OAUTH2_TXT
from var import GC_Values
# TODO: Move logic that determines file name into this module. We should be able
# to discover the file location without accessing a private member or waiting
# for a global initialization.
DEFAULT_OAUTH_STORAGE_FILE = _FN_OAUTH2_TXT
def get_admin_credentials_filename():
"""Gets the name of the file that stores the admin account credentials."""
# If the environment globals are loaded, use the set global value. It may have
# some custom name in it. Otherwise, just use the default name.
if GC_Values[GC_OAUTH2_TXT]:
return GC_Values[GC_OAUTH2_TXT]
else:
return DEFAULT_OAUTH_STORAGE_FILE
def get_admin_credentials():
"""Gets oauth.Credentials that are authenticated as the domain's admin user."""
credential_file = get_admin_credentials_filename()
return oauth.Credentials.from_credentials_file(credential_file)

View File

@@ -238,9 +238,11 @@ fi
if [ "$update_profile" = true ]; then
alias_line="gam() { \"$target_dir/gam/gam\" \"\$@\" ; }"
if [ "$gamos" == "linux" ]; then
update_profile "$HOME/.bash_aliases" 0 || update_profile "$HOME/.bash_profile" 0 || update_profile "$HOME/.bashrc" 0 || update_profile "$HOME/.zshrc" 0
update_profile "$HOME/.bash_aliases" 0 || update_profile "$HOME/.bash_profile" 0 || update_profile "$HOME/.bashrc" 0
update_profile "$HOME/.zshrc" 0
elif [ "$gamos" == "macos" ]; then
update_profile "$HOME/.bash_aliases" 0 || update_profile "$HOME/.bash_profile" 0 || update_profile "$HOME/.bashrc" 0 || update_profile "$HOME/.zshrc" 0 || update_profile "$HOME/.profile" 1
update_profile "$HOME/.bash_aliases" 0 || update_profile "$HOME/.bash_profile" 0 || update_profile "$HOME/.bashrc" 0 || update_profile "$HOME/.profile" 1
update_profile "$HOME/.zshrc" 1
fi
else
echo_yellow "skipping profile update."

11589
src/gam.py

File diff suppressed because it is too large Load Diff

View File

@@ -2,23 +2,31 @@
import sys
import importlib
from PyInstaller.utils.hooks import copy_metadata
sys.modules['FixTk'] = None
a = Analysis(['gam.py'],
extra_files = [('cloudprint-v2.json', 'cloudprint-v2.json')]
# dynamically determine where httplib2/cacerts.txt lives
proot = os.path.dirname(importlib.import_module('httplib2').__file__)
extra_files += [(os.path.join(proot, 'cacerts.txt'), 'httplib2')]
extra_files += copy_metadata('google-api-python-client')
a = Analysis(['gam/__main__.py'],
hiddenimports=[],
hookspath=None,
excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
datas=extra_files,
runtime_hooks=None)
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
a.datas += [('cloudprint-v2.json', 'cloudprint-v2.json', 'DATA')]
# dynamically determine where httplib2/cacerts.txt lives
import importlib
proot = os.path.dirname(importlib.import_module('httplib2').__file__)
a.datas += [('httplib2/cacerts.txt', os.path.join(proot, 'cacerts.txt'), 'DATA')]
pyz = PYZ(a.pure)
exe = EXE(pyz,

View File

@@ -41,7 +41,7 @@
<ComponentGroup
Id="ProductComponents"
Directory="INSTALLFOLDER"
Source="gam-64">
Source="dist/gam">
<Component Id="gam_exe" Guid="886abc07-73c5-4acc-9f71-58daf62aabc1">
<File Name="gam.exe" KeyPath="yes" />
<Environment Id="PATH" Name="PATH" Value="[INSTALLFOLDER]" Permanent="yes" Part="last" Action="set" System="yes" />
@@ -49,9 +49,6 @@
<Component Id="license" Guid="7a15de2e-fb91-4d0a-b8bf-c8b19c68f569">
<File Name="LICENSE" KeyPath="yes" />
</Component>
<Component Id="whatsnew_txt" Guid="6aa9863c-90d9-412f-9b73-fda82549a950">
<File Name="whatsnew.txt" KeyPath="yes" />
</Component>
<Component Id="gam_setup_bat" Guid="ef01f93a-4b50-488a-9c04-ec5e13e66218">
<File Name="gam-setup.bat" KeyPath="yes" />
</Component>

11598
src/gam/__init__.py Executable file

File diff suppressed because it is too large Load Diff

47
src/gam/__main__.py Normal file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# GAM
#
# Copyright 2019, LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""GAM is a command line tool which allows Administrators to control their G Suite domain and accounts.
With GAM you can programmatically create users, turn on/off services for users like POP and Forwarding and much more.
For more information, see https://git.io/gam
"""
import sys
from multiprocessing import freeze_support
from multiprocessing import set_start_method
from gam import controlflow
import gam
def main(argv):
freeze_support()
if sys.platform == 'darwin':
# https://bugs.python.org/issue33725 in Python 3.8.0 seems
# to break parallel operations with errors about extra -b
# command line arguments
set_start_method('fork')
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
controlflow.system_error_exit(5,
f'GAM requires Python 3.6 or newer. You are running %s.%s.%s. Please upgrade your Python version or use one of the binary GAM downloads.' % sys.version_info[
:3])
sys.exit(gam.ProcessGAMCommand(sys.argv))
# Run from command line
if __name__ == "__main__":
main(sys.argv)

26
src/gam/auth/__init__.py Normal file
View File

@@ -0,0 +1,26 @@
"""Authentication/Credentials general purpose and convenience methods."""
from gam.auth import oauth
from gam.var import _FN_OAUTH2_TXT
from gam.var import GC_OAUTH2_TXT
from gam.var import GC_Values
# TODO: Move logic that determines file name into this module. We should be able
# to discover the file location without accessing a private member or waiting
# for a global initialization.
DEFAULT_OAUTH_STORAGE_FILE = _FN_OAUTH2_TXT
def get_admin_credentials_filename():
"""Gets the name of the file that stores the admin account credentials."""
# If the environment globals are loaded, use the set global value. It may have
# some custom name in it. Otherwise, just use the default name.
if GC_Values[GC_OAUTH2_TXT]:
return GC_Values[GC_OAUTH2_TXT]
return DEFAULT_OAUTH_STORAGE_FILE
def get_admin_credentials():
"""Gets oauth.Credentials that are authenticated as the domain's admin user."""
credential_file = get_admin_credentials_filename()
return oauth.Credentials.from_credentials_file(credential_file)

View File

@@ -12,12 +12,11 @@ import google_auth_oauthlib.flow
import google.oauth2.credentials
import google.oauth2.id_token
import fileutils
import transport
from var import GAM_INFO
from var import GM_Globals
from var import GM_WINDOWS
import utils
from gam import fileutils
from gam import transport
from gam.var import GM_Globals
from gam.var import GM_WINDOWS
from gam import utils
MESSAGE_CONSOLE_AUTHORIZATION_PROMPT = ('\nGo to the following link in your '
'browser:\n\n\t{url}\n')
@@ -382,7 +381,12 @@ class Credentials(google.oauth2.credentials.Credentials):
"""
if not self.id_token:
raise CredentialsError('Failed to fetch token data. No id_token present.')
request = transport.create_request()
if self.expired:
# The id_token needs to be unexpired, in order to request data about it.
self.refresh(request)
self._id_token_data = google.oauth2.id_token.verify_oauth2_token(
self.id_token, request)

View File

@@ -10,7 +10,7 @@ from unittest.mock import patch
import google.oauth2.credentials
from auth import oauth
from gam.auth import oauth
class CredentialsTest(unittest.TestCase):
@@ -336,6 +336,26 @@ class CredentialsTest(unittest.TestCase):
id_token_data=self.fake_token_data)
self.assertEqual('Unknown', creds.get_token_value('unknown-field'))
@patch.object(oauth.google.oauth2.id_token, 'verify_oauth2_token')
def test_get_token_value_credentials_expired(self, mock_verify_oauth2_token):
mock_verify_oauth2_token.return_value = {'fetched-field': 'fetched-value'}
time_earlier_than_now = datetime.datetime.now() - datetime.timedelta(
minutes=5)
creds = oauth.Credentials(
token=self.fake_token,
client_id=self.fake_client_id,
client_secret=self.fake_client_secret,
expiry=time_earlier_than_now,
id_token=self.fake_id_token,
id_token_data=None)
self.assertTrue(creds.expired)
creds.refresh = MagicMock()
token_value = creds.get_token_value('fetched-field')
self.assertEqual('fetched-value', token_value)
self.assertTrue(creds.refresh.called)
def test_to_json_contains_all_required_fields(self):
creds = oauth.Credentials(
token=self.fake_token,
@@ -585,7 +605,7 @@ class ShortUrlFlowTest(unittest.TestCase):
@patch.object(oauth.google_auth_oauthlib.flow.InstalledAppFlow,
'authorization_url')
@unittest.skip("disable short url tests temporarily.")
@unittest.skip('disable short url tests temporarily.')
def test_shorturlflow_returns_shortened_url(self, mock_super_auth_url):
url_flow = oauth._ShortURLFlow.from_client_config(
self.fake_client_config, scopes=self.fake_scopes)
@@ -609,7 +629,7 @@ class ShortUrlFlowTest(unittest.TestCase):
@patch.object(oauth.google_auth_oauthlib.flow.InstalledAppFlow,
'authorization_url')
@unittest.skip("disable short url tests temporarily.")
@unittest.skip('disable short url tests temporarily.')
def test_shorturlflow_falls_back_to_long_url_on_request_error(
self, mock_super_auth_url):
url_flow = oauth._ShortURLFlow.from_client_config(
@@ -625,7 +645,7 @@ class ShortUrlFlowTest(unittest.TestCase):
@patch.object(oauth.google_auth_oauthlib.flow.InstalledAppFlow,
'authorization_url')
@unittest.skip("disable short url tests temporarily.")
@unittest.skip('disable short url tests temporarily.')
def test_shorturlflow_falls_back_to_long_url_on_non_200_response_status(
self, mock_super_auth_url):
url_flow = oauth._ShortURLFlow.from_client_config(
@@ -644,7 +664,7 @@ class ShortUrlFlowTest(unittest.TestCase):
@patch.object(oauth.google_auth_oauthlib.flow.InstalledAppFlow,
'authorization_url')
@unittest.skip("disable short url tests temporarily.")
@unittest.skip('disable short url tests temporarily.')
def test_shorturlflow_falls_back_to_long_url_on_bad_json_response(
self, mock_super_auth_url):
url_flow = oauth._ShortURLFlow.from_client_config(
@@ -663,7 +683,7 @@ class ShortUrlFlowTest(unittest.TestCase):
@patch.object(oauth.google_auth_oauthlib.flow.InstalledAppFlow,
'authorization_url')
@unittest.skip("disable short url tests temporarily.")
@unittest.skip('disable short url tests temporarily.')
def test_shorturlflow_falls_back_to_long_url_on_empty_short_url_field(
self, mock_super_auth_url):
url_flow = oauth._ShortURLFlow.from_client_config(

View File

@@ -3,9 +3,9 @@ import random
import sys
import time
import display # TODO: Change to relative import when gam is setup as a package
from var import MESSAGE_HEADER_NOT_FOUND_IN_CSV_HEADERS
from var import MESSAGE_INVALID_JSON
from gam import display
from gam.var import MESSAGE_HEADER_NOT_FOUND_IN_CSV_HEADERS
from gam.var import MESSAGE_INVALID_JSON
def system_error_exit(return_code, message):
@@ -21,38 +21,35 @@ def system_error_exit(return_code, message):
def invalid_argument_exit(argument, command):
'''Indicate that the argument is not valid for the command.
"""Indicate that the argument is not valid for the command.
Args:
argument: the invalid argument
command: the base GAM command
'''
system_error_exit(
2,
f'{argument} is not a valid argument for "{command}"')
"""
system_error_exit(2, f'{argument} is not a valid argument for "{command}"')
def missing_argument_exit(argument, command):
'''Indicate that the argument is missing for the command.
"""Indicate that the argument is missing for the command.
Args:
argument: the missingagrument
command: the base GAM command
'''
system_error_exit(
2,
f'missing argument {argument} for "{command}"')
"""
system_error_exit(2, f'missing argument {argument} for "{command}"')
def expected_argument_exit(name, expected, argument):
'''Indicate that the argument does not have an expected value for the command.
"""Indicate that the argument does not have an expected value for the command.
Args:
name: the field name
expected: the expected values
argument: the invalid argument
'''
system_error_exit(
2,
f'{name} must be one of {expected}; got {argument}')
"""
system_error_exit(2, f'{name} must be one of {expected}; got {argument}')
def csv_field_error_exit(field_name, field_names):
"""Raises a system exit when a CSV field is malformed.
@@ -93,7 +90,7 @@ def wait_on_failure(current_attempt_num,
60) + float(random.randint(1, 1000)) / 1000
if current_attempt_num > error_print_threshold:
sys.stderr.write((f'Temporary error: {error_message}, Backing off: '
f'{int(wait_on_fail)} seconds, Retry: '
f'{current_attempt_num}/{total_num_retries}\n'))
f'{int(wait_on_fail)} seconds, Retry: '
f'{current_attempt_num}/{total_num_retries}\n'))
sys.stderr.flush()
time.sleep(wait_on_fail)

View File

@@ -3,7 +3,7 @@
import unittest
from unittest.mock import patch
import controlflow
from gam import controlflow
class ControlFlowTest(unittest.TestCase):

View File

@@ -10,10 +10,10 @@ import dateutil
import googleapiclient.http
#TODO: get rid of these hacks
import __main__
from var import *
import controlflow
import gapi
import gam
from gam.var import *
from gam import controlflow
from gam import gapi
def current_count(i, count):
@@ -130,8 +130,8 @@ def write_csv_file(csvRows, titles, list_type, todrive):
return False
return rowBoolean == filterBoolean
def headerFilterMatch(title):
for filterStr in GC_Values[GC_CSV_HEADER_FILTER]:
def headerFilterMatch(filters, title):
for filterStr in filters:
if filterStr.match(title):
return True
return False
@@ -151,10 +151,13 @@ def write_csv_file(csvRows, titles, list_type, todrive):
csvRows = [row for row in csvRows if rowCountFilterMatch(row.get(column, 0), filterVal[1], filterVal[2])]
else: #boolean
csvRows = [row for row in csvRows if rowBooleanFilterMatch(row.get(column, False), filterVal[1])]
if GC_Values[GC_CSV_HEADER_FILTER]:
titles = [t for t in titles if headerFilterMatch(t)]
if GC_Values[GC_CSV_HEADER_FILTER] or GC_Values[GC_CSV_HEADER_DROP_FILTER]:
if GC_Values[GC_CSV_HEADER_DROP_FILTER]:
titles = [t for t in titles if not headerFilterMatch(GC_Values[GC_CSV_HEADER_DROP_FILTER], t)]
if GC_Values[GC_CSV_HEADER_FILTER]:
titles = [t for t in titles if headerFilterMatch(GC_Values[GC_CSV_HEADER_FILTER], t)]
if not titles:
controlflow.system_error_exit(3, 'No columns selected with GAM_CSV_HEADER_FILTER\n')
controlflow.system_error_exit(3, 'No columns selected with GAM_CSV_HEADER_FILTER and GAM_CSV_HEADER_DROP_FILTER\n')
return
csv.register_dialect('nixstdout', lineterminator='\n')
if todrive:
@@ -168,8 +171,8 @@ def write_csv_file(csvRows, titles, list_type, todrive):
except IOError as e:
controlflow.system_error_exit(6, e)
if todrive:
admin_email = __main__._getValueFromOAuth('email')
_, drive = __main__.buildDrive3GAPIObject(admin_email)
admin_email = gam._getValueFromOAuth('email')
_, drive = gam.buildDrive3GAPIObject(admin_email)
if not drive:
print(f'''\nGAM is not authorized to create Drive files. Please run:
gam user {admin_email} check serviceaccount
@@ -197,7 +200,7 @@ and follow recommend steps to authorize GAM for Drive access.''')
if GC_Values[GC_NO_BROWSER]:
msg_txt = f'Drive file uploaded to:\n {file_url}'
msg_subj = f'{GC_Values[GC_DOMAIN]} - {list_type}'
__main__.send_email(msg_subj, msg_txt)
gam.send_email(msg_subj, msg_txt)
print(msg_txt)
else:
webbrowser.open(file_url)

View File

@@ -3,9 +3,9 @@
import unittest
from unittest.mock import patch
import display
from var import ERROR_PREFIX
from var import WARNING_PREFIX
from gam import display
from gam.var import ERROR_PREFIX
from gam.var import WARNING_PREFIX
class DisplayTest(unittest.TestCase):

View File

@@ -4,11 +4,11 @@ import io
import os
import sys
import controlflow
import display
from var import GM_Globals
from var import GM_SYS_ENCODING
from var import UTF8_SIG
from gam import controlflow
from gam import display
from gam.var import GM_Globals
from gam.var import GM_SYS_ENCODING
from gam.var import UTF8_SIG
def _open_file(filename, mode, encoding=None, newline=None):

View File

@@ -6,7 +6,7 @@ import unittest
from unittest.mock import MagicMock
from unittest.mock import patch
import fileutils
from gam import fileutils
class FileutilsTest(unittest.TestCase):

View File

@@ -6,14 +6,14 @@ import googleapiclient.errors
import google.auth.exceptions
import httplib2
import controlflow
import display
from gapi import errors
import transport
from var import (GM_Globals, GM_CURRENT_API_SCOPES, GM_CURRENT_API_USER,
GM_EXTRA_ARGS_DICT, GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID,
MAX_RESULTS_API_EXCEPTIONS, MESSAGE_API_ACCESS_CONFIG,
MESSAGE_API_ACCESS_DENIED, MESSAGE_SERVICE_NOT_APPLICABLE)
from gam import controlflow
from gam import display
from gam.gapi import errors
from gam import transport
from gam.var import (GM_Globals, GM_CURRENT_API_SCOPES, GM_CURRENT_API_USER,
GM_EXTRA_ARGS_DICT, GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID,
MAX_RESULTS_API_EXCEPTIONS, MESSAGE_API_ACCESS_CONFIG,
MESSAGE_API_ACCESS_DENIED, MESSAGE_SERVICE_NOT_APPLICABLE)
def call(service,
@@ -63,7 +63,7 @@ def call(service,
if http_status == -1:
# The error detail indicated that we should retry this request
# We'll refresh credentials and make another pass
service._http.request.credentials.refresh(transport.create_http())
service._http.credentials.refresh(transport.create_http())
continue
if http_status == 0:
return None

View File

@@ -6,8 +6,8 @@ from unittest.mock import MagicMock
from unittest.mock import patch
from gam import SetGlobalVariables
import gapi
from gapi import errors
import gam.gapi as gapi
from gam.gapi import errors
def create_http_error(status, reason, message):
@@ -108,7 +108,7 @@ class GapiTest(unittest.TestCase):
self.mock_service, self.mock_method_name, soft_errors=True)
self.assertEqual(response, fake_200_response)
self.assertEqual(
self.mock_service._http.request.credentials.refresh.call_count, 1)
self.mock_service._http.credentials.refresh.call_count, 1)
self.assertEqual(self.mock_method.return_value.execute.call_count, 2)
def test_call_throws_for_provided_reason(self):

View File

@@ -3,28 +3,28 @@ import sys
import uuid
# TODO: get rid of these hacks
import __main__
from var import *
import gam
from gam.var import *
import controlflow
import display
import fileutils
import gapi
import utils
from gam import controlflow
from gam import display
from gam import fileutils
from gam import gapi
from gam import utils
def normalizeCalendarId(calname, checkPrimary=False):
if checkPrimary and calname.lower() == 'primary':
return calname
if not GC_Values[GC_DOMAIN]:
GC_Values[GC_DOMAIN] = __main__._getValueFromOAuth('hd')
return __main__.convertUIDtoEmailAddress(calname,
GC_Values[GC_DOMAIN] = gam._getValueFromOAuth('hd')
return gam.convertUIDtoEmailAddress(calname,
email_types=['user', 'resource'])
def buildCalendarGAPIObject(calname):
calendarId = normalizeCalendarId(calname)
return (calendarId, __main__.buildGAPIServiceObject('calendar',
return (calendarId, gam.buildGAPIServiceObject('calendar',
calendarId))
@@ -36,9 +36,9 @@ def buildCalendarDataGAPIObject(calname):
# so we need to access them as the admin.
cal = None
if not calname.endswith('.calendar.google.com'):
cal = __main__.buildGAPIServiceObject('calendar', calendarId, False)
cal = gam.buildGAPIServiceObject('calendar', calendarId, False)
if cal is None:
_, cal = buildCalendarGAPIObject(__main__._getValueFromOAuth('email'))
_, cal = buildCalendarGAPIObject(gam._getValueFromOAuth('email'))
return (calendarId, cal)
def printShowACLs(csvFormat):
@@ -87,7 +87,7 @@ def _getCalendarACLScope(i, body):
body['scope']['type'] = myarg
i += 1
if myarg in ['user', 'group']:
body['scope']['value'] = __main__.normalizeEmailAddressOrUID(
body['scope']['value'] = gam.normalizeEmailAddressOrUID(
sys.argv[i], noUid=True)
i += 1
elif myarg == 'domain':
@@ -99,7 +99,7 @@ def _getCalendarACLScope(i, body):
body['scope']['value'] = GC_Values[GC_DOMAIN]
elif myarg != 'default':
body['scope']['type'] = 'user'
body['scope']['value'] = __main__.normalizeEmailAddressOrUID(
body['scope']['value'] = gam.normalizeEmailAddressOrUID(
myarg, noUid=True)
return i
@@ -130,7 +130,7 @@ def addACL(function):
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg == 'sendnotifications':
sendNotifications = __main__.getBoolean(sys.argv[i+1], myarg)
sendNotifications = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
else:
controlflow.invalid_argument_exit(
@@ -237,7 +237,7 @@ def getSendUpdates(myarg, i, cal):
sendUpdates = 'all'
i += 1
elif myarg == 'sendnotifications':
sendUpdates = 'all' if __main__.getBoolean(sys.argv[i+1], myarg) else 'none'
sendUpdates = 'all' if gam.getBoolean(sys.argv[i+1], myarg) else 'none'
i += 2
else: # 'sendupdates':
sendUpdatesMap = {}
@@ -393,18 +393,18 @@ def getEventAttributes(i, calendarId, cal, body, action):
body['guestsCanInviteOthers'] = False
i += 1
elif myarg == 'guestscaninviteothers':
body['guestsCanInviteTohters'] = __main__.getBoolean(
body['guestsCanInviteTohters'] = gam.getBoolean(
sys.argv[i+1], 'guestscaninviteothers')
i += 2
elif myarg == 'guestscantseeothers':
body['guestsCanSeeOtherGuests'] = False
i += 1
elif myarg == 'guestscanseeothers':
body['guestsCanSeeOtherGuests'] = __main__.getBoolean(
body['guestsCanSeeOtherGuests'] = gam.getBoolean(
sys.argv[i+1], 'guestscanseeothers')
i += 2
elif myarg == 'guestscanmodify':
body['guestsCanModify'] = __main__.getBoolean(
body['guestsCanModify'] = gam.getBoolean(
sys.argv[i+1], 'guestscanmodify')
i += 2
elif myarg == 'id':
@@ -458,7 +458,7 @@ def getEventAttributes(i, calendarId, cal, body, action):
i += 1
elif myarg == 'reminder':
minutes = \
__main__.getInteger(sys.argv[i+1], myarg, minVal=0,
gam.getInteger(sys.argv[i+1], myarg, minVal=0,
maxVal=CALENDAR_REMINDER_MAX_MINUTES)
reminder = {'minutes': minutes, 'method': sys.argv[i+2]}
body.setdefault(
@@ -483,7 +483,7 @@ def getEventAttributes(i, calendarId, cal, body, action):
body['extendedProperties']['shared'][sys.argv[i+1]] = sys.argv[i+2]
i += 3
elif myarg == 'colorindex':
body['colorId'] = __main__.getInteger(
body['colorId'] = gam.getInteger(
sys.argv[i+1], myarg, CALENDAR_EVENT_MIN_COLOR_INDEX,
CALENDAR_EVENT_MAX_COLOR_INDEX)
i += 2
@@ -649,25 +649,25 @@ def getCalendarAttributes(i, body, function):
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg == 'selected':
body['selected'] = __main__.getBoolean(sys.argv[i+1], myarg)
body['selected'] = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
elif myarg == 'hidden':
body['hidden'] = __main__.getBoolean(sys.argv[i+1], myarg)
body['hidden'] = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
elif myarg == 'summary':
body['summaryOverride'] = sys.argv[i+1]
i += 2
elif myarg == 'colorindex':
body['colorId'] = __main__.getInteger(
body['colorId'] = gam.getInteger(
sys.argv[i+1], myarg, minVal=CALENDAR_MIN_COLOR_INDEX,
maxVal=CALENDAR_MAX_COLOR_INDEX)
i += 2
elif myarg == 'backgroundcolor':
body['backgroundColor'] = __main__.getColor(sys.argv[i+1])
body['backgroundColor'] = gam.getColor(sys.argv[i+1])
colorRgbFormat = True
i += 2
elif myarg == 'foregroundcolor':
body['foregroundColor'] = __main__.getColor(sys.argv[i+1])
body['foregroundColor'] = gam.getColor(sys.argv[i+1])
colorRgbFormat = True
i += 2
elif myarg == 'reminder':
@@ -677,7 +677,7 @@ def getCalendarAttributes(i, body, function):
if method not in CALENDAR_REMINDER_METHODS:
controlflow.expected_argument_exit("Method", ", ".join(
CALENDAR_REMINDER_METHODS+CLEAR_NONE_ARGUMENT), method)
minutes = __main__.getInteger(
minutes = gam.getInteger(
sys.argv[i+2], myarg, minVal=0,
maxVal=CALENDAR_REMINDER_MAX_MINUTES)
body['defaultReminders'].append(
@@ -862,7 +862,7 @@ def transferSecCals(users):
remove_source_user = False
i += 1
elif myarg == 'sendnotifications':
sendNotifications = __main__.getBoolean(sys.argv[i+1], myarg)
sendNotifications = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
else:
controlflow.invalid_argument_exit(

View File

@@ -0,0 +1,5 @@
import gam
def buildGAPIObject():
return gam.buildGAPIObject('directory')

View File

@@ -1,17 +1,17 @@
import datetime
from var import *
import __main__
import controlflow
import display
import fileutils
import gapi
import gapi.directory
import utils
from gam.var import *
import gam
from gam import controlflow
from gam import display
from gam import fileutils
from gam import gapi
from gam.gapi import directory as gapi_directory
from gam import utils
def doUpdateCros():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
i, devices = getCrOSDeviceEntity(3, cd)
update_body = {}
action_body = {}
@@ -32,7 +32,7 @@ def doUpdateCros():
update_body['annotatedAssetId'] = sys.argv[i+1]
i += 2
elif myarg in ['ou', 'org']:
orgUnitPath = __main__.getOrgUnitItem(sys.argv[i+1])
orgUnitPath = gam.getOrgUnitItem(sys.argv[i+1])
i += 2
elif myarg == 'action':
action = sys.argv[i+1].lower().replace('_', '').replace('-', '')
@@ -84,7 +84,7 @@ def doUpdateCros():
sys.exit(3)
for deviceId in devices:
i += 1
cur_count = __main__.currentCount(i, count)
cur_count = gam.currentCount(i, count)
print(f' performing action {action} for {deviceId}{cur_count}')
gapi.call(cd.chromeosdevices(), function='action',
customerId=GC_Values[GC_CUSTOMER_ID],
@@ -93,7 +93,7 @@ def doUpdateCros():
if update_body:
for deviceId in devices:
i += 1
current_count = __main__.currentCount(i, count)
current_count = gam.currentCount(i, count)
print(f' updating {deviceId}{current_count}')
gapi.call(cd.chromeosdevices(), 'update',
customerId=GC_Values[GC_CUSTOMER_ID],
@@ -110,7 +110,7 @@ def doUpdateCros():
def doGetCrosInfo():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
i, devices = getCrOSDeviceEntity(3, cd)
downloadfile = None
targetFolder = GC_Values[GC_DRIVE_DIR]
@@ -125,7 +125,7 @@ def doGetCrosInfo():
noLists = True
i += 1
elif myarg == 'listlimit':
listLimit = __main__.getInteger(sys.argv[i+1], myarg, minVal=-1)
listLimit = gam.getInteger(sys.argv[i+1], myarg, minVal=-1)
i += 2
elif myarg in CROS_START_ARGUMENTS:
startDate = _getFilterDate(sys.argv[i+1])
@@ -318,7 +318,7 @@ def doGetCrosInfo():
def doPrintCrosActivity():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
todrive = False
titles = ['deviceId', 'annotatedAssetId',
'annotatedLocation', 'serialNumber', 'orgUnitPath']
@@ -335,10 +335,10 @@ def doPrintCrosActivity():
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg in ['query', 'queries']:
queries = __main__.getQueries(myarg, sys.argv[i+1])
queries = gam.getQueries(myarg, sys.argv[i+1])
i += 2
elif myarg == 'limittoou':
orgUnitPath = __main__.getOrgUnitItem(sys.argv[i+1])
orgUnitPath = gam.getOrgUnitItem(sys.argv[i+1])
i += 2
elif myarg == 'todrive':
todrive = True
@@ -366,7 +366,7 @@ def doPrintCrosActivity():
endDate = _getFilterDate(sys.argv[i+1])
i += 2
elif myarg == 'listlimit':
listLimit = __main__.getInteger(sys.argv[i+1], myarg, minVal=0)
listLimit = gam.getInteger(sys.argv[i+1], myarg, minVal=0)
i += 2
elif myarg == 'delimiter':
delimiter = sys.argv[i+1]
@@ -393,7 +393,7 @@ def doPrintCrosActivity():
display.add_titles_to_csv_file(titles_to_add, titles)
fields = f'nextPageToken,chromeosdevices({",".join(fieldsList)})'
for query in queries:
__main__.printGettingAllItems('CrOS Devices', query)
gam.printGettingAllItems('CrOS Devices', query)
page_message = gapi.got_total_items_msg('CrOS Devices', '...\n')
all_cros = gapi.get_all_pages(cd.chromeosdevices(), 'list',
'chromeosdevices',
@@ -479,7 +479,7 @@ def doPrintCrosDevices():
elif myarg in CROS_SYSTEM_RAM_FREE_REPORTS_ARGUMENTS:
selectedLists['systemRamFreeReports'] = True
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
todrive = False
fieldsList = []
fieldsTitles = {}
@@ -497,10 +497,10 @@ def doPrintCrosDevices():
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg in ['query', 'queries']:
queries = __main__.getQueries(myarg, sys.argv[i+1])
queries = gam.getQueries(myarg, sys.argv[i+1])
i += 2
elif myarg == 'limittoou':
orgUnitPath = __main__.getOrgUnitItem(sys.argv[i+1])
orgUnitPath = gam.getOrgUnitItem(sys.argv[i+1])
i += 2
elif myarg == 'todrive':
todrive = True
@@ -510,7 +510,7 @@ def doPrintCrosDevices():
selectedLists = {}
i += 1
elif myarg == 'listlimit':
listLimit = __main__.getInteger(sys.argv[i+1], myarg, minVal=0)
listLimit = gam.getInteger(sys.argv[i+1], myarg, minVal=0)
i += 2
elif myarg in CROS_START_ARGUMENTS:
startDate = _getFilterDate(sys.argv[i+1])
@@ -589,7 +589,7 @@ def doPrintCrosDevices():
else:
fields = None
for query in queries:
__main__.printGettingAllItems('CrOS Devices', query)
gam.printGettingAllItems('CrOS Devices', query)
page_message = gapi.got_total_items_msg('CrOS Devices', '...\n')
all_cros = gapi.get_all_pages(cd.chromeosdevices(), 'list',
'chromeosdevices',
@@ -742,9 +742,9 @@ def doPrintCrosDevices():
def getCrOSDeviceEntity(i, cd):
myarg = sys.argv[i].lower()
if myarg == 'cros_sn':
return i+2, __main__.getUsersToModify('cros_sn', sys.argv[i+1])
return i+2, gam.getUsersToModify('cros_sn', sys.argv[i+1])
if myarg == 'query':
return i+2, __main__.getUsersToModify('crosquery', sys.argv[i+1])
return i+2, gam.getUsersToModify('crosquery', sys.argv[i+1])
if myarg[:6] == 'query:':
query = sys.argv[i][6:]
if query[:12].lower() == 'orgunitpath:':

View File

@@ -1,14 +1,14 @@
import datetime
from var import *
import controlflow
import gapi
import gapi.directory
import gapi.reports
from gam.var import *
from gam import controlflow
from gam import gapi
from gam.gapi import directory as gapi_directory
from gam.gapi import reports as gapi_reports
def doGetCustomerInfo():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
customer_info = gapi.call(cd.customers(), 'get',
customerKey=GC_Values[GC_CUSTOMER_ID])
print(f'Customer ID: {customer_info["id"]}')
@@ -59,7 +59,7 @@ def doGetCustomerInfo():
customerId = GC_Values[GC_CUSTOMER_ID]
if customerId == MY_CUSTOMER:
customerId = None
rep = gapi.reports.buildGAPIObject()
rep = gapi_reports.buildGAPIObject()
usage = None
throw_reasons = [gapi.errors.ErrorReason.INVALID]
while True:
@@ -71,7 +71,7 @@ def doGetCustomerInfo():
parameters=parameters)
break
except gapi.errors.GapiInvalidError as e:
tryDate = gapi.reports._adjust_date(str(e))
tryDate = gapi_reports._adjust_date(str(e))
if not usage:
print('No user count data available.')
return
@@ -84,7 +84,7 @@ def doGetCustomerInfo():
def doUpdateCustomer():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
body = {}
i = 3
while i < len(sys.argv):

View File

@@ -1,17 +1,18 @@
import sys
import uuid
import __main__
from var import *
import controlflow
import display
import gapi.directory
import utils
import gam
from gam.var import *
from gam import controlflow
from gam import display
from gam import gapi
from gam.gapi import directory as gapi_directory
from gam import utils
def printBuildings():
to_drive = False
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
titles = []
csvRows = []
fieldsList = ['buildingId']
@@ -65,7 +66,7 @@ def printBuildings():
def printResourceCalendars():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
todrive = False
fieldsList = []
fieldsTitles = {}
@@ -108,7 +109,7 @@ def printResourceCalendars():
if 'buildingId' in fieldsList:
display.add_field_to_csv_file('buildingName', {'buildingName': [
'buildingName', ]}, fieldsList, fieldsTitles, titles)
__main__.printGettingAllItems('Resource Calendars', None)
gam.printGettingAllItems('Resource Calendars', None)
page_message = gapi.got_total_items_first_last_msg('Resource Calendars')
resources = gapi.get_all_pages(cd.resources().calendars(), 'list',
'items', page_message=page_message,
@@ -162,7 +163,7 @@ RESCAL_ARGUMENT_TO_PROPERTY_MAP = {
def printFeatures():
to_drive = False
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
titles = []
csvRows = []
fieldsList = ['name']
@@ -240,7 +241,7 @@ def _getBuildingAttributes(args, body={}):
def createBuilding():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
body = {'floorNames': ['1'],
'buildingId': str(uuid.uuid4()),
'buildingName': sys.argv[3]}
@@ -318,7 +319,7 @@ def getBuildingNameById(cd, buildingId):
def updateBuilding():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
buildingId = getBuildingByNameOrId(cd, sys.argv[3])
body = _getBuildingAttributes(sys.argv[4:])
print(f'Updating building {buildingId}...')
@@ -328,7 +329,7 @@ def updateBuilding():
def getBuildingInfo():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
buildingId = getBuildingByNameOrId(cd, sys.argv[3])
building = gapi.call(cd.resources().buildings(), 'get',
customer=GC_Values[GC_CUSTOMER_ID],
@@ -343,7 +344,7 @@ def getBuildingInfo():
def deleteBuilding():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
buildingId = getBuildingByNameOrId(cd, sys.argv[3])
print(f'Deleting building {buildingId}...')
gapi.call(cd.resources().buildings(), 'delete',
@@ -364,7 +365,7 @@ def _getFeatureAttributes(args, body={}):
def createFeature():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
body = _getFeatureAttributes(sys.argv[3:])
print(f'Creating feature {body["name"]}...')
gapi.call(cd.resources().features(), 'insert',
@@ -375,7 +376,7 @@ def updateFeature():
# update does not work for name and name is only field to be updated
# if additional writable fields are added to feature in the future
# we'll add support for update as well as rename
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
oldName = sys.argv[3]
body = {'newName': sys.argv[5:]}
print(f'Updating feature {oldName}...')
@@ -385,7 +386,7 @@ def updateFeature():
def deleteFeature():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
featureKey = sys.argv[3]
print(f'Deleting feature {featureKey}...')
gapi.call(cd.resources().features(), 'delete',
@@ -410,7 +411,7 @@ def _getResourceCalendarAttributes(cd, args, body={}):
cd, args[i+1], minLen=0)
i += 2
elif myarg in ['capacity']:
body['capacity'] = __main__.getInteger(args[i+1], myarg, minVal=0)
body['capacity'] = gam.getInteger(args[i+1], myarg, minVal=0)
i += 2
elif myarg in ['feature', 'features']:
features = args[i+1].split(',')
@@ -440,7 +441,7 @@ def _getResourceCalendarAttributes(cd, args, body={}):
def createResourceCalendar():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
body = {'resourceId': sys.argv[3],
'resourceName': sys.argv[4]}
body = _getResourceCalendarAttributes(cd, sys.argv[5:], body)
@@ -450,7 +451,7 @@ def createResourceCalendar():
def updateResourceCalendar():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
resId = sys.argv[3]
body = _getResourceCalendarAttributes(cd, sys.argv[4:])
# Use patch since it seems to work better.
@@ -462,7 +463,7 @@ def updateResourceCalendar():
def getResourceCalendarInfo():
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
resId = sys.argv[3]
resource = gapi.call(cd.resources().calendars(), 'get',
customer=GC_Values[GC_CUSTOMER_ID],
@@ -481,7 +482,7 @@ def getResourceCalendarInfo():
def deleteResourceCalendar():
resId = sys.argv[3]
cd = gapi.directory.buildGAPIObject()
cd = gapi_directory.buildGAPIObject()
print(f'Deleting resource calendar {resId}')
gapi.call(cd.resources().calendars(), 'delete',
customer=GC_Values[GC_CUSTOMER_ID], calendarResourceId=resId)

View File

@@ -3,9 +3,9 @@
from enum import Enum
import json
import controlflow
import display # TODO: Change to relative import when gam is setup as a package
from var import UTF8
from gam import controlflow
from gam import display
from gam.var import UTF8
class GapiAbortedError(Exception):
@@ -110,12 +110,15 @@ class ErrorReason(Enum):
BAD_REQUEST = 'badRequest'
CONDITION_NOT_MET = 'conditionNotMet'
CYCLIC_MEMBERSHIPS_NOT_ALLOWED = 'cyclicMembershipsNotAllowed'
DAILY_LIMIT_EXCEEDED = 'dailyLimitExceeded'
DOMAIN_CANNOT_USE_APIS = 'domainCannotUseApis'
DOMAIN_NOT_FOUND = 'domainNotFound'
DUPLICATE = 'duplicate'
FAILED_PRECONDITION = 'failedPrecondition'
FORBIDDEN = 'forbidden'
FOUR_O_NINE = '409'
FOUR_O_THREE = '403'
FOUR_TWO_NINE = '429'
GATEWAY_TIMEOUT = 'gatewayTimeout'
GROUP_NOT_FOUND = 'groupNotFound'
INTERNAL_ERROR = 'internalError'
@@ -134,8 +137,6 @@ class ErrorReason(Enum):
SYSTEM_ERROR = 'systemError'
USER_NOT_FOUND = 'userNotFound'
USER_RATE_LIMIT_EXCEEDED = 'userRateLimitExceeded'
FOUR_TWO_NINE = '429'
DAILY_LIMIT_EXCEEDED = 'dailyLimitExceeded'
def __str__(self):
return str(self.value)

View File

@@ -6,7 +6,7 @@ import unittest
from unittest.mock import patch
import googleapiclient.errors
from gapi import errors
from gam.gapi import errors
def create_simple_http_error(status, reason, message):

View File

@@ -1,16 +1,20 @@
import calendar
import datetime
import re
import sys
import __main__
from var import *
import controlflow
import display
import gapi
import utils
from dateutil.relativedelta import relativedelta
import gam
from gam.var import *
from gam import controlflow
from gam import display
from gam import gapi
from gam import utils
def buildGAPIObject():
return __main__.buildGAPIObject('reports')
return gam.buildGAPIObject('reports')
REPORT_CHOICE_MAP = {
@@ -29,16 +33,238 @@ REPORT_CHOICE_MAP = {
'logins': 'login',
'oauthtoken': 'token',
'tokens': 'token',
'usage': 'usage',
'usageparameters': 'usageparameters',
'users': 'user',
'useraccounts': 'user_accounts',
}
def showUsageParameters():
rep = buildGAPIObject()
throw_reasons = [gapi.errors.ErrorReason.INVALID,
gapi.errors.ErrorReason.BAD_REQUEST]
todrive = False
if len(sys.argv) == 3:
controlflow.missing_argument_exit(
'user or customer', 'report usageparameters')
report = sys.argv[3].lower()
titles = ['parameter']
if report == 'customer':
endpoint = rep.customerUsageReports()
kwargs = {}
elif report == 'user':
endpoint = rep.userUsageReport()
kwargs = {'userKey': gam._getValueFromOAuth('email')}
else:
controlflow.expected_argument_exit(
'usageparameters', ['user', 'customer'], report)
customerId = GC_Values[GC_CUSTOMER_ID]
if customerId == MY_CUSTOMER:
customerId = None
tryDate = datetime.date.today().strftime(YYYYMMDD_FORMAT)
partial_apps = []
all_parameters = []
one_day = datetime.timedelta(days=1)
i = 4
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg == 'todrive':
todrive = True
i += 1
else:
controlflow.invalid_argument_exit(sys.argv[i], "gam report usageparameters")
while True:
try:
response = gapi.call(endpoint, 'get',
throw_reasons=throw_reasons,
date=tryDate,
customerId=customerId,
**kwargs)
partial_on_thisday = []
for warning in response.get('warnings', []):
for data in warning.get('data', []):
if data.get('key') == 'application':
partial_on_thisday.append(data['value'])
if partial_apps:
partial_apps = [app for app in partial_apps if app in partial_on_thisday]
else:
partial_apps = partial_on_thisday
for parameter in response['usageReports'][0]['parameters']:
name = parameter.get('name')
if name and name not in all_parameters:
all_parameters.append(name)
if not partial_apps:
break
tryDate = (utils.get_yyyymmdd(tryDate, returnDateTime=True) - \
one_day).strftime(YYYYMMDD_FORMAT)
except gapi.errors.GapiInvalidError as e:
tryDate = _adjust_date(str(e))
all_parameters.sort()
csvRows = []
for parameter in all_parameters:
csvRows.append({'parameter': parameter})
display.write_csv_file(
csvRows, titles, f'{report.capitalize()} Report Usage Parameters', todrive)
REPORTS_PARAMETERS_SIMPLE_TYPES = ['intValue', 'boolValue', 'datetimeValue', 'stringValue']
def showUsage():
rep = buildGAPIObject()
throw_reasons = [gapi.errors.ErrorReason.INVALID,
gapi.errors.ErrorReason.BAD_REQUEST]
todrive = False
if len(sys.argv) == 3:
controlflow.missing_argument_exit(
'user or customer', 'report usage')
report = sys.argv[3].lower()
titles = ['date']
if report == 'customer':
endpoint = rep.customerUsageReports()
kwargs = [{}]
elif report == 'user':
endpoint = rep.userUsageReport()
kwargs = [{'userKey': 'all'}]
titles.append('user')
else:
controlflow.expected_argument_exit(
'usage', ['user', 'customer'], report)
customerId = GC_Values[GC_CUSTOMER_ID]
if customerId == MY_CUSTOMER:
customerId = None
parameters = []
start_date = end_date = orgUnitId = None
skip_day_numbers = []
skip_dates = set()
one_day = datetime.timedelta(days=1)
i = 4
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
if myarg == 'startdate':
start_date = utils.get_yyyymmdd(sys.argv[i+1], returnDateTime=True)
i += 2
elif myarg == 'enddate':
end_date = utils.get_yyyymmdd(sys.argv[i+1], returnDateTime=True)
i += 2
elif myarg == 'todrive':
todrive = True
i += 1
elif myarg in ['fields', 'parameters']:
parameters = sys.argv[i+1].split(',')
i += 2
elif myarg == 'skipdates':
for skip in sys.argv[i+1].split(','):
if skip.find(':') == -1:
skip_dates.add(utils.get_yyyymmdd(skip, returnDateTime=True))
else:
skip_start, skip_end = skip.split(':', 1)
skip_start = utils.get_yyyymmdd(skip_start, returnDateTime=True)
skip_end = utils.get_yyyymmdd(skip_end, returnDateTime=True)
while skip_start <= skip_end:
skip_dates.add(skip_start)
skip_start += one_day
i += 2
elif myarg == 'skipdaysofweek':
skipdaynames = sys.argv[i+1].split(',')
dow = [d.lower() for d in calendar.day_abbr]
skip_day_numbers = [dow.index(d) for d in skipdaynames if d in dow]
i += 2
elif report == 'user' and myarg in ['orgunit', 'org', 'ou']:
_, orgUnitId = gam.getOrgUnitId(sys.argv[i+1])
i += 2
elif report == 'user' and myarg in usergroup_types:
users = gam.getUsersToModify(myarg, sys.argv[i+1])
kwargs = [{'userKey': user} for user in users]
i += 2
else:
controlflow.invalid_argument_exit(sys.argv[i], f'gam report usage {report}')
if parameters:
titles.extend(parameters)
parameters = ','.join(parameters)
else:
parameters = None
if not end_date:
end_date = datetime.datetime.now()
if not start_date:
start_date = end_date + relativedelta(months=-1)
if orgUnitId:
for kw in kwargs:
kw['orgUnitID'] = orgUnitId
usage_on_date = start_date
start_date = usage_on_date.strftime(YYYYMMDD_FORMAT)
usage_end_date = end_date
end_date = end_date.strftime(YYYYMMDD_FORMAT)
start_use_date = end_use_date = None
csvRows = []
while usage_on_date <= usage_end_date:
if usage_on_date.weekday() in skip_day_numbers or \
usage_on_date in skip_dates:
usage_on_date += one_day
continue
use_date = usage_on_date.strftime(YYYYMMDD_FORMAT)
usage_on_date += one_day
try:
for kwarg in kwargs:
try:
usage = gapi.get_all_pages(endpoint, 'get',
'usageReports',
throw_reasons=throw_reasons,
customerId=customerId,
date=use_date,
parameters=parameters,
**kwarg)
except gapi.errors.GapiBadRequestError:
continue
for entity in usage:
row = {'date': use_date}
if 'userEmail' in entity['entity']:
row['user'] = entity['entity']['userEmail']
for item in entity.get('parameters', []):
if 'name' not in item:
continue
name = item['name']
if name == 'cros:device_version_distribution':
for cros_ver in item['msgValue']:
v = cros_ver['version_number']
column_name = f'cros:num_devices_chrome_{v}'
if column_name not in titles:
titles.append(column_name)
row[column_name] = cros_ver['num_devices']
else:
if not name in titles:
titles.append(name)
for ptype in REPORTS_PARAMETERS_SIMPLE_TYPES:
if ptype in item:
row[name] = item[ptype]
break
else:
row[name] = ''
if not start_use_date:
start_use_date = use_date
end_use_date = use_date
csvRows.append(row)
except gapi.errors.GapiInvalidError as e:
display.print_warning(str(e))
break
if start_use_date:
report_name = f'{report.capitalize()} Usage Report - {start_use_date}:{end_use_date}'
else:
report_name = f'{report.capitalize()} Usage Report - {start_date}:{end_date} - No Data'
display.write_csv_file(
csvRows, titles, report_name, todrive)
def showReport():
rep = buildGAPIObject()
throw_reasons = [gapi.errors.ErrorReason.INVALID]
report = sys.argv[2].lower()
report = REPORT_CHOICE_MAP.get(report.replace('_', ''), report)
if report == 'usage':
showUsage()
return
if report == 'usageparameters':
showUsageParameters()
return
valid_apps = gapi.get_enum_values_minus_unspecified(
rep._rootDesc['resources']['activities']['methods']['list'][
'parameters']['applicationName']['enum'])+['customer', 'user']
@@ -60,7 +286,7 @@ def showReport():
tryDate = utils.get_yyyymmdd(sys.argv[i+1])
i += 2
elif myarg in ['orgunit', 'org', 'ou']:
_, orgUnitId = __main__.getOrgUnitId(sys.argv[i+1])
_, orgUnitId = gam.getOrgUnitId(sys.argv[i+1])
i += 2
elif myarg == 'fulldatarequired':
fullDataRequired = []
@@ -78,7 +304,7 @@ def showReport():
eventName = sys.argv[i+1]
i += 2
elif myarg == 'user':
userKey = __main__.normalizeEmailAddressOrUID(sys.argv[i+1])
userKey = gam.normalizeEmailAddressOrUID(sys.argv[i+1])
i += 2
elif myarg in ['filter', 'filters']:
filters = sys.argv[i+1]
@@ -130,7 +356,6 @@ def showReport():
sys.exit(1)
titles = ['email', 'date']
csvRows = []
ptypes = ['intValue', 'boolValue', 'datetimeValue', 'stringValue']
for user_report in usage:
if 'entity' not in user_report:
continue
@@ -142,7 +367,7 @@ def showReport():
name = item['name']
if not name in titles:
titles.append(name)
for ptype in ptypes:
for ptype in REPORTS_PARAMETERS_SIMPLE_TYPES:
if ptype in item:
row[name] = item[ptype]
break

View File

@@ -5,16 +5,15 @@ import sys
import googleapiclient
import __main__
from var import *
import controlflow
import fileutils
import gapi
import utils
import gam
from gam.var import *
from gam import fileutils
from gam import gapi
from gam import utils
def build_gapi():
return __main__.buildGAPIObject('storage')
return gam.buildGAPIObject('storage')
def get_cloud_storage_object(s, bucket, object_, local_file=None,

View File

@@ -4,24 +4,24 @@ import sys
import googleapiclient.http
import __main__
from var import *
import controlflow
import display
import fileutils
import gapi
import gapi.storage
import utils
import gam
from gam.var import *
from gam import controlflow
from gam import display
from gam import fileutils
from gam import gapi
from gam.gapi import storage as gapi_storage
from gam import utils
def buildGAPIObject():
return __main__.buildGAPIObject('vault')
return gam.buildGAPIObject('vault')
def validateCollaborators(collaboratorList, cd):
collaborators = []
for collaborator in collaboratorList.split(','):
collaborator_id = __main__.convertEmailAddressToUID(collaborator, cd)
collaborator_id = gam.convertEmailAddressToUID(collaborator, cd)
if not collaborator_id:
controlflow.system_error_exit(4, f'failed to get a UID for '
f'{collaborator}. Please make '
@@ -47,7 +47,7 @@ def createMatter():
i += 2
elif myarg in ['collaborator', 'collaborators']:
if not cd:
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
collaborators.extend(validateCollaborators(sys.argv[i+1], cd))
i += 2
else:
@@ -124,7 +124,7 @@ def createExport():
i += 2
elif searchMethod == 'ORG_UNIT':
body['query']['orgUnitInfo'] = {
'orgUnitId': __main__.getOrgUnitId(sys.argv[i+1])[1]}
'orgUnitId': gam.getOrgUnitId(sys.argv[i+1])[1]}
i += 2
elif searchMethod == 'SHARED_DRIVE':
body['query']['sharedDriveInfo'] = {
@@ -158,7 +158,7 @@ def createExport():
i += 2
elif myarg in ['excludedrafts']:
body['query']['mailOptions'] = {
'excludeDrafts': __main__.getBoolean(sys.argv[i+1], myarg)}
'excludeDrafts': gam.getBoolean(sys.argv[i+1], myarg)}
i += 2
elif myarg in ['driveversiondate']:
body['query'].setdefault('driveOptions', {})['versionDate'] = \
@@ -166,11 +166,11 @@ def createExport():
i += 2
elif myarg in ['includeshareddrives', 'includeteamdrives']:
body['query'].setdefault('driveOptions', {})[
'includeSharedDrives'] = __main__.getBoolean(sys.argv[i+1], myarg)
'includeSharedDrives'] = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
elif myarg in ['includerooms']:
body['query']['hangoutsChatOptions'] = {
'includeRooms': __main__.getBoolean(sys.argv[i+1], myarg)}
'includeRooms': gam.getBoolean(sys.argv[i+1], myarg)}
i += 2
elif myarg in ['format']:
export_format = sys.argv[i+1].upper()
@@ -179,7 +179,7 @@ def createExport():
"export format", ", ".join(allowed_formats), export_format)
i += 2
elif myarg in ['showconfidentialmodecontent']:
showConfidentialModeContent = __main__.getBoolean(sys.argv[i+1], myarg)
showConfidentialModeContent = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
elif myarg in ['region']:
allowed_regions = gapi.get_enum_values_minus_unspecified(
@@ -192,7 +192,7 @@ def createExport():
i += 2
elif myarg in ['includeaccessinfo']:
body['exportOptions'].setdefault('driveOptions', {})[
'includeAccessInfo'] = __main__.getBoolean(sys.argv[i+1], myarg)
'includeAccessInfo'] = gam.getBoolean(sys.argv[i+1], myarg)
i += 2
else:
controlflow.invalid_argument_exit(sys.argv[i], "gam create export")
@@ -277,7 +277,7 @@ def createHold():
i += 2
elif myarg in ['orgunit', 'ou']:
body['orgUnit'] = {
'orgUnitId': __main__.getOrgUnitId(sys.argv[i+1])[1]}
'orgUnitId': gam.getOrgUnitId(sys.argv[i+1])[1]}
i += 2
elif myarg in ['start', 'starttime']:
start_time = utils.get_date_zero_time_or_full_time(sys.argv[i+1])
@@ -319,11 +319,11 @@ def createHold():
body['query'][query_type]['endTime'] = end_time
if accounts:
body['accounts'] = []
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
account_type = 'group' if body['corpus'] == 'GROUPS' else 'user'
for account in accounts:
body['accounts'].append(
{'accountId': __main__.convertEmailAddressToUID(account,
{'accountId': gam.convertEmailAddressToUID(account,
cd,
account_type)}
)
@@ -370,16 +370,16 @@ def getHoldInfo():
3, 'you must specify a matter for the hold.')
results = gapi.call(v.matters().holds(), 'get',
matterId=matterId, holdId=holdId)
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
if 'accounts' in results:
account_type = 'group' if results['corpus'] == 'GROUPS' else 'user'
for i in range(0, len(results['accounts'])):
uid = f'uid:{results["accounts"][i]["accountId"]}'
acct_email = __main__.convertUIDtoEmailAddress(
acct_email = gam.convertUIDtoEmailAddress(
uid, cd, [account_type])
results['accounts'][i]['email'] = acct_email
if 'orgUnit' in results:
results['orgUnit']['orgUnitPath'] = __main__.doGetOrgInfo(
results['orgUnit']['orgUnitPath'] = gam.doGetOrgInfo(
results['orgUnit']['orgUnitId'], return_attrib='orgUnitPath')
display.print_json(results)
@@ -456,7 +456,7 @@ def updateHold():
query = sys.argv[i+1]
i += 2
elif myarg in ['orgunit', 'ou']:
body['orgUnit'] = {'orgUnitId': __main__.getOrgUnitId(sys.argv[i+1])[1]}
body['orgUnit'] = {'orgUnitId': gam.getOrgUnitId(sys.argv[i+1])[1]}
i += 2
elif myarg in ['start', 'starttime']:
start_time = utils.get_date_zero_time_or_full_time(sys.argv[i+1])
@@ -505,15 +505,15 @@ def updateHold():
gapi.call(v.matters().holds(), 'update',
matterId=matterId, holdId=holdId, body=body)
if add_accounts or del_accounts:
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
for account in add_accounts:
print(f'adding {account} to hold.')
add_body = {'accountId': __main__.convertEmailAddressToUID(account, cd)}
add_body = {'accountId': gam.convertEmailAddressToUID(account, cd)}
gapi.call(v.matters().holds().accounts(), 'create',
matterId=matterId, holdId=holdId, body=add_body)
for account in del_accounts:
print(f'removing {account} from hold.')
accountId = __main__.convertEmailAddressToUID(account, cd)
accountId = gam.convertEmailAddressToUID(account, cd)
gapi.call(v.matters().holds().accounts(), 'delete',
matterId=matterId, holdId=holdId, accountId=accountId)
@@ -543,12 +543,12 @@ def updateMatter(action=None):
i += 2
elif myarg in ['addcollaborator', 'addcollaborators']:
if not cd:
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
add_collaborators.extend(validateCollaborators(sys.argv[i+1], cd))
i += 2
elif myarg in ['removecollaborator', 'removecollaborators']:
if not cd:
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
remove_collaborators.extend(
validateCollaborators(sys.argv[i+1], cd))
i += 2
@@ -585,10 +585,10 @@ def getMatterInfo():
matterId = getMatterItem(v, sys.argv[3])
result = gapi.call(v.matters(), 'get', matterId=matterId, view='FULL')
if 'matterPermissions' in result:
cd = __main__.buildGAPIObject('directory')
cd = gam.buildGAPIObject('directory')
for i in range(0, len(result['matterPermissions'])):
uid = f'uid:{result["matterPermissions"][i]["accountId"]}'
user_email = __main__.convertUIDtoEmailAddress(uid, cd)
user_email = gam.convertUIDtoEmailAddress(uid, cd)
result['matterPermissions'][i]['email'] = user_email
display.print_json(result)
@@ -597,7 +597,7 @@ def downloadExport():
verifyFiles = True
extractFiles = True
v = buildGAPIObject()
s = gapi.storage.build_gapi()
s = gapi_storage.build_gapi()
matterId = getMatterItem(v, sys.argv[3])
exportId = convertExportNameToID(v, sys.argv[4], matterId)
targetFolder = GC_Values[GC_DRIVE_DIR]
@@ -643,7 +643,7 @@ def downloadExport():
utils.md5_matches_file(filename, expected_hash, True)
print('VERIFIED')
if extractFiles and re.search(r'\.zip$', filename):
__main__.extract_nested_zip(filename, targetFolder)
gam.extract_nested_zip(filename, targetFolder)
def printMatters():
@@ -674,7 +674,7 @@ def printMatters():
i += 2
else:
controlflow.invalid_argument_exit(myarg, "gam print matters")
__main__.printGettingAllItems('Vault Matters', None)
gam.printGettingAllItems('Vault Matters', None)
page_message = gapi.got_total_items_msg('Vault Matters', '...\n')
matters = gapi.get_all_pages(
v.matters(), 'list', 'matters', page_message=page_message, view=view,

View File

@@ -3,11 +3,11 @@
import google_auth_httplib2
import httplib2
from var import GAM_INFO
from var import GC_CA_FILE
from var import GC_TLS_MAX_VERSION
from var import GC_TLS_MIN_VERSION
from var import GC_Values
from gam.var import GAM_INFO
from gam.var import GC_CA_FILE
from gam.var import GC_TLS_MAX_VERSION
from gam.var import GC_TLS_MIN_VERSION
from gam.var import GC_Values
def create_http(cache=None,
@@ -27,13 +27,16 @@ def create_http(cache=None,
Returns:
httplib2.Http with the specified options.
"""
tls_minimum_version = override_min_tls if override_min_tls else GC_Values[GC_TLS_MIN_VERSION]
tls_maximum_version = override_max_tls if override_max_tls else GC_Values[GC_TLS_MAX_VERSION]
httpObj = httplib2.Http(ca_certs=GC_Values[GC_CA_FILE],
tls_maximum_version=tls_maximum_version,
tls_minimum_version=tls_minimum_version,
cache=cache,
timeout=timeout)
tls_minimum_version = override_min_tls if override_min_tls else GC_Values.get(
GC_TLS_MIN_VERSION)
tls_maximum_version = override_max_tls if override_max_tls else GC_Values.get(
GC_TLS_MAX_VERSION)
httpObj = httplib2.Http(
ca_certs=GC_Values.get(GC_CA_FILE),
tls_maximum_version=tls_maximum_version,
tls_minimum_version=tls_minimum_version,
cache=cache,
timeout=timeout)
httpObj.redirect_codes = set(httpObj.redirect_codes) - {308}
return httpObj
@@ -68,7 +71,9 @@ def _force_user_agent(user_agent):
if kwargs['headers'].get('user-agent'):
if user_agent not in kwargs['headers']['user-agent']:
# Save the existing user-agent header and tack on our own.
kwargs['headers']['user-agent'] = f'{user_agent} {kwargs["headers"]["user-agent"]}'
kwargs['headers']['user-agent'] = (
f'{user_agent} '
f'{kwargs["headers"]["user-agent"]}')
else:
kwargs['headers']['user-agent'] = user_agent
else:

View File

@@ -8,7 +8,7 @@ from gam import SetGlobalVariables
import google_auth_httplib2
import httplib2
import transport
from gam import transport
class CreateHttpTest(unittest.TestCase):

View File

@@ -8,10 +8,10 @@ from html.parser import HTMLParser
import json
import dateutil.parser
import controlflow
import fileutils
import transport
from var import *
from gam import controlflow
from gam import fileutils
from gam import transport
from gam.var import *
class _DeHTMLParser(HTMLParser):

View File

@@ -6,13 +6,13 @@ import platform
import re
gam_author = 'Jay Lee <jay0lee@gmail.com>'
gam_version = '5.03'
gam_version = '5.07'
gam_license = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
GAM_URL = 'https://git.io/gam'
GAM_INFO = (f'GAM {gam_version} - {GAM_URL} / {gam_author} / '
f'Python {platform.python_version()} {sys.version_info.releaselevel} / '
f'{platform.platform()} {platform.machine()}')
f'Python {platform.python_version()} {sys.version_info.releaselevel} / '
f'{platform.platform()} {platform.machine()}')
GAM_RELEASES = 'https://github.com/jay0lee/GAM/releases'
GAM_WIKI = 'https://github.com/jay0lee/GAM/wiki'
@@ -843,6 +843,8 @@ GC_SHOW_GETTINGS = 'show_gettings'
GC_SITE_DIR = 'site_dir'
# CSV Columns GAM should show on CSV output
GC_CSV_HEADER_FILTER = 'csv_header_filter'
# CSV Columns GAM should not show on CSV output
GC_CSV_HEADER_DROP_FILTER = 'csv_header_drop_filter'
# CSV Rows GAM should filter
GC_CSV_ROW_FILTER = 'csv_row_filter'
# Minimum TLS Version required for HTTPS connections
@@ -878,6 +880,7 @@ GC_Defaults = {
GC_SHOW_GETTINGS: True,
GC_SITE_DIR: '',
GC_CSV_HEADER_FILTER: '',
GC_CSV_HEADER_DROP_FILTER: '',
GC_CSV_ROW_FILTER: '',
GC_TLS_MIN_VERSION: tls_min,
GC_TLS_MAX_VERSION: None,
@@ -925,6 +928,7 @@ GC_VAR_INFO = {
GC_SHOW_GETTINGS: {GC_VAR_TYPE: GC_TYPE_BOOLEAN},
GC_SITE_DIR: {GC_VAR_TYPE: GC_TYPE_DIRECTORY},
GC_CSV_HEADER_FILTER: {GC_VAR_TYPE: GC_TYPE_HEADERFILTER},
GC_CSV_HEADER_DROP_FILTER: {GC_VAR_TYPE: GC_TYPE_HEADERFILTER},
GC_CSV_ROW_FILTER: {GC_VAR_TYPE: GC_TYPE_ROWFILTER},
GC_TLS_MIN_VERSION: {GC_VAR_TYPE: GC_TYPE_STRING},
GC_TLS_MAX_VERSION: {GC_VAR_TYPE: GC_TYPE_STRING},

View File

@@ -1,5 +0,0 @@
import __main__
def buildGAPIObject():
return __main__.buildGAPIObject('directory')

View File

@@ -1,12 +0,0 @@
rm -rf gam
rm -rf build
rm -rf dist
rm -rf gam-$1-linux-$(arch).tar.xz
export LD_LIBRARY_PATH=/usr/local/lib
pyinstaller --clean -F --distpath=gam linux-gam.spec
cp LICENSE gam
cp whatsnew.txt gam
cp GamCommands.txt gam
tar cfJ gam-$1-linux-$(arch).tar.xz gam/

View File

@@ -1,11 +0,0 @@
rm -rf gam
rm -rf build
rm -rf dist
rm -rf gam-$1-macos.tar.xz
/Library/Frameworks/Python.framework/Versions/2.7/bin/pyinstaller --clean -F --distpath=gam macos-gam.spec
cp LICENSE gam
cp whatsnew.txt gam
cp GamCommands.txt gam
tar cfJ gam-$1-macos.tar.xz gam/

View File

@@ -1,32 +0,0 @@
# -*- mode: python -*-
import sys
sys.modules['FixTk'] = None
a = Analysis(['gam.py'],
hiddenimports=[],
hookspath=None,
excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
runtime_hooks=None)
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
a.datas += [('cloudprint-v2.json', 'cloudprint-v2.json', 'DATA')]
# dynamically determine where httplib2/cacerts.txt lives
import importlib
proot = os.path.dirname(importlib.import_module('httplib2').__file__)
a.datas += [('httplib2/cacerts.txt', os.path.join(proot, 'cacerts.txt'), 'DATA')]
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='gam',
debug=False,
strip=None,
upx=False,
console=True )

7
src/requirements-dev.txt Normal file
View File

@@ -0,0 +1,7 @@
# This file contains all requirements needed for GAM development work
# Include all build requirements
-r requirements.txt
# Dev-specific requirements
pre-commit

View File

@@ -1,10 +1,10 @@
cryptography
python-dateutil
distro; sys_platform == 'linux'
filelock
google-api-python-client>=1.7.10
google-auth>=1.11.2
google-auth-httplib2
google-auth-oauthlib>=0.4.1
google-auth>=1.11.2
httplib2>=0.17.0
passlib>=1.7.2; sys_platform == 'win32'
python-dateutil

View File

@@ -5,7 +5,7 @@ if [[ "$TRAVIS_JOB_NAME" == *"Testing" ]]; then
echo "running tests with this version"
else
export whereibelong=$(pwd)
echo "We are running on Ubuntu $TRAVIS_DSIT $PLATFORM"
echo "We are running on Ubuntu $TRAVIS_DIST $PLATFORM"
export LD_LIBRARY_PATH=~/ssl/lib:~/python/lib
cpucount=$(nproc --all)
echo "This device has $cpucount CPUs for compiling..."
@@ -104,10 +104,11 @@ else
$pip install staticx
fi
$pip install --upgrade https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
cd $whereibelong
fi
echo "Upgrading pip packages..."
$pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 $pip install -U
$pip install --upgrade -r src/requirements.txt
$pip install --upgrade https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz

View File

@@ -1,33 +1,36 @@
cd src
if [[ "$TRAVIS_JOB_NAME" == *"Testing" ]]; then
export gam="$python gam.py"
export gam="$python -m gam"
export gampath=$(readlink -e .)
else
$python -OO -m PyInstaller --clean --noupx --strip -F --distpath=gam $GAMOS-gam.spec
export gam="gam/gam"
export gampath=$(readlink -e gam)
export gampath="dist/gam"
rm -rf $gampath
mkdir -p $gampath
export gampath=$(readlink -e $gampath)
$python -OO -m PyInstaller --clean --noupx --strip -F --distpath $gampath gam.spec
export gam="${gampath}/gam"
export GAMVERSION=`$gam version simple`
cp LICENSE $gampath
cp whatsnew.txt $gampath
cp GamCommands.txt $gampath
this_glibc_ver=$(ldd --version | awk '/ldd/{print $NF}')
GAM_ARCHIVE=gam-$GAMVERSION-$GAMOS-$PLATFORM-glibc$this_glibc_ver.tar.xz
rm $gampath/lastupdatecheck.txt
tar cfJ $GAM_ARCHIVE gam/
# tar will cd to dist and tar up gam/
tar -C dist/ --create --file $GAM_ARCHIVE --xz gam
echo "PyInstaller GAM info:"
du -h gam/gam
du -h $gam
time $gam version extended
if ([ "${TRAVIS_DIST}" == "trusty" ] || [ "${TRAVIS_DIST}" == "xenial" ]) && [ "${PLATFORM}" == "x86_64" ]; then
if [ "${TRAVIS_DIST}" == "xenial" ] && [ "${PLATFORM}" == "x86_64" ]; then
GAM_LEGACY_ARCHIVE=gam-${GAMVERSION}-${GAMOS}-${PLATFORM}-legacy.tar.xz
$python -OO -m staticx -l /lib/x86_64-linux-gnu/libresolv.so.2 -l /lib/x86_64-linux-gnu/libnss_dns.so.2 gam/gam gam/gam-staticx
strip gam/gam-staticx
rm gam/gam
mv gam/gam-staticx gam/gam
chmod 755 gam/gam
tar cvfJ $GAM_LEGACY_ARCHIVE gam/
$python -OO -m staticx -l /lib/x86_64-linux-gnu/libresolv.so.2 -l /lib/x86_64-linux-gnu/libnss_dns.so.2 $gam $gam-staticx
strip $gam-staticx
rm $gampath/gam
mv $gam-staticx $gam
chmod 755 $gam
rm $gampath/lastupdatecheck.txt
tar -C dist/ --create --file $GAM_LEGACY_ARCHIVE --xz gam
echo "Legacy StaticX GAM info:"
du -h gam/gam
du -h $gam
time $gam version extended
fi
echo "GAM packages:"

View File

@@ -9,7 +9,7 @@ echo "This device has $cpucount CPUs for compiling..."
#brew upgrade
# prefer standard GNU tools like date over MacOS defaults
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$(brew --prefix)/opt/gnu-tar/libexec/gnubin:$PATH"
cd ~

View File

@@ -1,15 +1,16 @@
cd src
echo "MacOS Version Info According to Python:"
python -c "import platform; print(platform.mac_ver())"
$python -OO -m PyInstaller --clean --noupx --strip -F --distpath=gam $GAMOS-gam.spec
export gam="gam/gam"
export gampath=gam
export gampath=dist/gam
rm -rf $gampath
$python -OO -m PyInstaller --clean --noupx --strip -F --distpath $gampath gam.spec
export gam="$gampath/gam"
$gam version extended
export GAMVERSION=`gam/gam version simple`
cp LICENSE gam
cp whatsnew.txt gam
cp GamCommands.txt gam
export GAMVERSION=`$gam version simple`
cp LICENSE $gampath
cp GamCommands.txt $gampath
MACOSVERSION=$(defaults read loginwindow SystemVersionStampAsString)
GAM_ARCHIVE=gam-$GAMVERSION-$GAMOS-$PLATFORM-MacOS$MACOSVERSION.tar.xz
rm gam/lastupdatecheck.txt
tar cfJ $GAM_ARCHIVE gam/
rm $gampath/lastupdatecheck.txt
# tar will cd to dist/ and tar up gam/
tar -C dist/ --create --file $GAM_ARCHIVE --xz gam

View File

@@ -6,10 +6,7 @@ cfg = json.load(sys.stdin)
cfg['client_secret'] = os.getenv('client_secret')
jid = os.getenv('jid')
cfg['refresh_token'] = os.getenv('refresh_%s' % jid)
name = os.getenv('TRAVIS_JOB_NAME')
if name.endswith('Testing'):
out_file = 'oauth2.txt'
else:
out_file = 'gam/oauth2.txt'
gampath = os.getenv('gampath')
out_file = os.path.join(gampath, 'oauth2.txt')
with open(out_file, 'w') as f:
json.dump(cfg, f)

View File

@@ -1,20 +1,25 @@
cd src
echo "compiling GAM with pyinstaller..."
pyinstaller --clean --noupx -F --distpath=gam $GAMOS-gam.spec
export gam="gam/gam"
export gampath=$(readlink -e gam)
export gampath="dist/gam"
rm -rf $gampath
mkdir -p $gampath
export gampath=$(readlink -e $gampath)
pyinstaller --clean --noupx -F --distpath $gampath gam.spec
export gam="${gampath}/gam"
echo "running compiled GAM..."
$gam version
export GAMVERSION=`$gam version simple`
rm gam/lastupdatecheck.txt
cp LICENSE gam
cp GamCommands.txt gam
cp whatsnew.txt gam
cp gam-setup.bat gam
rm $gampath/lastupdatecheck.txt
cp LICENSE $gampath
cp GamCommands.txt $gampath
cp gam-setup.bat $gampath
GAM_ARCHIVE=gam-$GAMVERSION-$GAMOS-$PLATFORM.zip
/c/Program\ Files/7-Zip/7z.exe a -tzip $GAM_ARCHIVE gam -xr!.svn
mkdir gam-64
cp -rf gam/* gam-64/;
/c/Program\ Files/7-Zip/7z.exe a -tzip $GAM_ARCHIVE $gampath -xr!.svn
echo "Running WIX candle $WIX_BITS..."
/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/candle.exe -arch $WIX_BITS gam.wxs
echo "Done with WIX candle..."
echo "Running WIX light..."
/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/light.exe -ext /c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/WixUIExtension.dll gam.wixobj -o gam-$GAMVERSION-$GAMOS-$PLATFORM.msi || true;
echo "Done with WIX light..."
rm *.wixpdb

View File

@@ -1,681 +0,0 @@
This file has been deprecated. For the latest features see https://git.io/gam-releases notes
GAM 4.65
- Manage email delivery settings for group members
- Add operatingSystemType to user posix config (Roman)
- Handle missing language setting (jalmeroth)
- handle mixed case aliases (Ross)
- contentmanager and fileorganizer roles in Team Drive (Ross)
- various other fixes and optimizations (Jay and Ross)
GAM 4.61
- New Gmail delegation API
- Remove "admin" command from user create/update to avoid accidental super admins. Still possible to give super admin rights via "gam create admin" command. (Ross)
- Vault export fixes by Ross
- minor fixes and improvements by Ross and Jay
GAM 4.60
- Google Vault Export API gam support
- Ross - add textcolor and backgroundcolor options for Gmail labels
- Ross - add owneremail option to print courses
- GAM 4.50 had no bugs at all, nothing to fix.
- Just kidding, lots of bug fixes and code cleanup. Thanks Ross.
GAM 4.50
- many cleanups, bugfixes and improvements by Ross and ejochman
- multiple queries and more options for Chrome OS by Ross
- per-API batch calls to solve global batch deprecation
- handle new G Suite Enterprise for EDU and Cloud Identity SKUs
- Library updates
GAM 4.40
- Team Drive Admin "asadmin" to give admins special access.
- Manage Buildings, Features and Resource Calendars.
- Download log files for kiosk Chrome devices.
- TPM info and vulnerability status for Chrome devices.
- New Google library for service account auth.
- (Ross) increase cell count for "todrive" to 2M.
- (Ross) improved course id handling.
- (Ross) numerous cleanups and bug fixes
GAM 4.32
- Fixes and improvements by Ross
- gam print courses now supports limiting results based on course state
- handle issues adding members to a group who were in a pending status before
- Data transfer commands now support transferring user Calendar events.
GAM 4.31
- Update course owners in Classroom
- support for time deltas like -4h for some commands (danielx)
- Set location, ssh keys and posix accounts details on user create/update
- support batch move of Chrome OS devices for better performance
- Huge amount of cleanup / performance improvements by Ross
GAM 4.30
- Google Vault Matters and Hold API support
- Ross - "gam update group" now uses batch for better performance
- "gam update project" enables new APIs for your project
- Include root level OrgUnit in OrgUnit commands
- Bulk move Chrome devices between OrgUnits
- Usual fixes / cleanups / improvements by Ross and Jay
GAM 4.22
- Validate client id and secret from user input (reduces user errors on create project)
- Ross - optimize "gam print printjobs"
- Ross- countsonly option for gam print courses
GAM 4.21
- Drive v3 fixes/updates by Ross
- "gam print crosactivty" command outputs active users and times
- SMime and calendar ACL fixes by Ross
- standardized cros info/print functionality by Ross
GAM 4.2
- Create, Update, Delete and List Team Drives
- Start moving to Drive API v3
- Disable GAM cache by default to prevent errors (Ross)
- Use service accounts for all Calendar, Drive and Gmail operations to reduce scopes
- Fix "Unknown" errors due to a scope issue (may require "gam oauth revoke" and re-authentication)
- "gam info domain" shows basic user / license sums again
- "gam report customer" now shows more browser usage stats
- Fix project creation ToS error (Ross)
GAM 4.12
- Realtime 2SV user status in gam info user and gam print users. Thanks hajdbo!
- Reseller API support. Create and manage customers and subscriptions.
- Delete or modify Gmail threads. Improved message delete/modify performance.
- Support for the new G Suite Enterprise license
- Manage S/MIME certificates for G Suite Enterprise users
- Many fixes and improvements by Ross.
GAM 4.11
- Allow newlines in calendar event descriptions (Ross)
- All HTTP requests should now honor SSL verify setting, debug, etc
GAM 4.1
- Fix "gam create project"
- project create cleanups by Ross
- Various fixes by Ross
- Improved batch command performance. Some commands will see 2-3x speedups.
- Faster "gam info user" commands via batch license retrieval
GAM 4.03
- Minor fixes by Jay and Ross. Mostly to new install process.
GAM 4.02
- "gam create project" command simplifies creation of client_secrets.json and oauth2service.json project files.
- Automated wizard simplifies GAM setup on Linux and MacOS (coming soon to Windows MSI).
- "gam calendar <email> deleteevent" deletes events by ID or query
GAM 3.8
- Old GData APIs removed from GAM. Admin Settings and Email Audit commands are no longer included, keep a copy of GAM 3.72 around if you use them. All Email Settings commands now use new Gmail API.
- Updated httplib2, google-api-client, uritemplate libraries
- New update check code utilizes GitHub API to check for latest releases.
- Many fixes and improvements by Ross
GAM 3.72
- Chrome OS device actions, disable, re-enable and deprovision devices.
- (beta) MSI Windows build
- (beta) binary Linux and MacOS builds
- Numerous fixes and updates by Ross
GAM 3.71
- Fix update first / last name.
- upgrade GAM versions of oauth2client, googleapiclient, RSA and six
- Improved UTF-8 support for CSV commands (Ross)
- Authorization flow improvements by Ross
- Other minor cleanups and fixes
GAM 3.7
- Classroom Guardians API. Invite, list and delete guardians for a student.
- Includes number of improvements from Ross in 3.66 (see below)
To use this version, you must update the list of authorized scopes for your Gam OAuth2 Client and Service Account.
Go here: https://github.com/jay0lee/GAM/wiki/CreatingClientSecretsFile
Log on to the admin console as in steps 6.ii.c, d, e.
In the list of Authorized API clients, locate your Gam OAuth2 Client, copy the Client ID and then remove the entry.
Paste the Client ID into the Client name box as in step 6.ii.f, then do steps 6.ii.g and 6.ii.h.
You'll notice that the API Scopes - OAuth2 list has additional entries, these are what is required in Gam 3.7.
Skip down to step 6.iii.
In the list of Authorized API clients, locate your Gam Service Account, copy the Client ID and then remove the entry.
Paste the Client ID into the Client name box as in step 6.iii.c, then do steps 6.iii.d and 6.iii.e.
You'll notice that the API Scopes - Service Account list has additional entries, these are what is required in Gam 3.7.
GAM 3.66
See GamCommands.txt for a complete syntax description.
Added arguments to gam info group to suppress aliases listing and include groups of which this group is a member.
gam info group <Group> ... [noaliases] [groups]
Added argument to gam print cros to limit number of activeTimeRanges and recentUsers entries
gam print cros ... [listlimit <Number>]
Added argument to gam <UserTypeEntity> signature and gam <UserTypeEntity> vacation to allow specification of file character set so that extended characters can be read.
Credit to Steve Main for suggesting the following enhancement.
Added argument to gam <UserTypeEntity> signature and gam <UserTypeEntity> vacation to allow pattern substitution in the signature and vacation message.
gam <UserTypeEntity> signature <String>|(file <FileName> [charset <Charset>]) (replace <Tag> <String>)*
gam <UserTypeEntity> vacation <TrueValues> subject <String> (message <String>)|(file <FileName> [charset <CharSet>]) (replace <Tag> <String>)*
[contactsonly] [domainonly] [startdate <Date>] [enddate <Date>]
Every instance of {<Tag>} in the signature/message will be replaced by <String>. Instances of the form {RT}...{Text}...{/RT} will be eliminated
if there was no <Tag> specified that matches Text or if a <Tag> matching Text was specified but the matching <String> is empty.
This is especially useful with CSV files.
gam csv Users.csv gam user "~User" signature file SignatureTemplate.txt replace "#User#" "~User" replace "#Title#" "~Title"
Added argument to gam <UserTypeEntity> show signature to format the signature.
gam <UserTypeEntity> show signature [format]
Added argument to gam add/update calendar to allow specification of event notifications
gam <UserTypeEntity> add/update calendar <Calendar> notification email|sms eventcreation|eventchange|eventcancellation|eventresponce|agenda
Added option to reminder and notification arguments of update calendar to allowing clearing of reminders/notifications.
gam <UserTypeEntity> update calendar <Calendar> [reminder clear] [notification clear]
Added arguments to gam print group-members to allow selecting subsets of groups.
Added argument to gam print group-members to add member full name to output,
Added argument to gam print group-members to allow output field selection.
gam print group-members [todrive] ([domain <DomainName>] [member <UserItem>])|[group <GroupItem>] [membernames] [fields <MembersFieldNameList>]
MembersFieldNameList is a comma separated list of field names: email | group | id | name | role | type
Added argument to gam info user to specify SKUs for which license information is desired.
gam info user [<UserItem>] ... [skus <SKUIDList>]
Added argument to gam print printjobs and gam printjob <PrinterID> fetch to allow specifying the maximum number of print jobs to retrieve.
gam printjob <PrinterID> fetch ... [limit <Number>]
gam print printjobs ... [limit <Number>]
limit <Number> specifies the maximum number of print jobs to retrieve; defaults to 25, set limit to 0 to retrieve all print jobs.
Credit to Seth Stein for the following enhancements.
Added argument to gam <UserTypeEntity> get drivefile to allow downloading a specific revision of a drive file.
gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(query <Query>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>]
Added command to show drive file revisions.
gam <UserTypeEntity> show filerevisions <DriveFileID>
Added argument to gam print adminroles to allow uploading to Google Drive.
gam print adminroles [todrive]
Added group, groups, mobile arguments to gam report.
gam report admin|calendar|calendars|drive|docs|doc|groups|group|logins|login|mobile|tokens|token ...
Added command to show user Google+ profile.
gam <UserTypeEntity> show gplusprofile [todrive]
To enable this command, visit: https://github.com/jay0lee/GAM/wiki/CreatingClientSecretsFile
In step 3.v, enable the Google+ API
In step 6.iii.d, add https://www.googleapis.com/auth/plus.me to the API scopes - Service Account list, then remove and re-add the authorization.
Added argument to gam <UserTypeEntity> show labels to allow seeing message counts for each label.
gam <UserTypeEntity> show labels|label [onlyuser] [showcounts]
Added argument to gam <UserTypeEntity> show fileinfo to allow field selection.
gam <UserTypeEntity> show fileinfo <DriveFileID> [allfields|<DriveFieldName>*]
Added argument to gam update group to allow removing members by role.
gam update group <Group> clear [members] [managers] [owners]
If no option follows clear, all members will removed.
Changed gam print admins to include 'id:' in OrgUnitID column as with other gam print commands.
Fixed GAM to handle both future date error messages in gam report
Fixed gam <UserTypeEntity> show delegates to handle Unicode characters in delagator name.
Fixed gam <UserTypeEntity> get drivefile to properly handle file extension.
Fixed gam create alias <Name> target <Group>.
2016/07/29
Added command to empty drive drive trash.
gam <UserTypeEntity> empty drivetrash
Added alternative command to add delegates and command to print delegates.
gam <UserTypeEntity> add delegate|delegates <UserEntity>
gam <UserTypeEntity> print delegates [todrive]
Improved Gmail filter processing.
gam <UserTypeEntity> [add] filter [from <EmailAddress>] [to <EmailAddress>] [subject <String>] [haswords|query <List>] [nowords|negatedquery <List>] [musthaveattachment|hasattachment] [excludechats] [size larger|smaller <ByteCount>]
[label <LabelID>] [important|notimportant] [star] [trash] [markread] [archive] [neverspam] [forward <EmailAddress>]
gam <UserTypeEntity> delete filters <FilterIDEntity>
gam <UserTypeEntity> show filters
gam <UserTypeEntity> info filters <FilterIDEntity>
gam <UserTypeEntity> print filters [todrive]
Added commands to process Gmail forwarding addresses.
gam <UserTypeEntity> add forwardingaddress|forwardingaddresses <EmailAddressEntity>
gam <UserTypeEntity> delete forwardingaddress|forwardingaddresses <EmailAddressEntity>
gam <UserTypeEntity> show forwardingaddress|forwardingaddresses
gam <UserTypeEntity> info forwardingaddress|forwardingaddresses <EmailAddressEntity>
gam <UserTypeEntity> print forwardingaddress|forwardingaddresses [todrive]
Improved Gmail forward processing.
gam <UserTypeEntity> forward <FalseValues>
gam <UserTypeEntity> forward <TrueValues> keep|leaveininbox|archive|delete|trash|markread <EmailAddress>
gam <UserTypeEntity> show forward
gam <UserTypeEntity> print forward [todrive]
Improved Gmail sendas processing.
gam <UserTypeEntity> [add] sendas <EmailAddress> <Name> [replyto <EmailAddress>] [default] [treatasalias <Boolean>] [signature|sig <String>|(file <FileName> [charset <CharSet>]) (replace <REPattern> <String>)*]
gam <UserTypeEntity> update sendas <EmailAddress> [name <Name>] [replyto <EmailAddress>] [default] [treatasalias <Boolean>] [signature|sig <String>|(file <FileName> [charset <CharSet>]) (replace <REPattern> <String>)*]
gam <UserTypeEntity> delete sendas <EmailAddressEntity>
gam <UserTypeEntity> show sendas [format]
gam <UserTypeEntity> info sendas <EmailAddressEntity> [format]
gam <UserTypeEntity> print sendas [todrive]
Improved Gmail signature processing.
gam <UserTypeEntity> signature|sig <String>|(file <FileName> [charset <Charset>]) (replace <Tag> <String>)* [name <String>] [replyto <EmailAddress>]
gam <UserTypeEntity> show signature|sig [format]
Use Gmail API for POP/IMAP/Vacation processing.
gam <UserTypeEntity> imap|imap4 <Boolean> [noautoexpunge] [expungebehavior archive|deleteforever|trash] [maxfoldersize 0|1000|2000|5000|10000]
gam <UserTypeEntity> pop|pop3 <Boolean> [for allmail|newmail|mailfromnowon|fromnowown] [action keep|leaveininbox|archive|delete|trash|markread]
gam <UserTypeEntity> vacation <FalseValues>
gam <UserTypeEntity> vacation <TrueValues> subject <String> (message <String>)|(file <FileName> [charset <CharSet>]) (replace <Tag> <String>)* [html]
[contactsonly] [domainonly] [startdate <Date>] [enddate <Date>]
gam <UserTypeEntity> show vacation [format]
Added command toGet information about a specific calendar.
gam <UserTypeEntity> info calendar <EmailAddress>
Added command to print calendars to CSV file, dropped all arguments from gam show calendars.
gam <UserTypeEntity> print calendars [todrive]
gam <UserTypeEntity> show calendars
Added command to print Gmail Profiles to CSV file, dropped all arguments from gam show gmailprofile.
gam <UserTypeEntity> print gmailprofile [todrive]
gam <UserTypeEntity> show gmailprofile
Added command to print Gplus Profiles to CSV file, dropped all arguments from gam show gplusprofile.
gam <UserTypeEntity> print gplusprofile [todrive]
gam <UserTypeEntity> show gplusprofile
Added command to print user schemas to CSV file, renamed command to display formatted user schemas to gam show schemas.
gam print schemas [todrive]
gam show schemas
Added command to print user access tokens to CSV file.
gam <UserTypeEntity> print tokens|token|3lo|oauth [todrive]
Added arguments to gam info cros to allow specification of desired output fields.
gam info cros <CrosDeviceEntity> [nolists] [listlimit <Number>]
[basic|full|allfields] <CrOSFieldName>* [fields <CrOSFieldNameList>]
Added drivedir and targetfolder <FilePath> arguments to gam printjob fetch and gam get photo to
allow specification of the destination folder for the file retrieved from Google. The default
location for these commands is the current working directory, drivedir specifies the value of the environment variable GAMDRIVEDIR and
targetfolder <FilePath> specifies a user-choosen path.
gam printjob <PrinterID>|any fetch
[olderthan|newerthan <PrintJobAge>] [query <QueryPrintJob>]
[status <PrintJobStatus>]
[orderby <PrintJobOrderByFieldName> [ascending|descending]]
[owner|user <EmailAddress>]
[limit <Number>] [drivedir|(targetfolder <FilePath>)]
gam <UserTypeEntity> get photo [drivedir|(targetfolder <FilePath>)]
Added noshow argument to gam get photo to suppress displaying of photo data
gam <UserTypeEntity> get photo [drivedir|(targetfolder <FilePath>)] [noshow]
Changed gam print cros to match gam print users. Previously, gam print cros produced a full listing of CrOS devices
and gam print users produced a listing of primaryEmail addresses. Now, gam print cros produces a listing of deviceIds.
To get the previous behavior, say gam print cros full. See GamCommands.txt for a summary of CrOS and User printing.
Commands that produce CSV file output have been changed to make the leftmost column(s) be the key fields.
If you have scripts that process the CSV files as flat files, expecting the columns to be in a particular
order, they will have to be updated. If your scripts process the CSV files by column header, no changes should be required.
2016/07/31
Changed gam get drivefile to take a list of file formats rather than a single format. The first format in the list that is available will be used.
Added drivefilename argument to allow downloading file by name.
<FileFormat> ::= csv|html|txt|tsv|jpeg|jpg|png|svg|pdf|rtf|pptx|xlsx|docx|odt|ods|openoffice|ms|microsoft|micro$oft
<FileFormatList> ::= '<FileFormat>(,<FileFormat)*'
gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(drivefilename <DriveFileName>)|(query <QueryDriveFile>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>]
2016/08/01
Added delimiter <String> argument to gam print courses to allow choice of delimiter to separate aliases.
gam print courses [todrive] [teacher] [student] [alias|aliases] [delimiter <String>]
Added notsuspended argument to gam update group add/sync to prevent adding suspended users to a group
when specifying all users, org <OrgUnitPath> or query <QueryUser> for <UserTypeEntity>.
gam update group <GroupItem> add [owner|manager|member] [notsuspended] <UserTypeEntity>
gam update group <GroupItem> sync [owner|manager|member] [notsuspended] <UserTypeEntity>
Added basic|full argument to gam print mobile to allow specification of output detail desired.
gam print mobile [todrive] [query <QueryMobile>] [basic|full] [orderby <MobileOrderByFieldName> [ascending|descending]]
GAM 3.65
-fix vacation issues (Ross)
-fix Windows path issues (Ross)
-Add message undelete (Ross) and modify (Jay) commands
-Improve message delete performance
-Upgrade to new versions of oauth2client and googleapiclient
GAM 3.63
-"gam update group ... sync users" now does batch add/remove of users for faster sync
-"gam file" can now use - to read list of users from stdin
-"gam csv file:column" can read CSV file of users and specify column to be used.
GAM 3.62
-New Admin Roles API allows you to create, delete and print delegated and super admins
-New Resource Calendar API replaces old GData API and allows you to create, update, get info, delete and print all resource calendars.
-Major cleanups and design updates from Ross Scroggs @taers232c mean GAM is more reliable and stable for your needs. Huge thanks Ross!
-Guard additional fields with convertUTF8
-Correct gam create resource to replace resType with type
-Add type as an argument to gam print resources to make resource type visible
-Handle students/teachers with missing emails in gam course sync
GAM 3.61
-Various fixes by Ross Scroggs for Domain API and Data Transfer commands
-Remove duplicate DoCreateDomain which broke "gam create domain"
GAM 3.6
-Change your primary domain!
-Transfer Google Drive and Google+ data between users.
-Domains API support includes ability to add, delete, update and print domains.
GAM 3.51
-delete or trash messages in mailboxes based on a Gmail search.
-create and delete course aliases with Classroom API.
-HUGE number of bug fixes, large and small by Ross Scroggs. Many thanks Ross!
GAM 3.5
-Support for the new Google Classroom API.
-create, update, info and delete courses
-add, remove and sync course teachers and students
-print courses and course participants
-Google CloudPrint API Support
-update, info, delete and report printers
-share, unshare and get ACLs for printers
-submit, cancel, report and delete print jobs
-Bug fixes and improvements to GAM batch commands
GAM 3.45
-add six.py to solve compatability issues on OS X and Linux
-be conservative with password hashing to prevent timeouts
If you see issues setting user passwords with GAM 3.44 or older, please upgrade to 3.45.
GAM 3.44
-"gam update cros <id> assetid <asset>" allows updating of Chrome OS device Asset ID field. Thanks Erik Pitti!
-Windows versions of GAM now use pyinstaller instead of py2exe.
-upgraded versions of the googleapiclient and oauth2client libraries.
-"gam print cros" should produce a cleaner CSV now.
GAM 3.43
-Fix crash when authenticating GAM related to Short URLs
-minor fixes to Drive and Calendar commands
-catch unauthorized service account errors and offer nice instructions.
-execute bit for gam.py (Thanks daethnir)
GAM 3.42
-"gam <users> show driveactivity" displays Drive activity for user
-"gam report tokens" displays user OAuth activity report
-"gam mobile <id> action accountwipe" wipes account only on Android devices
-"gam <users> update labels" removes Inbox/ prefix from label names
-upgrades to oauth2client and googleapiclient libraries which GAM depends on
-"gam <users> show gmailprofile" shows Gmail mailbox details
-"gam license <sku>" commands to perform actions only on users with a given license
-bug fixes, lots of bug fixes
GAM 3.41
-fix Google servers not returning file size on audit export download
-soft fail on license change errors
-fix for gam info domain errors
GAM 3.4 "Oktoberfest"
-Support for creating and setting custom user schemas http://goo.gl/M9rQrI
-End user view of print users and user info commands.
-fix updating name/description for groups
-fix groups sync commands
-gam print groups members no longer fails on zero member groups
-make sure downloaded Drive file names are safe for OS filenames.
-gam info domain should no longer crash on getting customer ID
-other minor bug fixes
GAM 3.32
-fix service account json files downloaded from new cloud console don't work with GAM
-use the new Gmail API for label command. Offers ability to rename labels and show/hide labels from the label and message list.
-copy Google drive files with commands like gam user <email> update drivefile id <fileid> copy
-print only one SKU for licenses with commands like gam print licenses sku vault
-short license names for Google Apps Message Security (gams), Google Apps Unlimtied (gau) and Google Vault Former Employee (vfe)
GAM 3.31
-New command "gam user delete aliases" clears all aliases for user.
-"gam update user email vfe" will rename user to vfe.oldname.XXXXX@olddomain.com
-fix delete photo command
-fix password update/create for Windows builds
GAM 3.3
-Major rewrites of "gam report" and "gam print users". Note that CSV headers have changed. Better performance and print users now supports "rich" fields like organization, phone, relations, etc.
-"gam report drive" now works for Google Apps Unlimited domains.
-"gam info user" now shows the user's licenses. Use "nolicenses" to prevent showing licenses.
-fix "gam print licenses" fails in large domains by reducing page size from 1000 to 100
-GAM now sends a sha-512 salted hashed password on user create and update for better security.
-cleanup unused features of old GData library.
-fix for Drive file downloading default format.
-upgrade to httplib v0.9 which may help with httplib.BadStatus errors.
GAM 3.21
-Fix crash when attempting to perform Drive operations for users with Drive service disabled.
-Fix "gam info org" only prints first 100 users in org.
GAM 3.2
-New Google Drive GAM commands: http://goo.gl/l7F8hY
-New GAM batch and CSV commands allow bulk parallel GAM operations. Documentation coming at: http://goo.gl/2rsDnc
GAM 3.04
-New domain verification commands "gam create verify <domain name>", "gam update verify <domain name> <verify type>" and "gam info verify".
-"gam update group sync" commands should now only sync changes to the specified role (member, manager, owner). Other roles should be left alone.
-Fix: setting or viewing email signatures and vacation messages with unicode characters caused GAM to crash.
-Fix: issues printing out ASPs and backup codes if user had none set.
-Fix: "gam print orgs parent" always fails.
GAM 3.03
-New GAM user security commands allow management of OAuth tokens, 2SV backup codes and application specific passwords
-Google Vault license commands now work
-"gam update user password random" now resets user password to a very long, random string
-fixed updating location for Chrome devices
-fixed "gam update org" commands broken
GAM 3.02
-client_secrets.json is no longer shipped with GAM, you need to create your own with the instructions at http://goo.gl/QYaQ6R
-New "gam report logins" command to report on user login times and IP.
-Updated "gam report domain" command provides cleaner details of aggregate usage.
-"gam report admin" fixed.
-Fix "gam ou..." commands (they were hanging forever)
-Other minor cleanups and fixes.
GAM 3.01
-Fix gamcache errors on Windows by keeping cache filenames much shorter.
-add (back) support for setting/updating calendar colors
-add support for bulk updating users specified on the command like (gam update users "user1@domain.com user2@domain.com user3@domain.com"... OR gam update users user1@domain.com,user2@domain.com,user3@domain.com...)
-fix setting "gal off" during user creation.
-rewrite "gam info domain" to use new API library (should help with Unicode/UTF-8 errors)
-fix "show pop" and signature commands
-handle out of memory errors more gracefully
GAM 3.0
-Support for the Enterprise License API. Manage Drive storage and Google Coordinate licenses for users.
-Improved compatability with GAM commands from 2.55 and older.
-Fixed undelete user command.
-New "gam print group-members" command to print user membership of all groups.
-New "gam <some users> update user..." command to bulk modify settings for given users. For example, "gam all users update user changepassword on" will force password change for all users, 'gam group class-of-2013@acme.edu update user suspended on' will suspend all members of class-of-2013 group.
-Optimizations which should result in modest improvements to GAM startup time and performance.
GAM 2.994
-Rewritten "gam reports" commands. gam report users, gam report domain, gam report docs, gam report admin
-If CSV file uploaded to drive on "gam report" and "gam print" commands with the todrive parameter are more than 400,000 cells or 256 columns, don't convert to GDoc Spreadsheet.
-Remove old Admin Audit API scope (replaced by Reports API).
-new command: gam all users prism off
GAM 2.992
-Various minor fixes
GAM 2.991
-gam print commands now support a "todrive" argument. When specified, instead of displaying the CSV output locally (or piping it to a file), GAM will upload the CSV data to a Google Docs Spreadsheet owned by the admin you've authenticated as. The spreadsheet will be opened automatically or, if you've created nobrowser.txt, a URL will be shown.
-GAM should handle non-English input characters better. Commands like: "gam.py update user rpinaya lastname Piñaya" should work without issue on Windows.
-Improved errors in various places (less "explosions" more meaningful instructions.
-gam undelete user is fixed to always use the user's id rather than email address. If an email address is supplied, GAM converts it to a id before attempting to delete. If more than 1 deleted user exists with that address, GAM displays the options.
GAM 2.99
-Support for the newly announced Google Apps Admin SDK offering a richer feature set of management for your users, groups, aliases and other objects.
-Simplified OAuth 2.0 authentication
-Ability to manage Mobile and Chrome OS devices.
-Ability to add managers to groups
-Ability to manage group aliases
-Increased performance thanks to new Google API formats, caching, compression and partial update features.
-To many more features to list here! Download it now to see for yourself.
GAM 2.55
-Fix change in Google APIs broke "gam whatis" command.
-Fix change in Google APIs broke "gam info domain" command on CNAME Verification Status message.
GAM 2.54
-Fix a stupid bug that broke "gam print users" when used without additional attributes.
-Another fix for outbound gateway settings on "gam info domain"
-Get this whatsnew.txt doc up to date.
GAM 2.53
-Two new group settings, spam_moderation_level and include_in_global_address_list allow further customization of your Google Groups.
-Error reporting for mailbox delegation has been further improved, GAM does a better job of pinpointing why a delegation failed.
-Fixed updating and deleting domain and default users for calendar ACLs
-proper error handling for adding and removing group members and owners
-Fixed error on gam info domain caused by failure to retrieve outbound gateway settings.
-An EXPERIMENTAL 64-bit build of GAM for Windows is now available. I do not expect it will be any bit faster for most GAM commands since most delay
is due to network I/O. However, some GAM commands like "gam print users", when run against large domains (10,000+ users), use a large amount of memory
and resources due to result size. In these scenarios, the x64 build MIGHT prove faster. If you try the x64 build, please report how it worked back to
the mailing list. "It feels faster" is nice but hard numbers with details of what you did are better :-) Note that if you're using the Python source
build and your Python is 64-bit, you're already using 64-bit GAM :-)
GAM 2.52
-It's a dud! Major bug caused me to pull this version 10 minutes after release :-)
GAM 2.51
-New gam calendar wipe command allows clearing all data off a user's primary calendar
-create user and update user commands now support setting user's org.
-gam whatis command allows looking up an email address to determine if it's a user, alias or group.
-gam delete user no longer renames a user by default since undelete is now in CPanel. Added optional dorename parameter to force old renaming behavior.
-Fix issue that broke gam delete resource command
-GAM now offers to remember your client secret and key when entered the first time
-various other bug fixes
GAM 2.5
-GAM now handles and retries errors consistently and provides nice error messages. Long running GAM processes
like "gam all users" should be much stabler now. Death to the 1000/Unknown errors!
This involved some major changes to the Google API calls so if you run into problems, try
downgrading to 2.3.1 and see if they go away. Be sure to submit bug reports!
-GAM checks for updates
-New parameters for gam create user and gam update user
-New parameters for gam print group: owners, members and settings
-GAM now works for delegated admins with user read/create/update/delete API rights
-gam update group add owner now only adds the user as a group owner, not a member (Google Group member
and owner status are independant of each other)
-gam update group add member no longer revokes user's owner rights if they have them
-gam info group now shows owners who are not a member of the group
-gam now works around the group settings "Backend Error" by making an HTTP request to the groups website.
This workaround may cease to work if performed on more than a few hundred groups at a time.
-moving large numbers of users to an Organization is now more reliable and is performed 25 users at a time.
-gam print users aliases now makes only 1 API call to retrieve all user aliases
-New commands "gam oauth info" and "gam oauth revoke" allow further OAuth token management
-gam info domain now shows the unique customer id
GAM 2.3.1
-Fixes to add calendar command
-Allow updating and removal of special Calendar ACL users domain and default
-pop commands now work without supplying all arguments (defaults to enable for all mail and keep)
-New "file" argument for signature and vacation commands allows specifying a file with message content.
-"gam create group" now only requires group name argument, rest are optional.
-special user * (everyone in domain) can now be added to a group via GAM
-print groups, print resources, print aliases and print orgs commands now output proper CSV
-Dito company information now displayed on OAuth token create
GAM 2.3
-GAM is now owned by Dito (www.ditoweb.com), the Google Apps Experts! See announcement and details at http://code.google.com/p/google-apps-manager
-New user profile photo management commands can update, get and delete user profile photos
-GAM now gracefully handles cross-domain mailbox delegations by using (or giving the delegate) an alias in the mailbox's domain.
-"gam user XXXX show delegates" now has optional argument "csv" to print existing delegations in CSV format
-GAM can now properly rename and delete long usernames by ensuring that the renamed user is max 64 characters in length
-"gam print groups" now has optional arguments nousermanagedgroups and onlyusermanagedgroups allowing user managed groups to be excluded from output or print user managed groups exclusively.
GAM 2.2
-Update Calendar ACLs command, update user calendar settings command and ability to set calendar settings when subscribing user
-Delete Gmail labels command
-Fixes for *nix CSV formatting
-Fixes to make Windows and *nix generated oauth.txt files compatible
-"gam info user" now shows mailbox quota and user organization
-"gam update user" can now handle change of user's domain in renames. "gam multi" commands now fully deprecated.
-Fix reply_to and a few other group settings were never getting updated.
-"gam info group" now makes 3 efficient API calls rather than one per member/owner of the group greatly increasing performance with large groups
-GAM should do a better job of always printing out full email address instead of just username. If you see GAM reporting only the username and not the full email address, please report it as a bug.
-All OAuth scopes are now selected by default.
GAM 2.1.1
-Fix to prevent unnecessary call to Groups Provisioning API when viewing detailed group settings
-should be show_in_group_directory not show_in_groups_directory.
GAM 2.1
-New Reporting API Support allows you to pull 5 different daily reports: accounts, activity, disk_space, email_clients and summary.
-Fix for Adding calendars to a user's list of calendars. Bug in 2.0 meant calendar was always added to the calendar list of the admin who authorized GAM, not the target user.
-GAM now looks for an environment variable called OAUTHFILE. If it exists, GAM will use that file instead of oauth.txt for authentication. This allows admins of many Google Apps domains to switch quickly between domains.
-Fixes for many "gam print users" issues. Thanks to Craig Box for the patch.
GAM 2.0
-Group Settings commands allow you to update Google Group settings
-Calendar commands allow you to grant access to calendars and modify user's list of calendars
-Update Admin Settings like the logo, outbound gateway, email migration and more
-OAuth is now the default authentication method. Support for username/password ClientLogin has been removed.
-Vacation/Away messages can now have a start and end date. They can also be limited to within the domain only.
-Further work to make all GAM commands multi-domain friendly.
-Lot's more bugfixes! look at the Wiki pages for details
GAM 1.9.1
-"gam print postini" will print all of the Postini Batch commands necessary to "mirror" Google Apps email addresses
into a Postini standalone instance.
-"gam version" will print details about the version of GAM you are using.
GAM 1.9 - "Baby Steps"
GAM 1.9 is dedicated to David, my 13 month year old son. Whose just starting to step out into the world this week.
-whatnew.txt is new (is that an oxymoron?)
-Share or Hide users profile from autocomplete and contacts search.
"gam user jsmith show profile"
"gam user jsmith profile share"
"gam group asked-to-be-hidden profile unshare"
Profile modifications only work with OAuth, not ClientLogin (username/password entered into GAM).
Since the profile API uses a scope GAM was not previously making use of, you'll need to re-run
"gam oauth request" to include the Profile API scope.
-Numerous actions can now be performed for all users in a given Organizational
Unit just like they can be for a group or all users. i.e. "gam ou Students webclips off".
-Provisioning API OAuth scope has been subdivided into user, group, alias and ou scopes
offering finer granularity.
-"gam all users" will now include all users across primary and secondary domains instead of just primary domain users.
-"gam info user" will show all email aliases for a user, not just those in the primary domain.
-"gam print users" with any extra arguments would fail, this should be fixed now.
-"gam info group" and "gam print groups" should no longer fail for groups with custom permissions.
GAM 1.8
-OAuth Support - GAM now supports OAuth Authentication. Instead of providing GAM your username and password, you grant GAM access to selected APIs from within your Google Account. This has a number of advantages:
-With OAuth GAM doesn't need to know your password.
-OAuth tokens don't expire, once you grant GAM OAuth access, GAM will have access until you revoke it within your Google account.
-OAuth has the concept of scopes, limiting the areas and services that access is granted to. This allows you to only provide GAM with the privileges it needs.
-More info about OAuth support is on it's way. But for now, you can try OAuth access by running "gam oauth request".
-The settings filter command http://code.google.com/p/google-apps-manager/wiki/ExamplesEmailSettings#Create_a_Filter now has more actions including forward, star, trash and never send to spam.
-Downloading Audit Exports now has partial resume support. GAM will not re-download files that already exist on the local drive. If a large export download fails you should delete the last file GAM was working on since it's incomplete and then restart the process, GAM will pick up with the last file.

View File

@@ -1,31 +0,0 @@
rmdir /q /s gam
rmdir /q /s gam-64
rmdir /q /s build
rmdir /q /s dist
del /q /f gam-%1-windows.zip
del /q /f gam-%1-windows-x64.zip
del /q /f gam-%1-windows-x64.msi
del /q /f *.wixobj
del /q /f *.wixpdb
set WIXVERSION=3.11
c:\python37-32\scripts\pyinstaller --clean -F --distpath=gam windows-gam.spec
xcopy LICENSE gam\
xcopy whatsnew.txt gam\
xcopy gam-setup.bat gam\
xcopy GamCommands.txt gam\
del gam\w9xpopen.exe
"%ProgramFiles%\7-Zip\7z.exe" a -tzip gam-%1-windows.zip gam\ -xr!.svn
c:\python37-64\scripts\pyinstaller --clean -F --distpath=gam-64 windows-gam.spec
xcopy LICENSE gam-64\
xcopy whatsnew.txt gam-64\
xcopy gam-setup.bat gam-64\
xcopy GamCommands.txt gam-64\
"%ProgramFiles%\7-Zip\7z.exe" a -tzip gam-%1-windows-x64.zip gam-64\ -xr!.svn
set GAMVERSION=%1
"%ProgramFiles(x86)%\WiX Toolset v%WIXVERSION%\bin\candle.exe" -arch x64 gam.wxs
"%ProgramFiles(x86)%\WiX Toolset v%WIXVERSION%\bin\light.exe" -ext "%ProgramFiles(x86)%\WiX Toolset v%WIXVERSION%\bin\WixUIExtension.dll" gam.wixobj -o gam-%1-windows-x64.msi
del /q /f gam-%1-windows-x64.wixpdb

View File

@@ -1,33 +0,0 @@
# -*- mode: python -*-
import sys
sys.modules['FixTk'] = None
a = Analysis(['gam.py'],
pathex=['C:\\Users\\jlee\\Documents\\GitHub\\GAM'],
hiddenimports=[],
hookspath=None,
excludes=['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter'],
runtime_hooks=None)
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
a.datas += [('cloudprint-v2.json', 'cloudprint-v2.json', 'DATA')]
# dynamically determine where httplib2/cacerts.txt lives
import importlib
proot = os.path.dirname(importlib.import_module('httplib2').__file__)
a.datas += [('httplib2/cacerts.txt', os.path.join(proot, 'cacerts.txt'), 'DATA')]
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='gam.exe',
debug=False,
strip=None,
upx=True,
console=True )