def getHoldInfo(): v = buildGAPIObject() hold = sys.argv[3] matterId = None i = 4 while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'matter': matterId = getMatterItem(v, sys.argv[i + 1]) holdId = convertHoldNameToID(v, hold, matterId) i += 2 else: controlflow.invalid_argument_exit(myarg, 'gam info hold') if not matterId: controlflow.system_error_exit( 3, 'you must specify a matter for the hold.') results = gapi.call(v.matters().holds(), 'get', matterId=matterId, holdId=holdId) 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 = gam.convertUIDtoEmailAddress(uid, cd, [account_type]) results['accounts'][i]['email'] = acct_email if 'orgUnit' in results: results['orgUnit']['orgUnitPath'] = gapi_directory_orgunits.info( results['orgUnit']['orgUnitId'], return_attrib='orgUnitPath') display.print_json(results)
def createMatter(): v = buildGAPIObject() matter_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') body = {'name': f'New Matter - {matter_time}'} collaborators = [] cd = None i = 3 while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'name': body['name'] = sys.argv[i + 1] i += 2 elif myarg == 'description': body['description'] = sys.argv[i + 1] i += 2 elif myarg in ['collaborator', 'collaborators']: if not cd: cd = gam.buildGAPIObject('directory') collaborators.extend(validateCollaborators(sys.argv[i + 1], cd)) i += 2 else: controlflow.invalid_argument_exit(sys.argv[i], 'gam create matter') matterId = gapi.call(v.matters(), 'create', body=body, fields='matterId')['matterId'] print(f'Created matter {matterId}') for collaborator in collaborators: print(f' adding collaborator {collaborator["email"]}') body = { 'matterPermission': { 'role': 'COLLABORATOR', 'accountId': collaborator['id'] } } gapi.call(v.matters(), 'addPermissions', matterId=matterId, body=body)
def getMatterInfo(): v = buildGAPIObject() matterId = getMatterItem(v, sys.argv[3]) result = gapi.call(v.matters(), 'get', matterId=matterId, view='FULL') if 'matterPermissions' in result: cd = gam.buildGAPIObject('directory') for i in range(0, len(result['matterPermissions'])): uid = f'uid:{result["matterPermissions"][i]["accountId"]}' user_email = gam.convertUIDtoEmailAddress(uid, cd) result['matterPermissions'][i]['email'] = user_email display.print_json(result)
def build(): return gam.buildGAPIObject('cbcm')
def buildGAPIObject(): return gam.buildGAPIObject('reports')
def build_beta(): return gam.buildGAPIObject('directory_beta')
print(result) print('\nGmailSettingsFiltersList') result = gam.GmailSettingsFiltersList(gapiGmailObj) print(result) print('\nGmailSettingsForwardingAddressesList') result = gam.GmailSettingsForwardingAddressesList(gapiGmailObj) print(result) print('\nGmailSettingsSendAsList') result = gam.GmailSettingsSendAsList(gapiGmailObj) print(result) # Directory API gapiDirObj = gam.buildGAPIObject(API.DIRECTORY) # Customers print('\nCustomersGet') result = gam.CustomersGet(gapiDirObj, customer) print(result) if isinstance(result, dict): customer = result.get('id', customer) # Domains print('\nDomainsGet') result = gam.DomainsGet(gapiDirObj, customer, DOMAIN_NAME) print(result) print('\nDomainsList') result = gam.DomainsList(gapiDirObj, customer) print(result)
def build(): return gam.buildGAPIObject('siteVerification')
def build(): return gam.buildGAPIObject('cloudidentity')
def build_gapi(): return gam.buildGAPIObject('storage')
def updateMatter(action=None): v = buildGAPIObject() matterId = getMatterItem(v, sys.argv[3]) body = {} action_kwargs = {'body': {}} add_collaborators = [] remove_collaborators = [] cd = None i = 4 while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'action': action = sys.argv[i + 1].lower() if action not in VAULT_MATTER_ACTIONS: controlflow.system_error_exit(3, f'allowed actions are ' \ f'{", ".join(VAULT_MATTER_ACTIONS)}, got {action}') i += 2 elif myarg == 'name': body['name'] = sys.argv[i + 1] i += 2 elif myarg == 'description': body['description'] = sys.argv[i + 1] i += 2 elif myarg in ['addcollaborator', 'addcollaborators']: if not cd: cd = gam.buildGAPIObject('directory') add_collaborators.extend(validateCollaborators( sys.argv[i + 1], cd)) i += 2 elif myarg in ['removecollaborator', 'removecollaborators']: if not cd: cd = gam.buildGAPIObject('directory') remove_collaborators.extend( validateCollaborators(sys.argv[i + 1], cd)) i += 2 else: controlflow.invalid_argument_exit(sys.argv[i], 'gam update matter') if action == 'delete': action_kwargs = {} if body: print(f'Updating matter {sys.argv[3]}...') if 'name' not in body or 'description' not in body: # bah, API requires name/description to be sent # on update even when it's not changing result = gapi.call(v.matters(), 'get', matterId=matterId, view='BASIC') body.setdefault('name', result['name']) body.setdefault('description', result.get('description')) gapi.call(v.matters(), 'update', body=body, matterId=matterId) if action: print(f'Performing {action} on matter {sys.argv[3]}') gapi.call(v.matters(), action, matterId=matterId, **action_kwargs) for collaborator in add_collaborators: print(f' adding collaborator {collaborator["email"]}') body = { 'matterPermission': { 'role': 'COLLABORATOR', 'accountId': collaborator['id'] } } gapi.call(v.matters(), 'addPermissions', matterId=matterId, body=body) for collaborator in remove_collaborators: print(f' removing collaborator {collaborator["email"]}') gapi.call(v.matters(), 'removePermissions', matterId=matterId, body={'accountId': collaborator['id']})
def updateHold(): v = buildGAPIObject() hold = sys.argv[3] matterId = None body = {} query = None add_accounts = [] del_accounts = [] start_time = None end_time = None i = 4 while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'matter': matterId = getMatterItem(v, sys.argv[i + 1]) holdId = convertHoldNameToID(v, hold, matterId) i += 2 elif myarg == 'query': query = sys.argv[i + 1] i += 2 elif myarg in ['orgunit', 'ou']: body['orgUnit'] = { 'orgUnitId': gapi_directory_orgunits.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]) i += 2 elif myarg in ['end', 'endtime']: end_time = utils.get_date_zero_time_or_full_time(sys.argv[i + 1]) i += 2 elif myarg in ['addusers', 'addaccounts', 'addgroups']: add_accounts = sys.argv[i + 1].split(',') i += 2 elif myarg in ['removeusers', 'removeaccounts', 'removegroups']: del_accounts = sys.argv[i + 1].split(',') i += 2 else: controlflow.invalid_argument_exit(myarg, 'gam update hold') if not matterId: controlflow.system_error_exit( 3, 'you must specify a matter for the hold.') if query or start_time or end_time or body.get('orgUnit'): fields = 'corpus,query,orgUnit' old_body = gapi.call(v.matters().holds(), 'get', matterId=matterId, holdId=holdId, fields=fields) body['query'] = old_body['query'] body['corpus'] = old_body['corpus'] if 'orgUnit' in old_body and 'orgUnit' not in body: # bah, API requires this to be sent # on update even when it's not changing body['orgUnit'] = old_body['orgUnit'] query_type = f'{body["corpus"].lower()}Query' if body['corpus'] == 'DRIVE': if query: try: body['query'][query_type] = json.loads(query) except ValueError as e: message = f'{str(e)}, query: {query}' controlflow.system_error_exit(3, message) elif body['corpus'] in ['GROUPS', 'MAIL']: if query: body['query'][query_type]['terms'] = query if start_time: body['query'][query_type]['startTime'] = start_time if end_time: body['query'][query_type]['endTime'] = end_time if body: print(f'Updating hold {hold} / {holdId}') gapi.call(v.matters().holds(), 'update', matterId=matterId, holdId=holdId, body=body) if add_accounts or del_accounts: cd = gam.buildGAPIObject('directory') for account in add_accounts: print(f'adding {account} to hold.') 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 = gam.convertEmailAddressToUID(account, cd) gapi.call(v.matters().holds().accounts(), 'delete', matterId=matterId, holdId=holdId, accountId=accountId)
def createHold(): v = buildGAPIObject() allowed_corpuses = gapi.get_enum_values_minus_unspecified( v._rootDesc['schemas']['Hold']['properties']['corpus']['enum']) body = {'query': {}} i = 3 query = None start_time = None end_time = None matterId = None accounts = [] while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'name': body['name'] = sys.argv[i + 1] i += 2 elif myarg == 'query': query = sys.argv[i + 1] i += 2 elif myarg == 'corpus': body['corpus'] = sys.argv[i + 1].upper() if body['corpus'] not in allowed_corpuses: controlflow.expected_argument_exit('corpus', ', '.join(allowed_corpuses), sys.argv[i + 1]) i += 2 elif myarg in ['accounts', 'users', 'groups']: accounts = sys.argv[i + 1].split(',') i += 2 elif myarg in ['orgunit', 'ou']: body['orgUnit'] = { 'orgUnitId': gapi_directory_orgunits.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]) i += 2 elif myarg in ['end', 'endtime']: end_time = utils.get_date_zero_time_or_full_time(sys.argv[i + 1]) i += 2 elif myarg == 'matter': matterId = getMatterItem(v, sys.argv[i + 1]) i += 2 else: controlflow.invalid_argument_exit(sys.argv[i], 'gam create hold') if not matterId: controlflow.system_error_exit( 3, 'you must specify a matter for the new hold.') if not body.get('name'): controlflow.system_error_exit( 3, 'you must specify a name for the new hold.') if not body.get('corpus'): controlflow.system_error_exit(3, f'you must specify a corpus for ' \ f'the new hold. Choose one of {", ".join(allowed_corpuses)}') if body['corpus'] == 'HANGOUTS_CHAT': query_type = 'hangoutsChatQuery' else: query_type = f'{body["corpus"].lower()}Query' body['query'][query_type] = {} if body['corpus'] == 'DRIVE': if query: try: body['query'][query_type] = json.loads(query) except ValueError as e: controlflow.system_error_exit(3, f'{str(e)}, query: {query}') elif body['corpus'] in ['GROUPS', 'MAIL']: if query: body['query'][query_type] = {'terms': query} if start_time: body['query'][query_type]['startTime'] = start_time if end_time: body['query'][query_type]['endTime'] = end_time if accounts: body['accounts'] = [] cd = gam.buildGAPIObject('directory') account_type = 'group' if body['corpus'] == 'GROUPS' else 'user' for account in accounts: body['accounts'].append({ 'accountId': gam.convertEmailAddressToUID(account, cd, account_type) }) holdId = gapi.call(v.matters().holds(), 'create', matterId=matterId, body=body, fields='holdId') print(f'Created hold {holdId["holdId"]}')
def buildGAPIObject(): return gam.buildGAPIObject('vault')
def build(): return gam.buildGAPIObject('licensing')
def build(api='cloudidentity'): return gam.buildGAPIObject(api)
def build(): return gam.buildGAPIObject('directory')
def build(): return gam.buildGAPIObject('chromepolicy')
def build(): return gam.buildGAPIObject('chromemanagement')
def build(): return gam.buildGAPIObject('contactdelegation')