def info(): cd = gapi_directory.build() resourceId = sys.argv[3] info = gapi.call(cd.mobiledevices(), 'get', customerId=GC_Values[GC_CUSTOMER_ID], resourceId=resourceId) if 'deviceId' in info: info['deviceId'] = info['deviceId'].encode('unicode-escape').decode( UTF8) attrib = 'securityPatchLevel' if attrib in info and int(info[attrib]): info[attrib] = utils.formatTimestampYMDHMS(info[attrib]) display.print_json(info)
def info(users): cd = gapi_directory.build() for user in users: asps = gapi.get_items(cd.asps(), 'list', 'items', userKey=user) if asps: print(f'Application-Specific Passwords for {user}') for asp in asps: if asp['creationTime'] == '0': created_date = 'Unknown' else: created_date = utils.formatTimestampYMDHMS( asp['creationTime']) if asp['lastTimeUsed'] == '0': used_date = 'Never' else: last_used = asp['lastTimeUsed'] used_date = utils.formatTimestampYMDHMS(last_used) print(f' ID: {asp["codeId"]}\n' \ f' Name: {asp["name"]}\n' \ f' Created: {created_date}\n' \ f' Last Used: {used_date}\n') else: print(f' no ASPs for {user}\n')
def print_(): cd = gapi_directory.build() todrive = False titles = [] csvRows = [] fields = None projection = orderBy = sortOrder = None queries = [None] delimiter = ' ' listLimit = 1 appsLimit = -1 i = 3 while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'todrive': todrive = True i += 1 elif myarg in ['query', 'queries']: queries = gam.getQueries(myarg, sys.argv[i + 1]) i += 2 elif myarg == 'delimiter': delimiter = sys.argv[i + 1] i += 2 elif myarg == 'listlimit': listLimit = gam.getInteger(sys.argv[i + 1], myarg, minVal=-1) i += 2 elif myarg == 'appslimit': appsLimit = gam.getInteger(sys.argv[i + 1], myarg, minVal=-1) i += 2 elif myarg == 'fields': fields = f'nextPageToken,mobiledevices({sys.argv[i+1]})' i += 2 elif myarg == 'orderby': orderBy = sys.argv[i + 1].lower() validOrderBy = [ 'deviceid', 'email', 'lastsync', 'model', 'name', 'os', 'status', 'type' ] if orderBy not in validOrderBy: controlflow.expected_argument_exit('orderby', ', '.join(validOrderBy), orderBy) if orderBy == 'lastsync': orderBy = 'lastSync' elif orderBy == 'deviceid': orderBy = 'deviceId' i += 2 elif myarg in SORTORDER_CHOICES_MAP: sortOrder = SORTORDER_CHOICES_MAP[myarg] i += 1 elif myarg in PROJECTION_CHOICES_MAP: projection = PROJECTION_CHOICES_MAP[myarg] i += 1 else: controlflow.invalid_argument_exit(sys.argv[i], 'gam print mobile') for query in queries: gam.printGettingAllItems('Mobile Devices', query) page_message = gapi.got_total_items_msg('Mobile Devices', '...\n') all_mobile = gapi.get_all_pages(cd.mobiledevices(), 'list', 'mobiledevices', page_message=page_message, customerId=GC_Values[GC_CUSTOMER_ID], query=query, projection=projection, fields=fields, orderBy=orderBy, sortOrder=sortOrder) for mobile in all_mobile: row = {} for attrib in mobile: if attrib in ['kind', 'etag']: continue if attrib in ['name', 'email', 'otherAccountsInfo']: if attrib not in titles: titles.append(attrib) if listLimit > 0: row[attrib] = delimiter.join( mobile[attrib][0:listLimit]) elif listLimit == 0: row[attrib] = delimiter.join(mobile[attrib]) elif attrib == 'applications': if appsLimit >= 0: if attrib not in titles: titles.append(attrib) applications = [] j = 0 for app in mobile[attrib]: j += 1 if appsLimit and (j > appsLimit): break appDetails = [] for field in [ 'displayName', 'packageName', 'versionName' ]: appDetails.append(app.get(field, '<None>')) appDetails.append( str(app.get('versionCode', '<None>'))) permissions = app.get('permission', []) if permissions: appDetails.append('/'.join(permissions)) else: appDetails.append('<None>') applications.append('-'.join(appDetails)) row[attrib] = delimiter.join(applications) else: if attrib not in titles: titles.append(attrib) if attrib == 'deviceId': row[attrib] = mobile[attrib].encode( 'unicode-escape').decode(UTF8) elif attrib == 'securityPatchLevel' and int( mobile[attrib]): row[attrib] = utils.formatTimestampYMDHMS( mobile[attrib]) else: row[attrib] = mobile[attrib] csvRows.append(row) display.sort_csv_titles( ['resourceId', 'deviceId', 'serialNumber', 'name', 'email', 'status'], titles) display.write_csv_file(csvRows, titles, 'Mobile', todrive)