Remove FUCKING FALLBACKS
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/options"
|
||||
@@ -34,8 +35,8 @@ func NewCachedESI(direct ESIInterface, db interface {
|
||||
// Parse cache validity ONCE at initialization
|
||||
cacheValidity, err := time.ParseDuration(options.GlobalOptions.CacheValidity)
|
||||
if err != nil {
|
||||
logger.Warning("Invalid cache validity duration %s, using 10m default: %v", options.GlobalOptions.CacheValidity, err)
|
||||
cacheValidity = 10 * time.Minute
|
||||
logger.Error("Invalid cache validity duration %s: %v", options.GlobalOptions.CacheValidity, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return &CachedESI{
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/options"
|
||||
@@ -110,8 +111,8 @@ func NewDirectESI() *DirectESI {
|
||||
// Parse HTTP timeout ONCE at initialization
|
||||
httpTimeout, err := time.ParseDuration(options.GlobalOptions.HTTPTimeout)
|
||||
if err != nil {
|
||||
logger.Warning("Invalid HTTP timeout duration %s, using 30s default: %v", options.GlobalOptions.HTTPTimeout, err)
|
||||
httpTimeout = 30 * time.Second
|
||||
logger.Error("Invalid HTTP timeout duration %s: %v", options.GlobalOptions.HTTPTimeout, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return &DirectESI{
|
||||
|
||||
18
esi/sso.go
18
esi/sso.go
@@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -279,12 +280,21 @@ func (s *SSO) processCallback(isGet bool, code, state string, writeResponse func
|
||||
}{code, state, nil}
|
||||
}
|
||||
|
||||
// parseTokenExpiryBufferSeconds parses the token expiry buffer from Go duration format to seconds
|
||||
func parseTokenExpiryBufferSeconds() int {
|
||||
duration, err := time.ParseDuration(options.GlobalOptions.TokenExpiryBuffer)
|
||||
if err != nil {
|
||||
logger.Error("Invalid token expiry buffer duration %s: %v", options.GlobalOptions.TokenExpiryBuffer, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return int(duration.Seconds())
|
||||
}
|
||||
|
||||
func (s *SSO) waitForCallback() (code, state string, err error) {
|
||||
// Parse SSO callback timeout ONCE at initialization
|
||||
callbackTimeout, err := time.ParseDuration(options.GlobalOptions.SSOCallbackTimeout)
|
||||
if err != nil {
|
||||
logger.Warning("Invalid SSO callback timeout duration %s, using 30s default: %v", options.GlobalOptions.SSOCallbackTimeout, err)
|
||||
callbackTimeout = 30 * time.Second
|
||||
return "", "", fmt.Errorf("invalid SSO callback timeout duration %s: %w", options.GlobalOptions.SSOCallbackTimeout, err)
|
||||
}
|
||||
|
||||
logger.Debug("Waiting for authentication callback (timeout: %v)", callbackTimeout)
|
||||
@@ -343,7 +353,7 @@ func (s *SSO) exchangeCodeForToken(ctx context.Context, code, verifier string) (
|
||||
CharacterName: name,
|
||||
AccessToken: tr.AccessToken,
|
||||
RefreshToken: tr.RefreshToken,
|
||||
ExpiresAt: time.Now().Add(time.Duration(tr.ExpiresIn-options.GlobalOptions.TokenExpiryBuffer) * time.Second),
|
||||
ExpiresAt: time.Now().Add(time.Duration(tr.ExpiresIn-parseTokenExpiryBufferSeconds()) * time.Second),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -384,7 +394,7 @@ func (s *SSO) refreshToken(ctx context.Context, char *types.Character) error {
|
||||
char.RefreshToken = tr.RefreshToken
|
||||
}
|
||||
if tr.ExpiresIn > 0 {
|
||||
char.ExpiresAt = time.Now().Add(time.Duration(tr.ExpiresIn-options.GlobalOptions.TokenExpiryBuffer) * time.Second)
|
||||
char.ExpiresAt = time.Now().Add(time.Duration(tr.ExpiresIn-parseTokenExpiryBufferSeconds()) * time.Second)
|
||||
}
|
||||
|
||||
logger.Debug("Saving refreshed token to database for character %s", char.CharacterName)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -28,8 +29,8 @@ func NewZulipWebhook(url, email, token string) *ZulipWebhook {
|
||||
// Parse HTTP timeout ONCE at initialization
|
||||
httpTimeout, err := time.ParseDuration(options.GlobalOptions.HTTPTimeout)
|
||||
if err != nil {
|
||||
logger.Warning("Invalid HTTP timeout duration %s, using 30s default: %v", options.GlobalOptions.HTTPTimeout, err)
|
||||
httpTimeout = 30 * time.Second
|
||||
logger.Error("Invalid HTTP timeout duration %s: %v", options.GlobalOptions.HTTPTimeout, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return &ZulipWebhook{
|
||||
|
||||
Reference in New Issue
Block a user