示例#1
0
def RecentlyModified(update_time):
    """Checks if the trigger with the given update_time was recently modified.

  Args:
    update_time: str, the time when the trigger was last modified.

  Returns:
    True if the trigger was recently modified and might not be ready for use.
  """
    update_dt = times.ParseDateTime(update_time)
    max_duration = iso_duration.Duration(minutes=MAX_READY_LATENCY_MINUTES)
    ready_dt = times.GetDateTimePlusDuration(update_dt, max_duration)
    return times.Now() < ready_dt
示例#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 _TokenExpiresWithinWindow(expiry_window,
                              token_expiry_time,
                              max_window_seconds=3600):
    """Determines if token_expiry_time is within expiry_window_duration.

  Calculates the amount of time between utcnow() and token_expiry_time and
  returns true, if that amount is less thank the provided duration window. All
  calculations are done in number of seconds for consistency.


  Args:
    expiry_window: string, Duration representing the amount of time between
      now and token_expiry_time to compare against.
    token_expiry_time: datetime, The time when token expires.
    max_window_seconds: int, Maximum size of expiry window, in seconds.

  Raises:
    ValueError: If expiry_window is invalid or can not be parsed.

  Returns:
    True if token is expired or will expire with in the provided window,
    False otherwise.
  """
    try:
        min_expiry = times.ParseDuration(expiry_window, default_suffix='s')
        if min_expiry.total_seconds > max_window_seconds:
            raise ValueError('Invalid expiry window duration [{}]: '
                             'Must be between 0s and 1h'.format(expiry_window))
    except times.Error as e:
        message = six.text_type(e).rstrip('.')
        raise ValueError('Error Parsing expiry window duration '
                         '[{}]: {}'.format(expiry_window, message))

    token_expiry_time = times.LocalizeDateTime(token_expiry_time,
                                               tzinfo=dateutil.tz.tzutc())
    window_end = times.GetDateTimePlusDuration(
        times.Now(tzinfo=dateutil.tz.tzutc()), min_expiry)

    return token_expiry_time <= window_end
示例#4
0
def ProcessTableExpiration(expire_duration):
    """Convert commandline duration into epoch timeoffset (in ms)."""
    t = times.GetDateTimePlusDuration(datetime.datetime.now(), expire_duration)
    return int(time.mktime(t.timetuple())) * 1000