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