pomerium/internal/databroker/config.go
Kenneth Jenkins 6171c09596
config: remove unused databroker storage settings (#5285)
Config options concerning the TLS connection from databroker to storage
backend are now unused. TLS options for this connection can instead be
set directly in the databroker storage connection string.
2024-09-16 11:58:57 -07:00

93 lines
2.6 KiB
Go

package databroker
import (
"time"
"github.com/pomerium/pomerium/internal/log"
"github.com/pomerium/pomerium/pkg/cryptutil"
)
var (
// DefaultDeletePermanentlyAfter is the default amount of time to wait before deleting
// a record permanently.
DefaultDeletePermanentlyAfter = time.Hour
// DefaultStorageType is the default storage type that Server use
DefaultStorageType = "memory"
// DefaultGetAllPageSize is the default page size for GetAll calls.
DefaultGetAllPageSize = 50
// DefaultRegistryTTL is the default registry time to live.
DefaultRegistryTTL = time.Minute
)
type serverConfig struct {
deletePermanentlyAfter time.Duration
secret []byte
storageType string
storageConnectionString string
getAllPageSize int
registryTTL time.Duration
}
func newServerConfig(options ...ServerOption) *serverConfig {
cfg := new(serverConfig)
WithDeletePermanentlyAfter(DefaultDeletePermanentlyAfter)(cfg)
WithStorageType(DefaultStorageType)(cfg)
WithGetAllPageSize(DefaultGetAllPageSize)(cfg)
WithRegistryTTL(DefaultRegistryTTL)(cfg)
for _, option := range options {
option(cfg)
}
return cfg
}
// A ServerOption customizes the server.
type ServerOption func(*serverConfig)
// WithDeletePermanentlyAfter sets the deletePermanentlyAfter duration.
// If a record is deleted via Delete, it will be permanently deleted after
// the given duration.
func WithDeletePermanentlyAfter(dur time.Duration) ServerOption {
return func(cfg *serverConfig) {
cfg.deletePermanentlyAfter = dur
}
}
// WithGetAllPageSize sets the page size for GetAll calls.
func WithGetAllPageSize(pageSize int) ServerOption {
return func(cfg *serverConfig) {
cfg.getAllPageSize = pageSize
}
}
// WithRegistryTTL sets the registry time to live in the config.
func WithRegistryTTL(ttl time.Duration) ServerOption {
return func(cfg *serverConfig) {
cfg.registryTTL = ttl
}
}
// WithGetSharedKey sets the secret in the config.
func WithGetSharedKey(getSharedKey func() ([]byte, error)) ServerOption {
return func(cfg *serverConfig) {
sharedKey, err := getSharedKey()
if err != nil {
log.Error().Err(err).Msgf("shared key is required and must be %d bytes long", cryptutil.DefaultKeySize)
return
}
cfg.secret = sharedKey
}
}
// WithStorageType sets the storage type.
func WithStorageType(typ string) ServerOption {
return func(cfg *serverConfig) {
cfg.storageType = typ
}
}
// WithStorageConnectionString sets the DSN for storage.
func WithStorageConnectionString(connStr string) ServerOption {
return func(cfg *serverConfig) {
cfg.storageConnectionString = connStr
}
}