mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 09:51:36 +00:00
Merge branch 'master' of https://github.com/jay0lee/GAM
This commit is contained in:
92
src/gam.py
92
src/gam.py
@@ -1203,8 +1203,8 @@ def doCheckServiceAccount(users):
|
||||
# Tack on email scope for more accurate checking
|
||||
check_scopes.append(USERINFO_EMAIL_SCOPE)
|
||||
long_url = (f'https://admin.google.com/{user_domain}/ManageOauthClients'
|
||||
f'?clientScopeToAdd={",".join(check_scopes)}'
|
||||
f'&clientNameToAdd={service_account}')
|
||||
f'?clientScopeToAdd={",".join(check_scopes)}'
|
||||
f'&clientNameToAdd={service_account}')
|
||||
short_url = shorten_url(long_url)
|
||||
scopes_failed = f'''Some scopes failed! To authorize them, please go to:
|
||||
|
||||
@@ -1785,7 +1785,7 @@ def doGetDomainInfo():
|
||||
for i in range(0, len(result['domainAliases'])):
|
||||
if 'creationTime' in result['domainAliases'][i]:
|
||||
result['domainAliases'][i]['creationTime'] = utils.formatTimestampYMDHMSF(result['domainAliases'][i]['creationTime'])
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doGetDomainAliasInfo():
|
||||
cd = buildGAPIObject('directory')
|
||||
@@ -1793,7 +1793,7 @@ def doGetDomainAliasInfo():
|
||||
result = gapi.call(cd.domainAliases(), 'get', customer=GC_Values[GC_CUSTOMER_ID], domainAliasName=alias)
|
||||
if 'creationTime' in result:
|
||||
result['creationTime'] = utils.formatTimestampYMDHMSF(result['creationTime'])
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doGetCustomerInfo():
|
||||
cd = buildGAPIObject('directory')
|
||||
@@ -2182,9 +2182,7 @@ def doCreateDataTransfer():
|
||||
def doPrintTransferApps():
|
||||
dt = buildGAPIObject('datatransfer')
|
||||
apps = gapi.get_all_pages(dt.applications(), 'list', 'applications', customerId=GC_Values[GC_CUSTOMER_ID])
|
||||
for app in apps:
|
||||
print_json(None, app)
|
||||
print()
|
||||
display.print_json(apps)
|
||||
|
||||
def doPrintDataTransfers():
|
||||
dt = buildGAPIObject('datatransfer')
|
||||
@@ -2308,7 +2306,7 @@ def doPrintShowGuardians(csvFormat):
|
||||
if not csvFormat:
|
||||
print(f'Student: {studentId}, {itemName}:{currentCount(i, count)}')
|
||||
for guardian in guardians:
|
||||
print_json(None, guardian, spacing=' ')
|
||||
display.print_json(guardian, spacing=' ')
|
||||
else:
|
||||
for guardian in guardians:
|
||||
guardian['studentEmail'] = studentId
|
||||
@@ -2435,7 +2433,7 @@ def doGetCourseInfo():
|
||||
courseId = addCourseIdScope(sys.argv[3])
|
||||
info = gapi.call(croom.courses(), 'get', id=courseId)
|
||||
info['ownerEmail'] = convertUIDtoEmailAddress(f'uid:{info["ownerId"]}')
|
||||
print_json(None, info)
|
||||
display.print_json(info)
|
||||
teachers = gapi.get_all_pages(croom.courses().teachers(), 'list', 'teachers', courseId=courseId)
|
||||
students = gapi.get_all_pages(croom.courses().students(), 'list', 'students', courseId=courseId)
|
||||
try:
|
||||
@@ -3041,7 +3039,7 @@ def doPrinterShowACL():
|
||||
for acl in printer_info['printers'][0]['access']:
|
||||
if 'key' in acl:
|
||||
acl['accessURL'] = f'https://www.google.com/cloudprint/addpublicprinter.html?printerid={show_printer}&key={acl["key"]}'
|
||||
print_json(None, acl)
|
||||
display.print_json(acl)
|
||||
print()
|
||||
|
||||
def doPrinterAddACL():
|
||||
@@ -3278,7 +3276,7 @@ def doGetPrinterInfo():
|
||||
if not everything:
|
||||
del printer_info['capabilities']
|
||||
del printer_info['access']
|
||||
print_json(None, printer_info)
|
||||
display.print_json(printer_info)
|
||||
|
||||
def doUpdatePrinter():
|
||||
cp = buildGAPIObject('cloudprint')
|
||||
@@ -3726,6 +3724,9 @@ def doCalendarAddEvent():
|
||||
elif myarg == 'colorindex':
|
||||
body['colorId'] = getInteger(sys.argv[i+1], myarg, CALENDAR_EVENT_MIN_COLOR_INDEX, CALENDAR_EVENT_MAX_COLOR_INDEX)
|
||||
i += 2
|
||||
elif myarg == 'hangoutsmeet':
|
||||
body['conferenceData'] = {'createRequest': {'requestId': f'{str(uuid.uuid4())}'}}
|
||||
i += 1
|
||||
else:
|
||||
controlflow.invalid_argument_exit(sys.argv[i], "gam calendar <email> addevent")
|
||||
if ('recurrence' in body) and (('start' in body) or ('end' in body)):
|
||||
@@ -4948,7 +4949,7 @@ def showDriveFileInfo(users):
|
||||
continue
|
||||
feed = gapi.call(drive.files(), 'get', fileId=fileId, fields=fields, supportsAllDrives=True)
|
||||
if feed:
|
||||
print_json(None, feed)
|
||||
display.print_json(feed)
|
||||
|
||||
def showDriveFileRevisions(users):
|
||||
fileId = sys.argv[5]
|
||||
@@ -4958,7 +4959,7 @@ def showDriveFileRevisions(users):
|
||||
continue
|
||||
feed = gapi.call(drive.revisions(), 'list', fileId=fileId)
|
||||
if feed:
|
||||
print_json(None, feed)
|
||||
display.print_json(feed)
|
||||
|
||||
def transferSecCals(users):
|
||||
target_user = sys.argv[5]
|
||||
@@ -5595,7 +5596,7 @@ def printShowSmime(users, csvFormat):
|
||||
for smime in smimes:
|
||||
addRowTitlesToCSVfile(flatten_json(smime, flattened={'User': user}), csvRows, titles)
|
||||
else:
|
||||
print_json(None, smimes)
|
||||
display.print_json(smimes)
|
||||
if csvFormat:
|
||||
writeCSVfile(csvRows, titles, 'S/MIME', todrive)
|
||||
|
||||
@@ -7368,14 +7369,14 @@ def shorten_url(long_url):
|
||||
'User-Agent': GAM_INFO}
|
||||
try:
|
||||
resp, content = simplehttp.request(url_shortnr, 'POST',
|
||||
f'{{"long_url": "{long_url}"}}', headers=headers)
|
||||
except Exception as e:
|
||||
f'{{"long_url": "{long_url}"}}', headers=headers)
|
||||
except Exception:
|
||||
return long_url
|
||||
if resp.status != 200:
|
||||
return long_url
|
||||
try:
|
||||
return json.loads(content).get('short_url', long_url)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
print(content)
|
||||
return long_url
|
||||
|
||||
@@ -7948,7 +7949,7 @@ def doShowServiceAccountKeys():
|
||||
key['name'] = key['name'].rsplit('/', 1)[-1]
|
||||
if key['name'] == currentPrivateKeyId:
|
||||
key['usedToAuthenticateThisRequest'] = True
|
||||
print_json(None, keys)
|
||||
display.print_json(keys)
|
||||
|
||||
def doCreateOrRotateServiceAccountKeys(iam=None, project_id=None, client_email=None, client_id=None):
|
||||
local_key_size = 2048
|
||||
@@ -8113,7 +8114,7 @@ def doGetTeamDriveInfo(users):
|
||||
continue
|
||||
result = gapi.call(drive.drives(), 'get', driveId=teamDriveId,
|
||||
useDomainAdminAccess=useDomainAdminAccess, fields='*')
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doCreateTeamDrive(users):
|
||||
body = {'name': sys.argv[5]}
|
||||
@@ -8405,7 +8406,7 @@ def doCreateVaultExport():
|
||||
body['exportOptions'][options_field]['showConfidentialModeContent'] = showConfidentialModeContent
|
||||
results = gapi.call(v.matters().exports(), 'create', matterId=matterId, body=body)
|
||||
print(f'Created export {results["id"]}')
|
||||
print_json(None, results)
|
||||
display.print_json(results)
|
||||
|
||||
def doDeleteVaultExport():
|
||||
v = buildGAPIObject('vault')
|
||||
@@ -8419,7 +8420,7 @@ def doGetVaultExportInfo():
|
||||
matterId = getMatterItem(v, sys.argv[3])
|
||||
exportId = convertExportNameToID(v, sys.argv[4], matterId)
|
||||
export = gapi.call(v.matters().exports(), 'get', matterId=matterId, exportId=exportId)
|
||||
print_json(None, export)
|
||||
display.print_json(export)
|
||||
|
||||
def _getCloudStorageObject(s, bucket, object_, local_file=None, expectedMd5=None):
|
||||
if not local_file:
|
||||
@@ -8665,7 +8666,7 @@ def doGetVaultHoldInfo():
|
||||
results['accounts'][i]['email'] = acct_email
|
||||
if 'orgUnit' in results:
|
||||
results['orgUnit']['orgUnitPath'] = doGetOrgInfo(results['orgUnit']['orgUnitId'], return_attrib='orgUnitPath')
|
||||
print_json(None, results)
|
||||
display.print_json(results)
|
||||
|
||||
def convertExportNameToID(v, nameOrID, matterId):
|
||||
nameOrID = nameOrID.lower()
|
||||
@@ -8844,7 +8845,7 @@ def doGetVaultMatterInfo():
|
||||
uid = f'uid:{result["matterPermissions"][i]["accountId"]}'
|
||||
user_email = convertUIDtoEmailAddress(uid, cd)
|
||||
result['matterPermissions'][i]['email'] = user_email
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doCreateUser():
|
||||
cd = buildGAPIObject('directory')
|
||||
@@ -9119,7 +9120,7 @@ def doGetBuildingInfo():
|
||||
building['floorNames'] = ','.join(building['floorNames'])
|
||||
if 'buildingName' in building:
|
||||
sys.stdout.write(building.pop('buildingName'))
|
||||
print_json(None, building)
|
||||
display.print_json(building)
|
||||
|
||||
def doDeleteBuilding():
|
||||
cd = buildGAPIObject('directory')
|
||||
@@ -9826,7 +9827,7 @@ def doCreateResoldSubscription():
|
||||
customerAuthToken, body = _getResoldSubscriptionAttr(sys.argv[4:], customerId)
|
||||
result = gapi.call(res.subscriptions(), 'insert', customerId=customerId, customerAuthToken=customerAuthToken, body=body, fields='customerId')
|
||||
print('Created subscription:')
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doUpdateResoldSubscription():
|
||||
res = buildGAPIObject('reseller')
|
||||
@@ -9885,7 +9886,7 @@ def doUpdateResoldSubscription():
|
||||
result = gapi.call(res.subscriptions(), function, customerId=customerId, subscriptionId=subscriptionId, **kwargs)
|
||||
print(f'Updated {customerId} SKU {sku} subscription:')
|
||||
if result:
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def doGetResoldSubscriptions():
|
||||
res = buildGAPIObject('reseller')
|
||||
@@ -9900,7 +9901,7 @@ def doGetResoldSubscriptions():
|
||||
else:
|
||||
controlflow.invalid_argument_exit(myarg, "gam info resoldsubscriptions")
|
||||
result = gapi.call(res.subscriptions(), 'list', customerId=customerId, customerAuthToken=customerAuthToken)
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def _getResoldSubscriptionAttr(arg, customerId):
|
||||
body = {'plan': {},
|
||||
@@ -9934,7 +9935,7 @@ def doGetResoldCustomer():
|
||||
res = buildGAPIObject('reseller')
|
||||
customerId = sys.argv[3]
|
||||
result = gapi.call(res.customers(), 'get', customerId=customerId)
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
|
||||
def _getResoldCustomerAttr(arg):
|
||||
body = {}
|
||||
@@ -9982,7 +9983,7 @@ def doGetMemberInfo():
|
||||
memberKey = normalizeEmailAddressOrUID(sys.argv[3])
|
||||
groupKey = normalizeEmailAddressOrUID(sys.argv[4])
|
||||
info = gapi.call(cd.members(), 'get', memberKey=memberKey, groupKey=groupKey)
|
||||
print_json(None, info)
|
||||
display.print_json(info)
|
||||
|
||||
def doGetUserInfo(user_email=None):
|
||||
|
||||
@@ -10362,7 +10363,7 @@ def doGetResourceCalendarInfo():
|
||||
if 'buildingId' in resource:
|
||||
resource['buildingName'] = _getBuildingNameById(cd, resource['buildingId'])
|
||||
resource['buildingId'] = f'id:{resource["buildingId"]}'
|
||||
print_json(None, resource)
|
||||
display.print_json(resource)
|
||||
|
||||
def _filterTimeRanges(activeTimeRanges, startDate, endDate):
|
||||
if startDate is None and endDate is None:
|
||||
@@ -10479,7 +10480,7 @@ def doGetCrosInfo():
|
||||
print(f' {up}: {cros[up]}')
|
||||
else:
|
||||
sys.stdout.write(f' {up}:')
|
||||
print_json(None, cros[up], ' ')
|
||||
display.print_json(cros[up], ' ')
|
||||
if not noLists:
|
||||
activeTimeRanges = _filterTimeRanges(cros.get('activeTimeRanges', []), startDate, endDate)
|
||||
lenATR = len(activeTimeRanges)
|
||||
@@ -10561,32 +10562,7 @@ def doGetMobileInfo():
|
||||
attrib = 'securityPatchLevel'
|
||||
if attrib in info and int(info[attrib]):
|
||||
info[attrib] = utils.formatTimestampYMDHMS(info[attrib])
|
||||
print_json(None, info)
|
||||
|
||||
def print_json(object_name, object_value, spacing=''):
|
||||
if object_name in ['kind', 'etag', 'etags']:
|
||||
return
|
||||
if object_name is not None:
|
||||
sys.stdout.write(f'{spacing}{object_name}: ')
|
||||
if isinstance(object_value, list):
|
||||
if len(object_value) == 1 and isinstance(object_value[0], (str, int, bool)):
|
||||
sys.stdout.write(f'{object_value[0]}\n')
|
||||
return
|
||||
if object_name is not None:
|
||||
sys.stdout.write('\n')
|
||||
for a_value in object_value:
|
||||
if isinstance(a_value, (str, int, bool)):
|
||||
sys.stdout.write(f' {spacing}{a_value}\n')
|
||||
else:
|
||||
print_json(None, a_value, f' {spacing}')
|
||||
elif isinstance(object_value, dict):
|
||||
print()
|
||||
if object_name is not None:
|
||||
sys.stdout.write('\n')
|
||||
for another_object in object_value:
|
||||
print_json(another_object, object_value[another_object], f' {spacing}')
|
||||
else:
|
||||
sys.stdout.write(f'{object_value}\n')
|
||||
display.print_json(info)
|
||||
|
||||
def doSiteVerifyShow():
|
||||
verif = buildGAPIObject('siteVerification')
|
||||
@@ -10814,7 +10790,7 @@ def doGetOrgInfo(name=None, return_attrib=None):
|
||||
result = gapi.call(cd.orgunits(), 'get', customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=encodeOrgUnitPath(name))
|
||||
if return_attrib:
|
||||
return result[return_attrib]
|
||||
print_json(None, result)
|
||||
display.print_json(result)
|
||||
if get_users:
|
||||
name = result['orgUnitPath']
|
||||
page_message = gapi.got_total_items_first_last_msg('Users')
|
||||
|
||||
Reference in New Issue
Block a user