// EnforceExpiry checks all instances for expiration and issues an expiration command, if necessary.
// This function returns raft.ErrNotLeader if this store is not the current leader.
196432
func (s *Store) EnforceExpiry() error {
	var cmd []byte
	if err := func() error {
		s.mu.Lock()
		defer s.mu.Unlock()

		// Ignore if this store is not the leader and hasn't been for at least 2 TTLs intervals.
		if !s.IsLeader() {
			return raft.ErrNotLeader
		} else if s.leaderTime.IsZero() || time.Since(s.leaderTime) < (2*s.InstanceTTL) {
			return ErrLeaderWait
		}

		// Iterate over services and then instances.
		var instances []expireInstance
		for service, m := range s.data.Instances {
			for _, inst := range m {
				// Ignore instances that have heartbeated within the TTL.
				if t := s.heartbeats[instanceKey{service, inst.ID}]; time.Since(t) <= s.InstanceTTL {
					continue
				}

				logger.Info("marking instance for expiry",
					"fn", "EnforceExpiry",
					"service", service,
					"instance.id", inst.ID,
					"instance.addr", inst.Addr,
				)

				// Add to list of instances to expire.
				// The current expiry time is added to prevent a race condition of
				// instances updating their expiry date while this command is applying.
				instances = append(instances, expireInstance{
					Service:    service,
					InstanceID: inst.ID,
				})
			}
		}

		// If we have no instances to expire then exit.
		if len(instances) == 0 {
			return nil
		}

		// Create command to expire instances.
		buf, err := json.Marshal(&expireInstancesCommand{
			Instances: instances,
		})
		if err != nil {
			return err
		}
		cmd = buf

		return nil
	}(); err != nil {
		return err
	} else if cmd == nil {
		return nil
	}

	// Apply command to raft.
	if _, err := s.raftApply(expireInstancesCommandType, cmd); err != nil {
		return err
	}
	return nil
}
648553
func (e *Enforcer) Enforce(rvals ...interface{}) bool {
	return enforce(e.Enforcer, e.defaultRole, e.claimsEnforcerFunc, rvals...)
}
5572
func EnforcePolicy(event *audit.Event, level audit.Level, omitStages []audit.Stage) (*audit.Event, error) {
	for _, stage := range omitStages {
		if event.Stage == stage {
			return nil, nil
		}
	}
	return enforceLevel(event, level)
}
948115
func checkExpiration(body *tokenserver.MachineTokenBody, now time.Time) error {
	notBefore := time.Unix(int64(body.IssuedAt), 0)
	notAfter := notBefore.Add(time.Duration(body.Lifetime) * time.Second)
	if now.Before(notBefore.Add(-allowedClockDrift)) {
		diff := notBefore.Sub(now)
		return fmt.Errorf("token is not valid yet, will be valid in %s", diff)
	}
	if now.After(notAfter.Add(allowedClockDrift)) {
		diff := now.Sub(notAfter)
		return fmt.Errorf("token expired %s ago", diff)
	}
	return nil
}
566565
func (self *Collection) IsExpired(record *Record) bool {
	if self.TTL(record) < 0 {
		return true
	} else {
		return false
	}
}
1296980
func (e *Expiry) IsExpired() bool {
	if e.CurrentTime == nil {
		e.CurrentTime = time.Now
	}
	return e.expiration.Before(e.CurrentTime())
}
1333996
func (o *OIDCConnectorV2) SetExpiry(expires time.Time) {
	o.Metadata.SetExpiry(expires)
}
1363691
func (p *Enforcer) Enforce(rule string, c Context) bool {
	c.rules = &p.rules
	c.checks = p.checks
	r, ok := p.rules[rule]
	return ok && r(c)
}
366845
func (d *DiskStorer) ResetExpiry(key string) error {
	if !validKey(key) {
		return errNoSession{}
	}

	filePath := path.Join(d.folderPath, key)
	nowTime := time.Now().UTC()

	return os.Chtimes(filePath, nowTime, nowTime)
}
80619
func (e *SyncedEnforcer) Enforce(rvals ...interface{}) bool {
	e.m.RLock()
	defer e.m.RUnlock()
	return e.Enforcer.Enforce(rvals...)
}
139946
func (s *DomainSummary) SetExpiry(v time.Time) *DomainSummary {
	s.Expiry = &v
	return s
}
572797
func (c *ExpirationCache) getOrExpire(key string) (interface{}, bool) {
	// Prevent all inserts from the time we deem an item as "expired" to when we
	// delete it, so an un-expired item doesn't sneak in under the same key, just
	// before the Delete.
	c.expirationLock.Lock()
	defer c.expirationLock.Unlock()
	timestampedItem, exists := c.getTimestampedEntry(key)
	if !exists {
		return nil, false
	}
	if c.expirationPolicy.IsExpired(timestampedItem) {
		klog.V(4).Infof("Entry %v: %+v has expired", key, timestampedItem.Obj)
		c.cacheStorage.Delete(key)
		return nil, false
	}
	return timestampedItem.Obj, true
}
443590
func (r *RoleV3) SetExpiry(expires time.Time) {
	r.Metadata.SetExpiry(expires)
}
885550
func (s *Command) SetExpiresAfter(v time.Time) *Command {
	s.ExpiresAfter = &v
	return s
}
497824
func (c *ClusterNameV2) SetExpiry(expires time.Time) {
	c.Metadata.SetExpiry(expires)
}
1057991
func Expiry(clock clockwork.Clock, ttl time.Duration) time.Time {
	if ttl == 0 {
		return time.Time{}
	}
	return clock.Now().UTC().Add(ttl)
}
389423
func (c *StaticTokensV2) SetExpiry(expires time.Time) {
	c.Metadata.SetExpiry(expires)
}