Skip to content

Commit

Permalink
feat: renamed config options with prefixes; added aliases for old names
Browse files Browse the repository at this point in the history
* secret-is-base64 -> jwt-secret-is-base64
* role-claim-key -> jwt-role-claim-key
* max-rows -> db-max-rows
* pre-request -> db-pre-request
* root-spec -> db-root-spec
* db-schema -> db-schemas

This is not a breaking change, because aliases are added as well.

refactor: sorted all config keys alphabetically where applicable
  • Loading branch information
wolfgangwalther committed Dec 6, 2020
1 parent ab33759 commit ed58511
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 223 deletions.
16 changes: 8 additions & 8 deletions main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import System.IO (BufferMode (..), hSetBuffering)

import PostgREST.App (postgrest)
import PostgREST.Config (AppConfig (..), CLI (..), Command (..),
configPoolTimeout', dumpAppConfig,
configDbPoolTimeout', dumpAppConfig,
prettyVersion, readCLIShowHelp,
readValidateConfig)
import PostgREST.DbStructure (getDbStructure, getPgVersion)
Expand Down Expand Up @@ -68,11 +68,11 @@ main = do

-- These are config values that can't be reloaded at runtime. Reloading some of them would imply restarting the web server.
let
host = configHost conf
port = configPort conf
maybeSocketAddr = configSocket conf
host = configServerHost conf
port = configServerPort conf
maybeSocketAddr = configServerUnixSocket conf
#ifndef mingw32_HOST_OS
socketFileMode = configSocketMode conf
socketFileMode = configServerUnixSocketMode conf
#endif
dbUri = toS (configDbUri conf)
(dbChannelEnabled, dbChannel) = (configDbChannelEnabled conf, toS $ configDbChannel conf)
Expand All @@ -81,8 +81,8 @@ main = do
. setPort port
. setServerName (toS $ "postgrest/" <> prettyVersion) $
defaultSettings
poolSize = configPoolSize conf
poolTimeout = configPoolTimeout' conf
poolSize = configDbPoolSize conf
poolTimeout = configDbPoolTimeout' conf
logLevel = configLogLevel conf

-- create connection pool with the provided settings, returns either a 'Connection' or a 'ConnectionError'. Does not throw.
Expand Down Expand Up @@ -248,7 +248,7 @@ connectionStatus pool =
fillSchemaCache :: P.Pool -> PgVersion -> IORef AppConfig -> IORef (Maybe DbStructure) -> IO ()
fillSchemaCache pool actualPgVersion refConf refDbStructure = do
conf <- readIORef refConf
result <- P.use pool $ HT.transaction HT.ReadCommitted HT.Read $ getDbStructure (toList $ configSchemas conf) (configExtraSearchPath conf) actualPgVersion (configDbPrepared conf)
result <- P.use pool $ HT.transaction HT.ReadCommitted HT.Read $ getDbStructure (toList $ configDbSchemas conf) (configDbExtraSearchPath conf) actualPgVersion (configDbPreparedStatements conf)
case result of
Left e -> do
-- If this error happens it would mean the connection is down again. Improbable because connectionStatus ensured the connection.
Expand Down
20 changes: 10 additions & 10 deletions src/PostgREST/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ postgrest logLev refConf refDbStructure pool getTime connWorker =
Nothing -> respond . errorResponseFor $ ConnectionLostError
Just dbStructure -> do
response <- do
let apiReq = userApiRequest (configSchemas conf) (configRootSpec conf) dbStructure req body
let apiReq = userApiRequest (configDbSchemas conf) (configDbRootSpec conf) dbStructure req body
case apiReq of
Left err -> return . errorResponseFor $ err
Right apiRequest -> do
-- The jwt must be checked before touching the db.
attempt <- attemptJwtClaims (configJWKS conf) (configJwtAudience conf) (toS $ iJWT apiRequest) time (rightToMaybe $ configRoleClaimKey conf)
attempt <- attemptJwtClaims (configJWKS conf) (configJwtAudience conf) (toS $ iJWT apiRequest) time (rightToMaybe $ configJwtRoleClaimKey conf)
case jwtClaims attempt of
Left errJwt -> return . errorResponseFor $ errJwt
Right claims -> do
let
authed = containsRole claims
shouldCommit = configTxAllowOverride conf && iPreferTransaction apiRequest == Just Commit
shouldRollback = configTxAllowOverride conf && iPreferTransaction apiRequest == Just Rollback
shouldCommit = configDbTxAllowOverride conf && iPreferTransaction apiRequest == Just Commit
shouldRollback = configDbTxAllowOverride conf && iPreferTransaction apiRequest == Just Rollback
preferenceApplied
| shouldCommit = addHeadersIfNotIncluded [(hPreferenceApplied, BS.pack (show Commit))]
| shouldRollback = addHeadersIfNotIncluded [(hPreferenceApplied, BS.pack (show Rollback))]
| otherwise = identity
handleReq = do
when (shouldRollback || (configTxRollbackAll conf && not shouldCommit)) HT.condemn
when (shouldRollback || (configDbTxRollbackAll conf && not shouldCommit)) HT.condemn
mapResponseHeaders preferenceApplied <$> runPgLocals conf claims (app dbStructure conf) apiRequest
dbResp <- P.use pool $ HT.transaction HT.ReadCommitted (txMode apiRequest) handleReq
return $ either (errorResponseFor . PgError authed) identity dbResp
Expand Down Expand Up @@ -320,9 +320,9 @@ app dbStructure conf apiRequest =
return $ responseLBS status headers rBody

(ActionInspect headersOnly, TargetDefaultSpec tSchema) -> do
let host = configHost conf
port = toInteger $ configPort conf
proxy = pickProxy $ toS <$> configOpenAPIProxyUri conf
let host = configServerHost conf
port = toInteger $ configServerPort conf
proxy = pickProxy $ toS <$> configOpenApiServerProxyUri conf
uri Nothing = ("http", host, port, "/")
uri (Just Proxy { proxyScheme = s, proxyHost = h, proxyPort = p, proxyPath = b }) = (s, h, p, b)
uri' = uri proxy
Expand All @@ -340,8 +340,8 @@ app dbStructure conf apiRequest =

where
notFound = responseLBS status404 [] ""
maxRows = configMaxRows conf
prepared = configDbPrepared conf
maxRows = configDbMaxRows conf
prepared = configDbPreparedStatements conf
exactCount = iPreferCount apiRequest == Just ExactCount
estimatedCount = iPreferCount apiRequest == Just EstimatedCount
plannedCount = iPreferCount apiRequest == Just PlannedCount
Expand Down
Loading

0 comments on commit ed58511

Please sign in to comment.