MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / nextRefreshCheckAt

Function nextRefreshCheckAt

sdk/cliproxy/auth/auto_refresh_loop.go:338–414  ·  view source on GitHub ↗
(now time.Time, auth *Auth, interval time.Duration)

Source from the content-addressed store, hash-verified

336}
337
338func nextRefreshCheckAt(now time.Time, auth *Auth, interval time.Duration) (time.Time, bool) {
339 if auth == nil {
340 return time.Time{}, false
341 }
342 if hasUnauthorizedAuthFailure(auth) {
343 return time.Time{}, false
344 }
345
346 if auth.AuthKind() == AuthKindAPIKey {
347 return time.Time{}, false
348 }
349
350 if !auth.NextRefreshAfter.IsZero() && now.Before(auth.NextRefreshAfter) {
351 return auth.NextRefreshAfter, true
352 }
353
354 if evaluator, ok := auth.Runtime.(RefreshEvaluator); ok && evaluator != nil {
355 if interval <= 0 {
356 interval = refreshCheckInterval
357 }
358 return now.Add(interval), true
359 }
360
361 lastRefresh := auth.LastRefreshedAt
362 if lastRefresh.IsZero() {
363 if ts, ok := authLastRefreshTimestamp(auth); ok {
364 lastRefresh = ts
365 }
366 }
367
368 expiry, hasExpiry := auth.ExpirationTime()
369
370 if pref := authPreferredInterval(auth); pref > 0 {
371 candidates := make([]time.Time, 0, 2)
372 if hasExpiry && !expiry.IsZero() {
373 if !expiry.After(now) || expiry.Sub(now) <= pref {
374 return now, true
375 }
376 candidates = append(candidates, expiry.Add(-pref))
377 }
378 if lastRefresh.IsZero() {
379 return now, true
380 }
381 candidates = append(candidates, lastRefresh.Add(pref))
382 next := candidates[0]
383 for _, candidate := range candidates[1:] {
384 if candidate.Before(next) {
385 next = candidate
386 }
387 }
388 if !next.After(now) {
389 return now, true
390 }
391 return next, true
392 }
393
394 provider := strings.ToLower(auth.Provider)
395 lead := ProviderRefreshLead(provider, auth.Runtime)

Calls 6

authLastRefreshTimestampFunction · 0.85
authPreferredIntervalFunction · 0.85
ProviderRefreshLeadFunction · 0.85
AuthKindMethod · 0.80
ExpirationTimeMethod · 0.80