Reformatting
This commit is contained in:
parent
a9aa54d567
commit
ac66838f6b
6
main.go
6
main.go
|
@ -19,9 +19,9 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/golang/groupcache/lru"
|
"github.com/golang/groupcache/lru"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
|
|
||||||
"github.com/discourse/discourse-auth-proxy/internal/httpproxy"
|
"github.com/discourse/discourse-auth-proxy/internal/httpproxy"
|
||||||
)
|
)
|
||||||
|
@ -323,11 +323,11 @@ func computeHMAC(message string, secret string) string {
|
||||||
func setupStorage(config *Config) {
|
func setupStorage(config *Config) {
|
||||||
if config.RedisAddress != "" {
|
if config.RedisAddress != "" {
|
||||||
client := redis.NewClient(&redis.Options{
|
client := redis.NewClient(&redis.Options{
|
||||||
Addr: config.RedisAddress,
|
Addr: config.RedisAddress,
|
||||||
Password: config.RedisPassword,
|
Password: config.RedisPassword,
|
||||||
})
|
})
|
||||||
storageInstance = &RedisStore{
|
storageInstance = &RedisStore{
|
||||||
Redis: client,
|
Redis: client,
|
||||||
Namespace: "_discourse-auth-proxy_",
|
Namespace: "_discourse-auth-proxy_",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
22
main_test.go
22
main_test.go
|
@ -6,14 +6,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
"sync"
|
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/golang/groupcache/lru"
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
|
"github.com/golang/groupcache/lru"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SSOOptions struct {
|
type SSOOptions struct {
|
||||||
|
@ -45,7 +45,7 @@ func NewMemoryStore() *MemoryStore {
|
||||||
|
|
||||||
var redisStore = NewRedisStore()
|
var redisStore = NewRedisStore()
|
||||||
var memoryStore = NewMemoryStore()
|
var memoryStore = NewMemoryStore()
|
||||||
var stores = [2]CacheStore{ memoryStore, redisStore }
|
var stores = [2]CacheStore{memoryStore, redisStore}
|
||||||
|
|
||||||
func mustParseURL(s string) *url.URL {
|
func mustParseURL(s string) *url.URL {
|
||||||
u, err := url.Parse(s)
|
u, err := url.Parse(s)
|
||||||
|
@ -337,11 +337,11 @@ func TestGetSetNXCookieSecretIfRedis(t *testing.T) {
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
for _, s := range stores {
|
for _, s := range stores {
|
||||||
err := s.Clear()
|
err := s.Clear()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s", err)
|
fmt.Printf("%s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/groupcache/lru"
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
|
"github.com/golang/groupcache/lru"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,12 +55,12 @@ func (store *MemoryStore) Clear() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisStore struct {
|
type RedisStore struct {
|
||||||
Redis *redis.Client
|
Redis *redis.Client
|
||||||
Namespace string
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *RedisStore) AddNonce(nonce string, val string) error {
|
func (store *RedisStore) AddNonce(nonce string, val string) error {
|
||||||
err := store.Redis.SetEX(bgCtx, store.Prefix(nonce), val, 600 * time.Second).Err()
|
err := store.Redis.SetEX(bgCtx, store.Prefix(nonce), val, 600*time.Second).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (store *RedisStore) GetAndDeleteNonce(nonce string) (val string, err error)
|
||||||
|
|
||||||
// used in tests only
|
// used in tests only
|
||||||
func (store *RedisStore) Clear() error {
|
func (store *RedisStore) Clear() error {
|
||||||
keys, err := store.Redis.Keys(bgCtx, store.Namespace + "*").Result()
|
keys, err := store.Redis.Keys(bgCtx, store.Namespace+"*").Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue