class_docstr: G Suite Reports base app integration. This is subclassed for various endpoints
class_docstr_tok: ["G","Suite","Reports","base","app","integration",".","This","is","subclassed","for","various","endpoints"]
docstr: Gather the G Suite Admin Report logs for this application type
  
  Returns:
      bool or list: If the execution fails for some reason, return False.
          Otherwise, return a list of activies for this application type.
docstr_tok: ["Gather","the","G","Suite","Admin","Report","logs","for","this","application","type","Returns",":","bool","or","list",":","If","the","execution","fails","for","some","reason",",","return","False",".","Otherwise",",","return","a","list","of","activies","for","this","application","type","."]
code: def _gather_logs(self):
      """Gather the G Suite Admin Report logs for this application type
  
      Returns:
          bool or list: If the execution fails for some reason, return False.
              Otherwise, return a list of activies for this application type.
      """
      if not self._create_service():
          return False
  
      # Cache the last event timestamp so it can be used for future requests
      if not self._next_page_token:
          self._last_event_timestamp = self._last_timestamp
          self._last_run_event_ids = self._context.get(
              "last_event_ids", []
          )
  
      LOGGER.debug(
          "[%s] Querying activities since %s",
          self,
          self._last_event_timestamp,
      )
      LOGGER.debug(
          "[%s] Using next page token: %s", self, self._next_page_token
      )
      LOGGER.debug(
          "[%s] Last run event ids: %s", self, self._last_run_event_ids
      )
  
      activities_list = self._activities_service.list(
          userKey="all",
          applicationName=self._type(),
          startTime=self._last_event_timestamp,
          pageToken=self._next_page_token,
      )
  
      try:
          results = activities_list.execute()
      except self._GOOGLE_API_EXCEPTIONS:
          LOGGER.exception(
              "[%s] Failed to execute activities listing", self
          )
          return False
  
      if not results:
          LOGGER.error(
              "[%s] No results received from the G Suite API request",
              self,
          )
          return False
  
      # Remove duplicate events present in the last time period.
      activities = [
          activity
          for activity in results.get("items", [])
          if activity["id"]["uniqueQualifier"]
          not in set(self._last_run_event_ids)
      ]
      if not activities:
          LOGGER.info(
              "[%s] No logs in response from G Suite API request", self
          )
          return False
  
      # The activity api returns logs in reverse chronological order, for some reason, and
      # therefore the newest log will be first in the list. This should only be updated
      # once during the first poll
      if not self._next_page_token:
          self._last_timestamp = activities[0]["id"]["time"]
          LOGGER.debug(
              "[%s] Caching last timestamp: %s",
              self,
              self._last_timestamp,
          )
          # Store the event ids with the most recent timestamp to de-duplicate them next time
          next_run_event_ids = [
              activity["id"]["uniqueQualifier"]
              for activity in activities
              if activity["id"]["time"] == self._last_timestamp
          ]
          self._context["last_event_ids"] = next_run_event_ids[
              : self._MAX_EVENT_IDS
          ]
          if len(next_run_event_ids) > self._MAX_EVENT_IDS:
              LOGGER.warning(
                  "[%s] More than %d next_run_event_ids. Unable to de-duplicate: %s",
                  self,
                  self._MAX_EVENT_IDS,
                  next_run_event_ids[self._MAX_EVENT_IDS :],
              )
  
      self._next_page_token = results.get("nextPageToken")
      self._more_to_poll = bool(self._next_page_token)
  
      return activities
  
imports: import logging
  import json
  import re
  import socket
  import ssl
  import googleapiclient.discovery
  import googleapiclient.errors
  from google.oauth2 import service_account
  from google.auth.exceptions import GoogleAuthError
  from .None import AppIntegration, StreamAlertApp, get_logger
label_desc: Use image node_id 7 for calling the GSuiteReportsApp obj's underlying member method code with example usage: obj._gather_logs() and returns: activities, False, False, False, False