refactor: move parseSecret out of App.postgrest

parseSecret only needs to be computed once, after the config is read.
This commit is contained in:
steve-chavez
2020-07-13 11:30:16 -05:00
committed by Steve Chavez
parent 96a16a377f
commit 0ff05edd16
5 changed files with 43 additions and 30 deletions
+5 -4
View File
@@ -29,6 +29,7 @@ module PostgREST.Config ( prettyVersion
)
where
import Crypto.JWT (JWKSet)
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as BS
@@ -97,7 +98,7 @@ data AppConfig = AppConfig {
, configRootSpec :: Maybe Text
, configRawMediaTypes :: [B.ByteString]
, configPath :: Maybe FilePath
, configJWKS :: Maybe JWKSet
}
configPoolTimeout' :: (Fractional a) => AppConfig -> a
@@ -230,14 +231,14 @@ readAppConfig cfgPath = do
, Handler (\(C.ParseError err) -> exitErr $ "Error parsing config file:\n" <> err)
]
case C.runParser (parseConfig cfgPath) conf of
case C.runParser parseConfig conf of
Left err ->
exitErr $ "Error parsing config file:\n\t" <> err
Right appConf ->
return appConf
where
parseConfig path =
parseConfig =
AppConfig
<$> reqString "db-uri"
<*> reqString "db-anon-role"
@@ -262,7 +263,7 @@ readAppConfig cfgPath = do
<*> (maybe ["public"] splitOnCommas <$> optValue "db-extra-search-path")
<*> optString "root-spec"
<*> (maybe [] (fmap encodeUtf8 . splitOnCommas) <$> optValue "raw-media-types")
<*> pure (Just path)
<*> pure Nothing
parseSocketFileMode :: C.Key -> C.Parser C.Config (Either Text FileMode)
parseSocketFileMode k =