module LaunchDarkly.Server.Config
( Config
, makeConfig
, configSetKey
, configSetBaseURI
, configSetStreamURI
, configSetEventsURI
, configSetStreaming
, configSetAllAttributesPrivate
, configSetPrivateAttributeNames
, configSetFlushIntervalSeconds
, configSetPollIntervalSeconds
, configSetUserKeyLRUCapacity
, configSetInlineUsersInEvents
, configSetEventsCapacity
, configSetLogger
, configSetSendEvents
, configSetOffline
, configSetRequestTimeoutSeconds
, configSetStoreBackend
, configSetStoreTTL
, configSetUseLdd
) where
import Control.Monad.Logger (LoggingT, runStdoutLoggingT)
import Data.Generics.Product (setField)
import Data.Set (Set)
import Data.Text (Text)
import Data.Monoid (mempty)
import GHC.Natural (Natural)
import LaunchDarkly.Server.Config.Internal (Config(..), mapConfig, ConfigI(..))
import LaunchDarkly.Server.Store (StoreInterface)
makeConfig :: Text -> Config
makeConfig key = Config $ ConfigI
{ key = key
, baseURI = "https://app.launchdarkly.com"
, streamURI = "https://stream.launchdarkly.com"
, eventsURI = "https://events.launchdarkly.com"
, storeBackend = Nothing
, storeTTLSeconds = 10
, streaming = True
, allAttributesPrivate = False
, privateAttributeNames = mempty
, flushIntervalSeconds = 5
, pollIntervalSeconds = 30
, userKeyLRUCapacity = 1000
, inlineUsersInEvents = False
, eventsCapacity = 10000
, logger = runStdoutLoggingT
, sendEvents = True
, offline = False
, requestTimeoutSeconds = 30
, useLdd = False
}
configSetKey :: Text -> Config -> Config
configSetKey = mapConfig . setField @"key"
configSetBaseURI :: Text -> Config -> Config
configSetBaseURI = mapConfig . setField @"baseURI"
configSetStreamURI :: Text -> Config -> Config
configSetStreamURI = mapConfig . setField @"streamURI"
configSetEventsURI :: Text -> Config -> Config
configSetEventsURI = mapConfig . setField @"eventsURI"
configSetStoreBackend :: Maybe StoreInterface -> Config -> Config
configSetStoreBackend = mapConfig . setField @"storeBackend"
configSetStoreTTL :: Natural -> Config -> Config
configSetStoreTTL = mapConfig . setField @"storeTTLSeconds"
configSetStreaming :: Bool -> Config -> Config
configSetStreaming = mapConfig . setField @"streaming"
configSetAllAttributesPrivate :: Bool -> Config -> Config
configSetAllAttributesPrivate = mapConfig . setField @"allAttributesPrivate"
configSetPrivateAttributeNames :: Set Text -> Config -> Config
configSetPrivateAttributeNames = mapConfig . setField @"privateAttributeNames"
configSetFlushIntervalSeconds :: Natural -> Config -> Config
configSetFlushIntervalSeconds = mapConfig . setField @"flushIntervalSeconds"
configSetPollIntervalSeconds :: Natural -> Config -> Config
configSetPollIntervalSeconds = mapConfig . setField @"pollIntervalSeconds"
configSetUserKeyLRUCapacity :: Natural -> Config -> Config
configSetUserKeyLRUCapacity = mapConfig . setField @"userKeyLRUCapacity"
configSetInlineUsersInEvents :: Bool -> Config -> Config
configSetInlineUsersInEvents = mapConfig . setField @"inlineUsersInEvents"
configSetEventsCapacity :: Natural -> Config -> Config
configSetEventsCapacity = mapConfig . setField @"eventsCapacity"
configSetLogger :: (LoggingT IO () -> IO ()) -> Config -> Config
configSetLogger = mapConfig . setField @"logger"
configSetSendEvents :: Bool -> Config -> Config
configSetSendEvents = mapConfig . setField @"sendEvents"
configSetOffline :: Bool -> Config -> Config
configSetOffline = mapConfig . setField @"offline"
configSetRequestTimeoutSeconds :: Natural -> Config -> Config
configSetRequestTimeoutSeconds = mapConfig . setField @"requestTimeoutSeconds"
configSetUseLdd :: Bool -> Config -> Config
configSetUseLdd = mapConfig . setField @"useLdd"