Compare commits

..

5 Commits
v4.86 ... v4.87

Author SHA1 Message Date
Jay Lee
1cb96cf057 Print Calendars ACLs, delete by ACL id 2019-06-12 14:25:10 -04:00
Jay Lee
2bc8a114c1 GAM 4.87 2019-06-12 13:46:14 -04:00
Ross Scroggs
7f183b9edc Prevent traps when filtering CSV rows (#951) 2019-06-12 13:44:01 -04:00
Jay Lee
f86be17834 Merge branch 'master' of https://github.com/jay0lee/GAM 2019-06-12 13:42:48 -04:00
Jay Lee
6854e3729a prefer id_token_jwt if present in oauth2.txt. Fixes #952 2019-06-12 13:41:16 -04:00
3 changed files with 39 additions and 16 deletions

View File

@@ -182,9 +182,12 @@ script:
- if [ "$e2e" = true ]; then $gam create resource $newresource "Resource Calendar $tstamp" capacity 25 features Whiteboard-$newbase,VC-$newbase building $newbuilding floor 15 type Room; fi
- if [ "$e2e" = true ]; then $gam info resource $newresource; fi
- if [ "$e2e" = true ]; then $gam user $newuser show filelist; fi
- if [ "$e2e" = true ]; then $gam calendar $newuser update read domain; fi
- if [ "$e2e" = true ]; then $gam calendar $newuser add editor $gam_user; fi
- if [ "$e2e" = true ]; then $gam calendar $newuser showacl; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user printacl | $gam csv - gam calendar $gam_user delete id ~id; fi # clear ACLs
- if [ "$e2e" = true ]; then $gam calendar $gam_user update read domain; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user update freebusy default; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user add editor $newuser; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user showacl; fi
- if [ "$e2e" = true ]; then $gam calendar $gam_user printacl | $gam csv - gam calendar $gam_user delete id ~id; fi
- if [ "$e2e" = true ]; then $gam printer register; fi
- if [ "$e2e" = true ]; then source travis/set_printer_csv_filter.sh; fi
- if [ "$e2e" = true ]; then $gam print printers > printers.csv; fi

View File

@@ -1242,7 +1242,7 @@ def getOauth2TxtStorageCredentials():
oauth_data = json.loads(oauth_string)
creds = google.oauth2.credentials.Credentials.from_authorized_user_file(GC_Values[GC_OAUTH2_TXT])
creds.token = oauth_data.get('token', oauth_data.get('auth_token', ''))
creds._id_token = oauth_data.get('id_token', None)
creds._id_token = oauth_data.get('id_token_jwt', oauth_data.get('id_token', None))
token_expiry = oauth_data.get('token_expiry', '1970-01-01T00:00:01Z')
creds.expiry = datetime.datetime.strptime(token_expiry, '%Y-%m-%dT%H:%M:%SZ')
GC_Values[GC_DECODED_ID_TOKEN] = oauth_data.get('decoded_id_token', '')
@@ -3705,16 +3705,29 @@ def formatACLRule(rule):
return '(Scope: {0}:{1}, Role: {2})'.format(rule['scope']['type'], rule['scope']['value'], rule['role'])
return '(Scope: {0}, Role: {1})'.format(rule['scope']['type'], rule['role'])
def doCalendarShowACL():
def doCalendarShowPrintACL(csvOut=False):
calendarId, cal = buildCalendarDataGAPIObject(sys.argv[2])
if not cal:
return
acls = callGAPIpages(cal.acl(), 'list', 'items', calendarId=calendarId, fields='nextPageToken,items(role,scope)')
acls = callGAPIpages(cal.acl(), 'list', 'items', calendarId=calendarId)
i = 0
count = len(acls)
if csvOut:
titles = []
rows = []
else:
count = len(acls)
for rule in acls:
i += 1
print('Calendar: {0}, ACL: {1}{2}'.format(calendarId, formatACLRule(rule), currentCount(i, count)))
if csvOut:
row = flatten_json(rule, None)
for key in row:
if key not in titles:
titles.append(key)
rows.append(row)
else:
print('Calendar: {0}, ACL: {1}{2}'.format(calendarId, formatACLRule(rule), currentCount(i, count)))
if csvOut:
writeCSVfile(rows, titles, '%s Calendar ACLs' % calendarId, False)
def _getCalendarACLScope(i, body):
body['scope'] = {}
@@ -3770,10 +3783,15 @@ def doCalendarDelACL():
calendarId, cal = buildCalendarDataGAPIObject(sys.argv[2])
if not cal:
return
body = {'role': 'none'}
_getCalendarACLScope(5, body)
print('Calendar: {0}, {1} ACL: {2}'.format(calendarId, 'Delete', formatACLScope(body)))
callGAPI(cal.acl(), 'insert', calendarId=calendarId, body=body, sendNotifications=False)
if sys.argv[4].lower() == 'user':
body = {'role': 'none'}
_getCalendarACLScope(5, body)
print('Calendar: {0}, {1} ACL: {2}'.format(calendarId, 'Delete', formatACLScope(body)))
callGAPI(cal.acl(), 'insert', calendarId=calendarId, body=body, sendNotifications=False)
elif sys.argv[4].lower() == 'id':
ruleId = sys.argv[5]
print('Removing rights for %s to %s' % (ruleId, calendarId))
callGAPI(cal.acl(), 'delete', calendarId=calendarId, ruleId=ruleId)
def doCalendarWipeData():
calendarId, cal = buildCalendarDataGAPIObject(sys.argv[2])
@@ -10943,7 +10961,7 @@ def sortCSVTitles(firstTitle, titles):
def writeCSVfile(csvRows, titles, list_type, todrive):
def rowDateTimeFilterMatch(dateMode, rowDate, op, filterDate):
if not rowDate:
if not rowDate or not isinstance(rowDate, str):
return False
try:
rowTime = dateutil.parser.parse(rowDate, ignoretz=True)
@@ -10999,7 +11017,7 @@ def writeCSVfile(csvRows, titles, list_type, todrive):
sys.stderr.write('WARNING: Row filter column "{0}" is not in output columns\n'.format(column))
continue
if filterVal[0] == 'regex':
csvRows = [row for row in csvRows if filterVal[1].search(row.get(column, ''))]
csvRows = [row for row in csvRows if filterVal[1].search(str(row.get(column, '')))]
elif filterVal[0] in ['date', 'time']:
csvRows = [row for row in csvRows if rowDateTimeFilterMatch(filterVal[0] == 'date', row.get(column, ''), filterVal[1], filterVal[2])]
elif filterVal[0] == 'count':
@@ -14043,7 +14061,9 @@ def ProcessGAMCommand(args):
elif command == 'calendar':
argument = sys.argv[3].lower()
if argument == 'showacl':
doCalendarShowACL()
doCalendarShowPrintACL(csvOut=False)
elif argument == 'printacl':
doCalendarShowPrintACL(csvOut=True)
elif argument == 'add':
doCalendarAddACL('Add')
elif argument in ['del', 'delete']:

View File

@@ -6,7 +6,7 @@ import platform
import re
gam_author = 'Jay Lee <jay0lee@gmail.com>'
gam_version = '4.86'
gam_version = '4.87'
gam_license = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
GAM_URL = 'https://git.io/gam'