{-# LANGUAGE NumericUnderscores #-}
module LaunchDarkly.Server.Config
( Config
, makeConfig
, configSetKey
, configSetBaseURI
, configSetStreamURI
, configSetEventsURI
, configSetStreaming
, configSetInitialRetryDelay
, configSetAllAttributesPrivate
, configSetPrivateAttributeNames
, configSetFlushIntervalSeconds
, configSetPollIntervalSeconds
, configSetContextKeyLRUCapacity
, configSetUserKeyLRUCapacity
, configSetEventsCapacity
, configSetLogger
, configSetManager
, configSetSendEvents
, configSetOffline
, configSetRequestTimeoutSeconds
, configSetStoreBackend
, configSetStoreTTL
, configSetUseLdd
, configSetDataSourceFactory
, configSetApplicationInfo
, configSetOmitAnonymousContexts
, ApplicationInfo
, makeApplicationInfo
, withApplicationValue
) where
import Control.Monad.Logger (LoggingT, runStdoutLoggingT)
import Data.Generics.Product (setField)
import Data.Set (Set)
import Data.Text (Text, dropWhileEnd)
import GHC.Natural (Natural)
import Network.HTTP.Client (Manager)
import LaunchDarkly.Server.Config.Internal (ApplicationInfo, Config (..), makeApplicationInfo, withApplicationValue)
import LaunchDarkly.Server.DataSource.Internal (DataSourceFactory)
import LaunchDarkly.Server.Reference (Reference)
import LaunchDarkly.Server.Store (PersistentDataStore)
makeConfig :: Text -> Config
makeConfig :: Text -> Config
makeConfig key :: Text
key =
$WConfig :: Text
-> Text
-> Text
-> Text
-> Maybe PersistentDataStore
-> Natural
-> Bool
-> Int
-> Bool
-> Set Reference
-> Natural
-> Natural
-> Natural
-> Natural
-> (LoggingT IO () -> IO ())
-> Bool
-> Bool
-> Natural
-> Bool
-> Maybe DataSourceFactory
-> Maybe Manager
-> Maybe ApplicationInfo
-> Bool
-> Config
Config
{ $sel:key:Config :: Text
key = Text
key
, $sel:baseURI:Config :: Text
baseURI = "https://sdk.launchdarkly.com"
, $sel:streamURI:Config :: Text
streamURI = "https://stream.launchdarkly.com"
, $sel:eventsURI:Config :: Text
eventsURI = "https://events.launchdarkly.com"
, $sel:storeBackend:Config :: Maybe PersistentDataStore
storeBackend = Maybe PersistentDataStore
forall a. Maybe a
Nothing
, $sel:storeTTLSeconds:Config :: Natural
storeTTLSeconds = 10
, $sel:streaming:Config :: Bool
streaming = Bool
True
, $sel:initialRetryDelay:Config :: Int
initialRetryDelay = 1_000
, $sel:allAttributesPrivate:Config :: Bool
allAttributesPrivate = Bool
False
, $sel:privateAttributeNames:Config :: Set Reference
privateAttributeNames = Set Reference
forall a. Monoid a => a
mempty
, $sel:flushIntervalSeconds:Config :: Natural
flushIntervalSeconds = 5
, $sel:pollIntervalSeconds:Config :: Natural
pollIntervalSeconds = 30
, $sel:contextKeyLRUCapacity:Config :: Natural
contextKeyLRUCapacity = 1_000
, $sel:eventsCapacity:Config :: Natural
eventsCapacity = 10_000
, $sel:logger:Config :: LoggingT IO () -> IO ()
logger = LoggingT IO () -> IO ()
forall (m :: * -> *) a. MonadIO m => LoggingT m a -> m a
runStdoutLoggingT
, $sel:sendEvents:Config :: Bool
sendEvents = Bool
True
, $sel:offline:Config :: Bool
offline = Bool
False
, $sel:requestTimeoutSeconds:Config :: Natural
requestTimeoutSeconds = 30
, $sel:useLdd:Config :: Bool
useLdd = Bool
False
, $sel:dataSourceFactory:Config :: Maybe DataSourceFactory
dataSourceFactory = Maybe DataSourceFactory
forall a. Maybe a
Nothing
, $sel:manager:Config :: Maybe Manager
manager = Maybe Manager
forall a. Maybe a
Nothing
, $sel:applicationInfo:Config :: Maybe ApplicationInfo
applicationInfo = Maybe ApplicationInfo
forall a. Maybe a
Nothing
, $sel:omitAnonymousContexts:Config :: Bool
omitAnonymousContexts = Bool
False
}
configSetKey :: Text -> Config -> Config
configSetKey :: Text -> Config -> Config
configSetKey = forall s a. HasField' "key" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"key"
configSetBaseURI :: Text -> Config -> Config
configSetBaseURI :: Text -> Config -> Config
configSetBaseURI = forall s a. HasField' "baseURI" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"baseURI" (Text -> Config -> Config)
-> (Text -> Text) -> Text -> Config -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
(==) '/')
configSetStreamURI :: Text -> Config -> Config
configSetStreamURI :: Text -> Config -> Config
configSetStreamURI = forall s a. HasField' "streamURI" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"streamURI" (Text -> Config -> Config)
-> (Text -> Text) -> Text -> Config -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
(==) '/')
configSetEventsURI :: Text -> Config -> Config
configSetEventsURI :: Text -> Config -> Config
configSetEventsURI = forall s a. HasField' "eventsURI" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"eventsURI" (Text -> Config -> Config)
-> (Text -> Text) -> Text -> Config -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
(==) '/')
configSetStoreBackend :: Maybe PersistentDataStore -> Config -> Config
configSetStoreBackend :: Maybe PersistentDataStore -> Config -> Config
configSetStoreBackend = forall s a. HasField' "storeBackend" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"storeBackend"
configSetStoreTTL :: Natural -> Config -> Config
configSetStoreTTL :: Natural -> Config -> Config
configSetStoreTTL = forall s a. HasField' "storeTTLSeconds" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"storeTTLSeconds"
configSetStreaming :: Bool -> Config -> Config
configSetStreaming :: Bool -> Config -> Config
configSetStreaming = forall s a. HasField' "streaming" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"streaming"
configSetInitialRetryDelay :: Int -> Config -> Config
configSetInitialRetryDelay :: Int -> Config -> Config
configSetInitialRetryDelay seconds :: Int
seconds config :: Config
config
| Int
seconds Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = Config
config
| Bool
otherwise = Int -> Config -> Config
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"initialRetryDelay" Int
seconds Config
config
configSetAllAttributesPrivate :: Bool -> Config -> Config
configSetAllAttributesPrivate :: Bool -> Config -> Config
configSetAllAttributesPrivate = forall s a. HasField' "allAttributesPrivate" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"allAttributesPrivate"
configSetPrivateAttributeNames :: Set Reference -> Config -> Config
configSetPrivateAttributeNames :: Set Reference -> Config -> Config
configSetPrivateAttributeNames = forall s a. HasField' "privateAttributeNames" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"privateAttributeNames"
configSetFlushIntervalSeconds :: Natural -> Config -> Config
configSetFlushIntervalSeconds :: Natural -> Config -> Config
configSetFlushIntervalSeconds = forall s a. HasField' "flushIntervalSeconds" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"flushIntervalSeconds"
configSetPollIntervalSeconds :: Natural -> Config -> Config
configSetPollIntervalSeconds :: Natural -> Config -> Config
configSetPollIntervalSeconds = forall s a. HasField' "pollIntervalSeconds" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"pollIntervalSeconds"
configSetContextKeyLRUCapacity :: Natural -> Config -> Config
configSetContextKeyLRUCapacity :: Natural -> Config -> Config
configSetContextKeyLRUCapacity = forall s a. HasField' "contextKeyLRUCapacity" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"contextKeyLRUCapacity"
{-# DEPRECATED configSetUserKeyLRUCapacity "Use configSetContextKeyLRUCapacity instead" #-}
configSetUserKeyLRUCapacity :: Natural -> Config -> Config
configSetUserKeyLRUCapacity :: Natural -> Config -> Config
configSetUserKeyLRUCapacity = Natural -> Config -> Config
configSetContextKeyLRUCapacity
configSetEventsCapacity :: Natural -> Config -> Config
configSetEventsCapacity :: Natural -> Config -> Config
configSetEventsCapacity = forall s a. HasField' "eventsCapacity" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"eventsCapacity"
configSetLogger :: (LoggingT IO () -> IO ()) -> Config -> Config
configSetLogger :: (LoggingT IO () -> IO ()) -> Config -> Config
configSetLogger = forall s a. HasField' "logger" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"logger"
configSetSendEvents :: Bool -> Config -> Config
configSetSendEvents :: Bool -> Config -> Config
configSetSendEvents = forall s a. HasField' "sendEvents" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"sendEvents"
configSetOffline :: Bool -> Config -> Config
configSetOffline :: Bool -> Config -> Config
configSetOffline = forall s a. HasField' "offline" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"offline"
configSetRequestTimeoutSeconds :: Natural -> Config -> Config
configSetRequestTimeoutSeconds :: Natural -> Config -> Config
configSetRequestTimeoutSeconds = forall s a. HasField' "requestTimeoutSeconds" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"requestTimeoutSeconds"
configSetUseLdd :: Bool -> Config -> Config
configSetUseLdd :: Bool -> Config -> Config
configSetUseLdd = forall s a. HasField' "useLdd" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"useLdd"
configSetDataSourceFactory :: Maybe DataSourceFactory -> Config -> Config
configSetDataSourceFactory :: Maybe DataSourceFactory -> Config -> Config
configSetDataSourceFactory = forall s a. HasField' "dataSourceFactory" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"dataSourceFactory"
configSetManager :: Manager -> Config -> Config
configSetManager :: Manager -> Config -> Config
configSetManager = forall s a. HasField' "manager" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"manager" (Maybe Manager -> Config -> Config)
-> (Manager -> Maybe Manager) -> Manager -> Config -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Manager -> Maybe Manager
forall a. a -> Maybe a
Just
configSetApplicationInfo :: ApplicationInfo -> Config -> Config
configSetApplicationInfo :: ApplicationInfo -> Config -> Config
configSetApplicationInfo = forall s a. HasField' "applicationInfo" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"applicationInfo" (Maybe ApplicationInfo -> Config -> Config)
-> (ApplicationInfo -> Maybe ApplicationInfo)
-> ApplicationInfo
-> Config
-> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ApplicationInfo -> Maybe ApplicationInfo
forall a. a -> Maybe a
Just
configSetOmitAnonymousContexts :: Bool -> Config -> Config
configSetOmitAnonymousContexts :: Bool -> Config -> Config
configSetOmitAnonymousContexts = forall s a. HasField' "omitAnonymousContexts" s a => a -> s -> s
forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"omitAnonymousContexts"