def TransformTrigger(data, undefined=''):
  """Returns textual information about functions trigger.

  Args:
    data: JSON-serializable 1st and 2nd gen Functions objects.
    undefined: Returns this value if the resource cannot be formatted.

  Returns:
    str containing information about functions trigger.
  """
  generation = _TransformGeneration(data)
  if generation == GEN_1:
    if 'httpsTrigger' in data:
      return 'HTTP Trigger'
    if 'gcsTrigger' in data:
      return 'bucket: ' + data['gcsTrigger']
    if 'pubsubTrigger' in data:
      return 'topic: ' + data['pubsubTrigger'].split('/')[-1]
    if 'eventTrigger' in data:
      return 'Event Trigger'
    return undefined

  elif generation == GEN_2:
    if 'eventTrigger' in data:
      event_trigger = data['eventTrigger']
      event_type = event_trigger.get('eventType')

      if trigger_types.IsAuditLogType(event_type):
        return 'Cloud Audit Log'
      elif trigger_types.IsStorageType(event_type):
        event_filters = event_trigger['eventFilters']
        bucket = next((f.get('value')
                       for f in event_filters
                       if f.get('attribute') == 'bucket'), None)
        if bucket:
          return 'bucket: ' + bucket

      if 'pubsubTopic' in event_trigger:
        return 'topic: ' + event_trigger['pubsubTopic'].split('/')[-1]
      return 'Event Trigger'

    # v2 functions can always be http triggered as backed by a cloud run
    # service, if no trigger is found display 'HTTP trigger'
    return 'HTTP Trigger'

  return undefined
Пример #2
0
def TriggerActiveTime(event_type, update_time):
  """Computes the time by which the trigger will become active.

  Args:
    event_type: str, the trigger's event type.
    update_time: str, the time when the trigger was last modified.

  Returns:
    The active time as a string, or None if the trigger is already active.
  """
  if not types.IsAuditLogType(event_type):
    # The delay only applies to Audit Log triggers.
    return None
  update_dt = times.ParseDateTime(update_time)
  delay = iso_duration.Duration(minutes=MAX_ACTIVE_DELAY_MINUTES)
  active_dt = times.GetDateTimePlusDuration(update_dt, delay)
  if times.Now() >= active_dt:
    return None
  return times.FormatDateTime(active_dt, fmt='%H:%M:%S', tzinfo=times.LOCAL)
Пример #3
0
 def Epilog(self, resources_were_displayed):
     if resources_were_displayed and types.IsAuditLogType(self._event_type):
         log.warning(
             'It may take up to {} minutes for the update to take full effect.'
             .format(triggers.MAX_ACTIVE_DELAY_MINUTES))
 def Epilog(self, resources_were_displayed):
     if resources_were_displayed and types.IsAuditLogType(self._event_type):
         log.warning(
             'It may take up to {} minutes for the new trigger to become active.'
             .format(triggers.MAX_ACTIVE_DELAY_MINUTES))