// Get2faValidityTime is the handler for GET /organizations/globalid/2fa/validity
// Get the 2fa validity time for the organization, in seconds
197267
func (api OrganizationsAPI) Get2faValidityTime(w http.ResponseWriter, r *http.Request) {
	globalid := mux.Vars(r)["globalid"]
	mgr := organization.NewManager(r)

	validity, err := mgr.GetValidity(globalid)
	if err != nil && err != mgo.ErrNotFound {
		log.Error("Error while getting validity duration: ", err.Error())
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if err == mgo.ErrNotFound {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	response := struct {
		SecondsValidity int `json:"secondsvalidity"`
	}{
		SecondsValidity: validity,
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(&response)
}
1194192
func (t *TimePeriod) Validate(c *validation.Context) {
	switch {
	case t.GetDuration() != "":
		c.Enter("duration")
		t.Time.(*TimePeriod_Duration).Validate(c)
		c.Exit()
	case t.GetSeconds() < 0:
		c.Errorf("seconds must be non-negative")
	}
}
273608
func GetLastSendTime(ctx context.Context, g *globals.Context, log utils.DebugLabeler) time.Time {
	var zeroTime time.Time
	var lastSendUnixTime int64
	found, err := g.LocalChatDb.GetInto(&lastSendUnixTime, lastSendTimeDbKey())
	// Warn for errors and return zero.
	if err != nil {
		log.Debug(ctx, "Failed to get chat active last send time: %s", err)
		return zeroTime
	}
	// If the last time doesn't exist, again return zero.
	if !found {
		return zeroTime
	}
	// Otherwise return what we found.
	return time.Unix(lastSendUnixTime, 0)
}
680048
func (c *ConfigLookup) GetDuration(key string) time.Duration {
	value, ok := c.Lookup(key)
	if !ok {
		return 0
	}
	return cast.ToDuration(value)
}
144995
func getLast2FACollection(session *mgo.Session) *mgo.Collection {
	return db.GetCollection(session, last2FACollectionName)
}
626520
func (c *InstanceCache) getAccessTime(ctx context.Context, now time.Time, pin common.Pin) (lastAccess time.Time, ok bool) {
	c.withState(ctx, now, func(s *messages.InstanceCache) {
		var entry *messages.InstanceCache_Entry
		if entry, ok = s.Entries[pin.InstanceID]; ok {
			lastAccess = google.TimeFromProto(entry.LastAccess)
		}
	})
	return
}
864270
func (c *CacheTTL) isValidItem(item *eurekache.Item) bool {
	if item.Value == nil {
		return false
	}
	return item.ExpiredAt > time.Now().UnixNano()
}
1351203
func (c *Context) GetTime(key string) (t time.Time) {
	if val, ok := c.Get(key); ok && val != nil {
		t, _ = val.(time.Time)
	}
	return
}
606701
func GetCredential(accessKeyID, location string, t time.Time) string {
	scope := getScope(location, t)
	return accessKeyID + "/" + scope
}
373972
func (_class VDIClass) GetSnapshotTime(sessionID SessionRef, self VDIRef) (_retval time.Time, _err error) {
	_method := "VDI.get_snapshot_time"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVDIRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertTimeToGo(_method + " -> ", _result.Value)
	return
}
520028
func (k *Key) ValidTimes(delim string) []time.Time {
	return k.ValidTimesFormat(time.RFC3339, delim)
}
59861
func (o *ValidUntilOption) Get() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.value
}
201605
func (d *domainClient) GetCurrentTime(ctx context.Context, args *GetCurrentTimeArgs) (reply *GetCurrentTimeReply, err error) {
	reply = new(GetCurrentTimeReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "Animation.getCurrentTime", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "Animation.getCurrentTime", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "Animation", Op: "GetCurrentTime", Err: err}
	}
	return
}
1263027
func (c *Certificate) GetExpirationDuration() time.Duration {
	if err := c.buildX509Certificate(); err != nil {
		return time.Unix(0, 0).Sub(time.Now())
	}
	return c.crt.NotAfter.Sub(time.Now())
}
1181964
func (si SignerInfo) GetSigningTimeAttribute() (time.Time, error) {
	var t time.Time

	if !si.SignedAttrs.HasAttribute(oid.AttributeSigningTime) {
		return t, nil
	}
	rv, err := si.SignedAttrs.GetOnlyAttributeValueBytes(oid.AttributeSigningTime)
	if err != nil {
		return t, err
	}
	if rv.Class != asn1.ClassUniversal || (rv.Tag != asn1.TagUTCTime && rv.Tag != asn1.TagGeneralizedTime) {
		return t, ASN1Error{"bad class or tag"}
	}

	if rest, err := asn1.Unmarshal(rv.FullBytes, &t); err != nil {
		return t, err
	} else if len(rest) > 0 {
		return t, ErrTrailingData
	}

	return t, nil
}
584609
func (c *crontime) nextValidMinute(baseTime time.Time) {
	for _, min := range c.minute {
		if c.calculatedTime.Hour() == baseTime.Hour() {
			if !hasPassed(min, c.calculatedTime.Minute()) {
				c.calculatedTime = setMinute(c.calculatedTime, min)
				return
			}
		} else {
			c.calculatedTime = setMinute(c.calculatedTime, min)
			return
		}
	}
	c.calculatedTime = c.calculatedTime.Add(1 * time.Hour)
	c.calculatedTime = setMinute(c.calculatedTime, c.minute[0])
	//log.Println("Cronbee: Minute", c.calculatedTime, baseTime)
	c.nextValidHour(baseTime)
	c.nextValidMinute(baseTime)
}
326368
func validateMetadata(clientNonce, pendingTime string, storedIdentity *whitelistIdentity, roleEntry *awsRoleEntry) error {
	// For sanity
	if !storedIdentity.DisallowReauthentication && storedIdentity.ClientNonce == "" {
		return fmt.Errorf("client nonce missing in stored identity")
	}

	// If reauthentication is disabled or if the nonce supplied matches a
	// predefined nonce which indicates reauthentication to be disabled,
	// authentication will not succeed.
	if storedIdentity.DisallowReauthentication ||
		subtle.ConstantTimeCompare([]byte(reauthenticationDisabledNonce), []byte(clientNonce)) == 1 {
		return fmt.Errorf("reauthentication is disabled")
	}

	givenPendingTime, err := time.Parse(time.RFC3339, pendingTime)
	if err != nil {
		return err
	}

	storedPendingTime, err := time.Parse(time.RFC3339, storedIdentity.PendingTime)
	if err != nil {
		return err
	}

	// When the presented client nonce does not match the cached entry, it
	// is either that a rogue client is trying to login or that a valid
	// client suffered a migration. The migration is detected via
	// pendingTime in the instance metadata, which sadly is only updated
	// when an instance is stopped and started but *not* when the instance
	// is rebooted. If reboot survivability is needed, either
	// instrumentation to delete the instance ID from the whitelist is
	// necessary, or the client must durably store the nonce.
	//
	// If the `allow_instance_migration` property of the registered role is
	// enabled, then the client nonce mismatch is ignored, as long as the
	// pending time in the presented instance identity document is newer
	// than the cached pending time. The new pendingTime is stored and used
	// for future checks.
	//
	// This is a weak criterion and hence the `allow_instance_migration`
	// option should be used with caution.
	if subtle.ConstantTimeCompare([]byte(clientNonce), []byte(storedIdentity.ClientNonce)) != 1 {
		if !roleEntry.AllowInstanceMigration {
			return fmt.Errorf("client nonce mismatch")
		}
		if roleEntry.AllowInstanceMigration && !givenPendingTime.After(storedPendingTime) {
			return fmt.Errorf("client nonce mismatch and instance meta-data incorrect")
		}
	}

	// Ensure that the 'pendingTime' on the given identity document is not
	// before the 'pendingTime' that was used for previous login. This
	// disallows old metadata documents from being used to perform login.
	if givenPendingTime.Before(storedPendingTime) {
		return fmt.Errorf("instance meta-data is older than the one used for previous login")
	}
	return nil
}