mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 16:59:22 +02:00
parent
aab9ec413e
commit
bc61206b78
21 changed files with 409 additions and 88 deletions
|
@ -1,6 +1,9 @@
|
|||
package databroker
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultDeletePermanentlyAfter is the default amount of time to wait before deleting
|
||||
|
@ -18,6 +21,7 @@ type serverConfig struct {
|
|||
secret []byte
|
||||
storageType string
|
||||
storageConnectionString string
|
||||
storageTLSConfig *tls.Config
|
||||
}
|
||||
|
||||
func newServerConfig(options ...ServerOption) *serverConfig {
|
||||
|
@ -70,3 +74,10 @@ func WithStorageConnectionString(connStr string) ServerOption {
|
|||
cfg.storageConnectionString = connStr
|
||||
}
|
||||
}
|
||||
|
||||
// WithStorageTLSConfig sets the tls config for connection to storage.
|
||||
func WithStorageTLSConfig(tlsConfig *tls.Config) ServerOption {
|
||||
return func(cfg *serverConfig) {
|
||||
cfg.storageTLSConfig = tlsConfig
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestConfigSource(t *testing.T) {
|
|||
}
|
||||
defer li.Close()
|
||||
|
||||
dataBrokerServer := newTestServer()
|
||||
dataBrokerServer := New()
|
||||
srv := grpc.NewServer()
|
||||
databroker.RegisterDataBrokerServiceServer(srv, dataBrokerServer)
|
||||
go func() { _ = srv.Serve(li) }()
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// +build !redis
|
||||
|
||||
package databroker
|
||||
|
||||
func newTestServer() *Server {
|
||||
return New()
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
// +build redis
|
||||
|
||||
package databroker
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/storage/redis"
|
||||
)
|
||||
|
||||
func newTestServer() *Server {
|
||||
address := "redis://localhost:6379/0"
|
||||
if redisURL := os.Getenv("REDIS_URL"); redisURL != "" {
|
||||
address = redisURL
|
||||
}
|
||||
return New(WithStorageType(redis.Name), WithStorageConnectionString(address))
|
||||
}
|
|
@ -350,9 +350,14 @@ func (srv *Server) getDB(recordType string) (storage.Backend, error) {
|
|||
func (srv *Server) newDB(recordType string) (db storage.Backend, err error) {
|
||||
switch srv.cfg.storageType {
|
||||
case config.StorageInMemoryName:
|
||||
db = inmemory.NewDB(recordType, srv.cfg.btreeDegree)
|
||||
return inmemory.NewDB(recordType, srv.cfg.btreeDegree), nil
|
||||
case config.StorageRedisName:
|
||||
db, err = redis.New(srv.cfg.storageConnectionString, recordType, int64(srv.cfg.deletePermanentlyAfter.Seconds()))
|
||||
db, err = redis.New(
|
||||
srv.cfg.storageConnectionString,
|
||||
recordType,
|
||||
int64(srv.cfg.deletePermanentlyAfter.Seconds()),
|
||||
redis.WithTLSConfig(srv.cfg.storageTLSConfig),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create new redis storage: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue