mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
Fixes/Updates (#317)
GamCommands.txt Update documentation gam.py doCheckServiceAccount Correct my previous update - Lines 1211/1241 doCalendarDeleteEvent: Eliminate duplicate events - Line 3337 Fix error message - LInes 3344/2245 Pass sendNotifications to API - LInes 3323,3349 doCalendarAddEvent Update error message - LIne 3461 doGetCrosInfo Add query capability - Lines 7992/8078
This commit is contained in:
@@ -57,7 +57,7 @@ If an item contains spaces, it should be surrounded by " or '.
|
|||||||
<CourseID> ::= <Number>|d:<CourseAlias>
|
<CourseID> ::= <Number>|d:<CourseAlias>
|
||||||
<CourseParticipantType> ::= teacher|teachers|student|students
|
<CourseParticipantType> ::= teacher|teachers|student|students
|
||||||
<CrOSID> ::= <String>
|
<CrOSID> ::= <String>
|
||||||
<CrOSItem> ::= <CrOSID>|(query:<QueryCrOS>)|(query <QueryCrOS>)
|
<CrOSItem> ::= <CrOSID>|(query:<QueryCrOS>)
|
||||||
<DestEmailAddress> ::= <EmailAddress>
|
<DestEmailAddress> ::= <EmailAddress>
|
||||||
<DomainAlias> ::= <String>
|
<DomainAlias> ::= <String>
|
||||||
<DriveFileACLRole> :: =commenter|editor|owner|reader|writer
|
<DriveFileACLRole> :: =commenter|editor|owner|reader|writer
|
||||||
@@ -99,6 +99,7 @@ If an item contains spaces, it should be surrounded by " or '.
|
|||||||
<PrintJobStatus> ::= done|error|held|in_progress|queued|submitted
|
<PrintJobStatus> ::= done|error|held|in_progress|queued|submitted
|
||||||
<PropertyKey> ::= <String>
|
<PropertyKey> ::= <String>
|
||||||
<PropertyValue> ::= <String>
|
<PropertyValue> ::= <String>
|
||||||
|
<QueryCalendar> ::= <String>
|
||||||
<QueryContact> ::= <String> See: https://developers.google.com/google-apps/contacts/v3/reference#contacts-query-parameters-reference
|
<QueryContact> ::= <String> See: https://developers.google.com/google-apps/contacts/v3/reference#contacts-query-parameters-reference
|
||||||
<QueryCrOS> ::= <String> See: https://support.google.com/chrome/a/answer/1698333?hl=en
|
<QueryCrOS> ::= <String> See: https://support.google.com/chrome/a/answer/1698333?hl=en
|
||||||
<QueryDriveFile> :: = <String> See: https://developers.google.com/drive/v2/web/search-parameters
|
<QueryDriveFile> :: = <String> See: https://developers.google.com/drive/v2/web/search-parameters
|
||||||
@@ -463,7 +464,7 @@ If an item contains spaces, it should be surrounded by " or '.
|
|||||||
(website|websites clear|(home_page|blog|profile|work|home|other|ftp|reservations|app_install_page|<String> <URL> [notprimary|primary]))|
|
(website|websites clear|(home_page|blog|profile|work|home|other|ftp|reservations|app_install_page|<String> <URL> [notprimary|primary]))|
|
||||||
(<SchemaName>.<FieldName> [multivalued|multivalue|value [type work|home|other|(custom <String>)]] <String>)
|
(<SchemaName>.<FieldName> [multivalued|multivalue|value [type work|home|other|(custom <String>)]] <String>)
|
||||||
|
|
||||||
gam version [check]
|
gam version [check] [simple]
|
||||||
gam help
|
gam help
|
||||||
|
|
||||||
gam batch <FileName>|- [charset <Charset>]
|
gam batch <FileName>|- [charset <Charset>]
|
||||||
@@ -537,6 +538,7 @@ gam calendar <CalendarItem> del|delete <CalendarACLRole> <EmailAddress>|(domain
|
|||||||
gam calendar <CalendarItem> showacl
|
gam calendar <CalendarItem> showacl
|
||||||
|
|
||||||
gam calendar <CalendarItem> addevent <EventAttributes>+
|
gam calendar <CalendarItem> addevent <EventAttributes>+
|
||||||
|
gam calendar <CalendarItem> deleteevent (id|eventid <EventID>)* (query|eventquery <QueryCalendar>)* [doit] [notifyattendees]
|
||||||
gam calendar <CalendarItem> wipe
|
gam calendar <CalendarItem> wipe
|
||||||
|
|
||||||
gam update cros <CrOSItem> (<CrOSAttributes>+)|(action deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device|disable|reenable [acknowledge_device_touch_requirement])
|
gam update cros <CrOSItem> (<CrOSAttributes>+)|(action deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device|disable|reenable [acknowledge_device_touch_requirement])
|
||||||
|
|||||||
90
src/gam.py
90
src/gam.py
@@ -1208,23 +1208,20 @@ def buildGplusGAPIObject(user):
|
|||||||
def doCheckServiceAccount(users):
|
def doCheckServiceAccount(users):
|
||||||
for user in users:
|
for user in users:
|
||||||
all_scopes_pass = True
|
all_scopes_pass = True
|
||||||
all_scopes = []
|
all_scopes = {}
|
||||||
print u'User: %s' % (user)
|
print u'User: %s' % (user)
|
||||||
for api, scopes in API_SCOPE_MAPPING.items():
|
for api, scopes in API_SCOPE_MAPPING.items():
|
||||||
for scope in scopes:
|
for scope in scopes:
|
||||||
if scope in all_scopes:
|
all_scopes[scope] = api
|
||||||
continue # don't check same scope twice
|
for scope, api in sorted(all_scopes.items()):
|
||||||
all_scopes.append((api, scope))
|
|
||||||
all_scopes = sorted(all_scopes)
|
|
||||||
for scope in all_scopes:
|
|
||||||
try:
|
try:
|
||||||
service = buildGAPIServiceObject(scope[0], act_as=user, use_scopes=scope[1])
|
service = buildGAPIServiceObject(api, act_as=user, use_scopes=scope)
|
||||||
service._http.request.credentials.refresh(httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL]))
|
service._http.request.credentials.refresh(httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL]))
|
||||||
result = u'PASS'
|
result = u'PASS'
|
||||||
except oauth2client.client.HttpAccessTokenRefreshError:
|
except oauth2client.client.HttpAccessTokenRefreshError:
|
||||||
result = u'FAIL'
|
result = u'FAIL'
|
||||||
all_scopes_pass = False
|
all_scopes_pass = False
|
||||||
print u' Scope: {0:60} {1}'.format(scope[1], result)
|
print u' Scope: {0:60} {1}'.format(scope, result)
|
||||||
service_account = service._http.request.credentials.serialization_data[u'client_id']
|
service_account = service._http.request.credentials.serialization_data[u'client_id']
|
||||||
if all_scopes_pass:
|
if all_scopes_pass:
|
||||||
print u'\nAll scopes passed!\nService account %s is fully authorized.' % service_account
|
print u'\nAll scopes passed!\nService account %s is fully authorized.' % service_account
|
||||||
@@ -1241,7 +1238,7 @@ and grant Client name:
|
|||||||
|
|
||||||
Access to scopes:
|
Access to scopes:
|
||||||
|
|
||||||
%s\n''' % (user_domain, service_account, ',\n'.join([scope[1] for scope in all_scopes]))
|
%s\n''' % (user_domain, service_account, ',\n'.join(sorted(all_scopes.keys())))
|
||||||
sys.exit(int(not all_scopes_pass))
|
sys.exit(int(not all_scopes_pass))
|
||||||
|
|
||||||
def showReport():
|
def showReport():
|
||||||
@@ -3323,10 +3320,10 @@ def doCalendarDeleteEvent():
|
|||||||
if not cal:
|
if not cal:
|
||||||
return
|
return
|
||||||
events = []
|
events = []
|
||||||
sendNotifications = None
|
sendNotifications = False
|
||||||
doit = False
|
doit = False
|
||||||
i = 4
|
i = 4
|
||||||
while (i < len(sys.argv)):
|
while i < len(sys.argv):
|
||||||
if sys.argv[i].lower() == u'notifyattendees':
|
if sys.argv[i].lower() == u'notifyattendees':
|
||||||
sendNotifications = True
|
sendNotifications = True
|
||||||
i += 1
|
i += 1
|
||||||
@@ -3337,19 +3334,19 @@ def doCalendarDeleteEvent():
|
|||||||
query = sys.argv[i+1]
|
query = sys.argv[i+1]
|
||||||
result = callGAPIpages(cal.events(), u'list', items=u'items', calendarId=calendarId, q=query)
|
result = callGAPIpages(cal.events(), u'list', items=u'items', calendarId=calendarId, q=query)
|
||||||
for event in result:
|
for event in result:
|
||||||
if u'id' in event:
|
if u'id' in event and event[u'id'] not in events:
|
||||||
events.append(event[u'id'])
|
events.append(event[u'id'])
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower() == u'doit':
|
elif sys.argv[i].lower() == u'doit':
|
||||||
doit = True
|
doit = True
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
print u'ERROR: %s is not a valid argument for gam calendar <email> delete event'
|
print u'ERROR: %s is not a valid argument for "gam calendar <email> deleteevent"' % sys.argv[i]
|
||||||
sys.exit(3)
|
sys.exit(2)
|
||||||
if doit:
|
if doit:
|
||||||
for eventId in events:
|
for eventId in events:
|
||||||
print u' deleting eventId %s' % eventId
|
print u' deleting eventId %s' % eventId
|
||||||
callGAPI(cal.events(), u'delete', calendarId=calendarId, eventId=eventId)
|
callGAPI(cal.events(), u'delete', calendarId=calendarId, eventId=eventId, sendNotifications=sendNotifications)
|
||||||
else:
|
else:
|
||||||
for eventId in events:
|
for eventId in events:
|
||||||
print u' would delete eventId %s. Add doit to command to actually delete event' % eventId
|
print u' would delete eventId %s. Add doit to command to actually delete event' % eventId
|
||||||
@@ -3461,7 +3458,7 @@ def doCalendarAddEvent():
|
|||||||
body[u'colorId'] = str(sys.argv[i+1])
|
body[u'colorId'] = str(sys.argv[i+1])
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
print u'ERROR: %s is not a valid argument for "gam calendar"' % sys.argv[i]
|
print u'ERROR: %s is not a valid argument for "gam calendar <email> addevent"' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
if not timeZone and u'recurrence' in body:
|
if not timeZone and u'recurrence' in body:
|
||||||
timeZone = callGAPI(cal.calendars(), u'get', calendarId=calendarId, fields=u'timeZone')[u'timeZone']
|
timeZone = callGAPI(cal.calendars(), u'get', calendarId=calendarId, fields=u'timeZone')[u'timeZone']
|
||||||
@@ -7992,6 +7989,15 @@ CROS_SCALAR_PROPERTY_PRINT_ORDER = [
|
|||||||
def doGetCrosInfo():
|
def doGetCrosInfo():
|
||||||
cd = buildGAPIObject(u'directory')
|
cd = buildGAPIObject(u'directory')
|
||||||
deviceId = sys.argv[3]
|
deviceId = sys.argv[3]
|
||||||
|
if deviceId[:6].lower() == u'query:':
|
||||||
|
query = deviceId[6:]
|
||||||
|
devices_result = callGAPIpages(cd.chromeosdevices(), u'list', u'chromeosdevices',
|
||||||
|
query=query, customerId=GC_Values[GC_CUSTOMER_ID], fields=u'chromeosdevices/deviceId,nextPageToken')
|
||||||
|
devices = list()
|
||||||
|
for a_device in devices_result:
|
||||||
|
devices.append(a_device[u'deviceId'])
|
||||||
|
else:
|
||||||
|
devices = [deviceId,]
|
||||||
projection = None
|
projection = None
|
||||||
fieldsList = []
|
fieldsList = []
|
||||||
noLists = False
|
noLists = False
|
||||||
@@ -8042,30 +8048,34 @@ def doGetCrosInfo():
|
|||||||
fields = u','.join(set(fieldsList)).replace(u'.', u'/')
|
fields = u','.join(set(fieldsList)).replace(u'.', u'/')
|
||||||
else:
|
else:
|
||||||
fields = None
|
fields = None
|
||||||
cros = callGAPI(cd.chromeosdevices(), u'get', customerId=GC_Values[GC_CUSTOMER_ID],
|
i = 1
|
||||||
deviceId=deviceId, projection=projection, fields=fields)
|
device_count = len(devices)
|
||||||
print u'CrOS Device: {0}'.format(deviceId)
|
for deviceId in devices:
|
||||||
if u'notes' in cros:
|
cros = callGAPI(cd.chromeosdevices(), u'get', customerId=GC_Values[GC_CUSTOMER_ID],
|
||||||
cros[u'notes'] = cros[u'notes'].replace(u'\n', u'\\n')
|
deviceId=deviceId, projection=projection, fields=fields)
|
||||||
for up in CROS_SCALAR_PROPERTY_PRINT_ORDER:
|
print u'CrOS Device: {0} ({1} of {2})'.format(deviceId, i, device_count)
|
||||||
if up in cros:
|
if u'notes' in cros:
|
||||||
print u' {0}: {1}'.format(up, cros[up])
|
cros[u'notes'] = cros[u'notes'].replace(u'\n', u'\\n')
|
||||||
if not noLists:
|
for up in CROS_SCALAR_PROPERTY_PRINT_ORDER:
|
||||||
activeTimeRanges = cros.get(u'activeTimeRanges', [])
|
if up in cros:
|
||||||
lenATR = len(activeTimeRanges)
|
print u' {0}: {1}'.format(up, cros[up])
|
||||||
if lenATR:
|
if not noLists:
|
||||||
print u' activeTimeRanges'
|
activeTimeRanges = cros.get(u'activeTimeRanges', [])
|
||||||
for i in xrange(min(listLimit, lenATR) if listLimit else lenATR):
|
lenATR = len(activeTimeRanges)
|
||||||
print u' date: {0}'.format(activeTimeRanges[i][u'date'])
|
if lenATR:
|
||||||
print u' activeTime: {0}'.format(str(activeTimeRanges[i][u'activeTime']))
|
print u' activeTimeRanges'
|
||||||
print u' duration: {0}'.format(formatMilliSeconds(activeTimeRanges[i][u'activeTime']))
|
for i in xrange(min(listLimit, lenATR) if listLimit else lenATR):
|
||||||
recentUsers = cros.get(u'recentUsers', [])
|
print u' date: {0}'.format(activeTimeRanges[i][u'date'])
|
||||||
lenRU = len(recentUsers)
|
print u' activeTime: {0}'.format(str(activeTimeRanges[i][u'activeTime']))
|
||||||
if lenRU:
|
print u' duration: {0}'.format(formatMilliSeconds(activeTimeRanges[i][u'activeTime']))
|
||||||
print u' recentUsers'
|
recentUsers = cros.get(u'recentUsers', [])
|
||||||
for i in xrange(min(listLimit, lenRU) if listLimit else lenRU):
|
lenRU = len(recentUsers)
|
||||||
print u' type: {0}'.format(recentUsers[i][u'type'])
|
if lenRU:
|
||||||
print u' email: {0}'.format(recentUsers[i].get(u'email', u''))
|
print u' recentUsers'
|
||||||
|
for i in xrange(min(listLimit, lenRU) if listLimit else lenRU):
|
||||||
|
print u' type: {0}'.format(recentUsers[i][u'type'])
|
||||||
|
print u' email: {0}'.format(recentUsers[i].get(u'email', u''))
|
||||||
|
i += 1
|
||||||
|
|
||||||
def doGetMobileInfo():
|
def doGetMobileInfo():
|
||||||
cd = buildGAPIObject(u'directory')
|
cd = buildGAPIObject(u'directory')
|
||||||
|
|||||||
Reference in New Issue
Block a user