{-# 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
, 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 Text
key =
Config
{ $sel:key:Config :: Text
key = Text
key
, $sel:baseURI:Config :: Text
baseURI = Text
"https://sdk.launchdarkly.com"
, $sel:streamURI:Config :: Text
streamURI = Text
"https://stream.launchdarkly.com"
, $sel:eventsURI:Config :: Text
eventsURI = Text
"https://events.launchdarkly.com"
, $sel:storeBackend:Config :: Maybe PersistentDataStore
storeBackend = forall a. Maybe a
Nothing
, $sel:storeTTLSeconds:Config :: Natural
storeTTLSeconds = Natural
10
, $sel:streaming:Config :: Bool
streaming = Bool
True
, $sel:initialRetryDelay:Config :: Int
initialRetryDelay = Int
1_000
, $sel:allAttributesPrivate:Config :: Bool
allAttributesPrivate = Bool
False
, $sel:privateAttributeNames:Config :: Set Reference
privateAttributeNames = forall a. Monoid a => a
mempty
, $sel:flushIntervalSeconds:Config :: Natural
flushIntervalSeconds = Natural
5
, $sel:pollIntervalSeconds:Config :: Natural
pollIntervalSeconds = Natural
30
, $sel:contextKeyLRUCapacity:Config :: Natural
contextKeyLRUCapacity = Natural
1_000
, $sel:eventsCapacity:Config :: Natural
eventsCapacity = Natural
10_000
, $sel:logger:Config :: LoggingT IO () -> IO ()
logger = 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 = Natural
30
, $sel:useLdd:Config :: Bool
useLdd = Bool
False
, $sel:dataSourceFactory:Config :: Maybe DataSourceFactory
dataSourceFactory = forall a. Maybe a
Nothing
, $sel:manager:Config :: Maybe Manager
manager = forall a. Maybe a
Nothing
, $sel:applicationInfo:Config :: Maybe ApplicationInfo
applicationInfo = forall a. Maybe a
Nothing
}
configSetKey :: Text -> Config -> Config
configSetKey :: Text -> Config -> Config
configSetKey = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"key"
configSetBaseURI :: Text -> Config -> Config
configSetBaseURI :: Text -> Config -> Config
configSetBaseURI = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"baseURI" forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (forall a. Eq a => a -> a -> Bool
(==) Char
'/')
configSetStreamURI :: Text -> Config -> Config
configSetStreamURI :: Text -> Config -> Config
configSetStreamURI = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"streamURI" forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (forall a. Eq a => a -> a -> Bool
(==) Char
'/')
configSetEventsURI :: Text -> Config -> Config
configSetEventsURI :: Text -> Config -> Config
configSetEventsURI = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"eventsURI" forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
dropWhileEnd (forall a. Eq a => a -> a -> Bool
(==) Char
'/')
configSetStoreBackend :: Maybe PersistentDataStore -> Config -> Config
configSetStoreBackend :: Maybe PersistentDataStore -> Config -> Config
configSetStoreBackend = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"storeBackend"
configSetStoreTTL :: Natural -> Config -> Config
configSetStoreTTL :: Natural -> Config -> Config
configSetStoreTTL = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"storeTTLSeconds"
configSetStreaming :: Bool -> Config -> Config
configSetStreaming :: Bool -> Config -> Config
configSetStreaming = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"streaming"
configSetInitialRetryDelay :: Int -> Config -> Config
configSetInitialRetryDelay :: Int -> Config -> Config
configSetInitialRetryDelay Int
seconds Config
config
| Int
seconds forall a. Ord a => a -> a -> Bool
<= Int
0 = Config
config
| Bool
otherwise = 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 (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 (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"privateAttributeNames"
configSetFlushIntervalSeconds :: Natural -> Config -> Config
configSetFlushIntervalSeconds :: Natural -> Config -> Config
configSetFlushIntervalSeconds = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"flushIntervalSeconds"
configSetPollIntervalSeconds :: Natural -> Config -> Config
configSetPollIntervalSeconds :: Natural -> Config -> Config
configSetPollIntervalSeconds = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"pollIntervalSeconds"
configSetContextKeyLRUCapacity :: Natural -> Config -> Config
configSetContextKeyLRUCapacity :: Natural -> Config -> Config
configSetContextKeyLRUCapacity = 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 (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 (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"logger"
configSetSendEvents :: Bool -> Config -> Config
configSetSendEvents :: Bool -> Config -> Config
configSetSendEvents = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"sendEvents"
configSetOffline :: Bool -> Config -> Config
configSetOffline :: Bool -> Config -> Config
configSetOffline = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"offline"
configSetRequestTimeoutSeconds :: Natural -> Config -> Config
configSetRequestTimeoutSeconds :: Natural -> Config -> Config
configSetRequestTimeoutSeconds = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"requestTimeoutSeconds"
configSetUseLdd :: Bool -> Config -> Config
configSetUseLdd :: Bool -> Config -> Config
configSetUseLdd = 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 (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"dataSourceFactory"
configSetManager :: Manager -> Config -> Config
configSetManager :: Manager -> Config -> Config
configSetManager = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"manager" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just
configSetApplicationInfo :: ApplicationInfo -> Config -> Config
configSetApplicationInfo :: ApplicationInfo -> Config -> Config
configSetApplicationInfo = forall (f :: Symbol) s a. HasField' f s a => a -> s -> s
setField @"applicationInfo" forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just