feat: renamed config options with prefixes; added aliases for old names

* 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
This commit is contained in:
Wolfgang Walther
2020-12-06 21:59:03 +01:00
committed by Wolfgang Walther
parent ab3375998d
commit ed58511de3
21 changed files with 269 additions and 224 deletions
+2 -2
View File
@@ -63,7 +63,7 @@ main = do
actualPgVersion <- either (panic.show) id <$> P.use pool getPgVersion
refDbStructure <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ testCfg testDbConn) (configExtraSearchPath $ testCfg testDbConn) actualPgVersion
refDbStructure <- (newIORef . Just) =<< setupDbStructure pool (configDbSchemas $ testCfg testDbConn) (configDbExtraSearchPath $ testCfg testDbConn) actualPgVersion
let
-- For tests that run with the same refDbStructure
@@ -73,7 +73,7 @@ main = do
-- For tests that run with a different DbStructure(depends on configSchemas)
appDbs cfg = do
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) (configExtraSearchPath $ cfg testDbConn) actualPgVersion
dbs <- (newIORef . Just) =<< setupDbStructure pool (configDbSchemas $ cfg testDbConn) (configDbExtraSearchPath $ cfg testDbConn) actualPgVersion
refConf <- newIORef $ cfg testDbConn
return ((), postgrest LogCrit refConf dbs pool getTime $ pure ())
+37 -37
View File
@@ -66,55 +66,55 @@ getEnvVarWithDefault var def = toS <$>
_baseCfg :: AppConfig
_baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
AppConfig {
configDbUri = mempty
, configAnonRole = "postgrest_test_anonymous"
, configOpenAPIProxyUri = Nothing
, configSchemas = fromList ["test"]
, configHost = "localhost"
, configPort = 3000
, configSocket = Nothing
, configSocketMode = Right 432
, configDbChannel = mempty
, configDbChannelEnabled = False
, configJwtSecret = secret
, configJwtSecretIsBase64 = False
, configJwtAudience = Nothing
, configPoolSize = 10
, configPoolTimeout = 10
, configMaxRows = Nothing
, configPreReq = Just "test.switch_role"
, configSettings = [ ("app.settings.app_host", "localhost") , ("app.settings.external_api_secret", "0123456789abcdef") ]
, configRoleClaimKey = Right [JSPKey "role"]
, configExtraSearchPath = []
, configRootSpec = Nothing
, configRawMediaTypes = []
, configJWKS = parseSecret <$> secret
, configLogLevel = LogCrit
, configTxRollbackAll = True
, configTxAllowOverride = True
, configDbPrepared = True
configAppSettings = [ ("app.settings.app_host", "localhost") , ("app.settings.external_api_secret", "0123456789abcdef") ]
, configDbAnonRole = "postgrest_test_anonymous"
, configDbChannel = mempty
, configDbChannelEnabled = False
, configDbExtraSearchPath = []
, configDbMaxRows = Nothing
, configDbPoolSize = 10
, configDbPoolTimeout = 10
, configDbPreRequest = Just "test.switch_role"
, configDbPreparedStatements = True
, configDbRootSpec = Nothing
, configDbSchemas = fromList ["test"]
, configDbUri = mempty
, configJWKS = parseSecret <$> secret
, configJwtAudience = Nothing
, configJwtRoleClaimKey = Right [JSPKey "role"]
, configJwtSecret = secret
, configJwtSecretIsBase64 = False
, configLogLevel = LogCrit
, configOpenApiServerProxyUri = Nothing
, configRawMediaTypes = []
, configServerHost = "localhost"
, configServerPort = 3000
, configServerUnixSocket = Nothing
, configServerUnixSocketMode = Right 432
, configDbTxAllowOverride = True
, configDbTxRollbackAll = True
}
testCfg :: Text -> AppConfig
testCfg testDbConn = _baseCfg { configDbUri = testDbConn }
testCfgDisallowRollback :: Text -> AppConfig
testCfgDisallowRollback testDbConn = (testCfg testDbConn) { configTxRollbackAll = False, configTxAllowOverride = False }
testCfgDisallowRollback testDbConn = (testCfg testDbConn) { configDbTxAllowOverride = False, configDbTxRollbackAll = False }
testCfgForceRollback :: Text -> AppConfig
testCfgForceRollback testDbConn = (testCfg testDbConn) { configTxRollbackAll = True, configTxAllowOverride = False }
testCfgForceRollback testDbConn = (testCfg testDbConn) { configDbTxAllowOverride = False, configDbTxRollbackAll = True }
testCfgNoJWT :: Text -> AppConfig
testCfgNoJWT testDbConn = (testCfg testDbConn) { configJwtSecret = Nothing, configJWKS = Nothing }
testUnicodeCfg :: Text -> AppConfig
testUnicodeCfg testDbConn = (testCfg testDbConn) { configSchemas = fromList ["تست"] }
testUnicodeCfg testDbConn = (testCfg testDbConn) { configDbSchemas = fromList ["تست"] }
testMaxRowsCfg :: Text -> AppConfig
testMaxRowsCfg testDbConn = (testCfg testDbConn) { configMaxRows = Just 2 }
testMaxRowsCfg testDbConn = (testCfg testDbConn) { configDbMaxRows = Just 2 }
testProxyCfg :: Text -> AppConfig
testProxyCfg testDbConn = (testCfg testDbConn) { configOpenAPIProxyUri = Just "https://postgrest.com/openapi.json" }
testProxyCfg testDbConn = (testCfg testDbConn) { configOpenApiServerProxyUri = Just "https://postgrest.com/openapi.json" }
testCfgBinaryJWT :: Text -> AppConfig
testCfgBinaryJWT testDbConn =
@@ -150,22 +150,22 @@ testCfgAsymJWKSet testDbConn =
}
testNonexistentSchemaCfg :: Text -> AppConfig
testNonexistentSchemaCfg testDbConn = (testCfg testDbConn) { configSchemas = fromList ["nonexistent"] }
testNonexistentSchemaCfg testDbConn = (testCfg testDbConn) { configDbSchemas = fromList ["nonexistent"] }
testCfgExtraSearchPath :: Text -> AppConfig
testCfgExtraSearchPath testDbConn = (testCfg testDbConn) { configExtraSearchPath = ["public", "extensions"] }
testCfgExtraSearchPath testDbConn = (testCfg testDbConn) { configDbExtraSearchPath = ["public", "extensions"] }
testCfgRootSpec :: Text -> AppConfig
testCfgRootSpec testDbConn = (testCfg testDbConn) { configRootSpec = Just "root"}
testCfgRootSpec testDbConn = (testCfg testDbConn) { configDbRootSpec = Just "root"}
testCfgHtmlRawOutput :: Text -> AppConfig
testCfgHtmlRawOutput testDbConn = (testCfg testDbConn) { configRawMediaTypes = ["text/html"] }
testCfgResponseHeaders :: Text -> AppConfig
testCfgResponseHeaders testDbConn = (testCfg testDbConn) { configPreReq = Just "custom_headers" }
testCfgResponseHeaders testDbConn = (testCfg testDbConn) { configDbPreRequest = Just "custom_headers" }
testMultipleSchemaCfg :: Text -> AppConfig
testMultipleSchemaCfg testDbConn = (testCfg testDbConn) { configSchemas = fromList ["v1", "v2"] }
testMultipleSchemaCfg testDbConn = (testCfg testDbConn) { configDbSchemas = fromList ["v1", "v2"] }
resetDb :: Text -> IO ()
resetDb dbConn = loadFixture dbConn "data"
+4 -4
View File
@@ -316,17 +316,17 @@ checkDbSchemaReload(){
# wait for the server to start
sleep 0.1
done
# add v1 schema to db-schema
replaceConfigValue "db-schema" "test, v1" "$configFile"
# add v1 schema to db-schemas
replaceConfigValue "db-schemas" "test, v1" "$configFile"
# reload
kill -s SIGUSR2 $pgrPID
kill -s SIGUSR1 $pgrPID
httpStatus="$(v1SchemaParentsStatus)"
if test "$httpStatus" -eq 200
then
ok "db-schema config reloaded with SIGUSR2"
ok "db-schemas config reloaded with SIGUSR2"
else
ko "db-schema config not reloaded with SIGUSR2. Got: $httpStatus"
ko "db-schemas config not reloaded with SIGUSR2. Got: $httpStatus"
fi
pgrStop
}
+9
View File
@@ -0,0 +1,9 @@
db-anon-role = "required"
db-uri = "required"
db-schema = "provided_through_alias"
max-rows = 1000
pre-request = "check_alias"
role-claim-key = ".aliased"
root-spec = "open_alias"
secret-is-base64 = true
+1 -1
View File
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
db-pool-timeout = 1
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
@@ -7,4 +7,4 @@ server-port = 49421
# Read secret from a file: /dev/stdin (alias for standard input)
jwt-secret = "@/dev/stdin"
secret-is-base64 = true
jwt-secret-is-base64 = true
+1 -1
View File
@@ -1,5 +1,5 @@
db-uri = "@/dev/stdin"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
+1 -1
View File
@@ -1,3 +1,3 @@
db-uri = "required"
db-schema = "required"
db-schemas = "required"
db-anon-role = "required"
@@ -0,0 +1,24 @@
db-anon-role = "required"
db-channel = "pgrst"
db-channel-enabled = false
db-extra-search-path = "public"
db-max-rows = 1000
db-pool = 10
db-pool-timeout = 10
db-pre-request = "check_alias"
db-prepared-statements = true
db-root-spec = "open_alias"
db-schemas = "provided_through_alias"
db-tx-end = "commit"
db-uri = "required"
jwt-aud = ""
jwt-role-claim-key = ".\"aliased\""
jwt-secret = ""
jwt-secret-is-base64 = true
log-level = "error"
openapi-server-proxy-uri = ""
raw-media-types = ""
server-host = "!4"
server-port = 3000
server-unix-socket = ""
server-unix-socket-mode = "660"
+16 -16
View File
@@ -1,24 +1,24 @@
db-uri = "required"
db-schema = "required"
db-anon-role = "required"
db-pool = 10
db-pool-timeout = 10
db-extra-search-path = "public"
db-channel = "pgrst"
db-channel-enabled = false
db-tx-end = "commit"
db-extra-search-path = "public"
db-max-rows = ""
db-pool = 10
db-pool-timeout = 10
db-pre-request = ""
db-prepared-statements = true
db-root-spec = ""
db-schemas = "required"
db-tx-end = "commit"
db-uri = "required"
jwt-aud = ""
jwt-role-claim-key = ".\"role\""
jwt-secret = ""
jwt-secret-is-base64 = false
log-level = "error"
openapi-server-proxy-uri = ""
raw-media-types = ""
server-host = "!4"
server-port = 3000
server-unix-socket = ""
server-unix-socket-mode = "660"
openapi-server-proxy-uri = ""
jwt-secret = ""
jwt-aud = ""
secret-is-base64 = false
role-claim-key = ".\"role\""
max-rows = ""
pre-request = ""
root-spec = ""
raw-media-types = ""
log-level = "error"
@@ -1,26 +1,26 @@
db-uri = "tmp_db"
db-schema = "multi,tenant,setup"
db-anon-role = "root"
db-pool = 1
db-pool-timeout = 100
db-extra-search-path = "public,test"
db-channel = "postgrest"
db-channel-enabled = true
db-tx-end = "rollback-allow-override"
db-extra-search-path = "public,test"
db-max-rows = 1000
db-pool = 1
db-pool-timeout = 100
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
db-schemas = "multi,tenant,setup"
db-tx-end = "rollback-allow-override"
db-uri = "tmp_db"
jwt-aud = "https://postgrest.org"
jwt-role-claim-key = ".\"user\"[0].\"real-role\""
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
jwt-secret-is-base64 = true
log-level = "info"
openapi-server-proxy-uri = "https://postgrest.org"
raw-media-types = "application/vnd.pgrst.config"
server-host = "0.0.0.0"
server-port = 80
server-unix-socket = "/tmp/pgrst_io_test.sock"
server-unix-socket-mode = "777"
openapi-server-proxy-uri = "https://postgrest.org"
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
jwt-aud = "https://postgrest.org"
secret-is-base64 = true
role-claim-key = ".\"user\"[0].\"real-role\""
max-rows = 1000
pre-request = "please_run_fast"
root-spec = "openapi_v3"
raw-media-types = "application/vnd.pgrst.config"
log-level = "info"
app.settings.test = "test"
app.settings.test2 = "test"
+16 -16
View File
@@ -1,26 +1,26 @@
db-uri = "tmp_db"
db-schema = "multi, tenant,setup"
db-anon-role = "root"
db-pool = 1
db-pool-timeout = 100
db-extra-search-path = "public, test"
db-channel = "postgrest"
db-channel-enabled = true
db-tx-end = "rollback-allow-override"
db-extra-search-path = "public, test"
db-max-rows = 1000
db-pool = 1
db-pool-timeout = 100
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
db-schemas = "multi, tenant,setup"
db-tx-end = "rollback-allow-override"
db-uri = "tmp_db"
jwt-aud = "https://postgrest.org"
jwt-role-claim-key = ".user[0].\"real-role\""
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
jwt-secret-is-base64 = true
log-level = "info"
openapi-server-proxy-uri = "https://postgrest.org"
raw-media-types = "application/vnd.pgrst.config"
server-host = "0.0.0.0"
server-port = 80
server-unix-socket = "/tmp/pgrst_io_test.sock"
server-unix-socket-mode = "777"
openapi-server-proxy-uri = "https://postgrest.org"
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
jwt-aud = "https://postgrest.org"
secret-is-base64 = true
role-claim-key = ".user[0].\"real-role\""
max-rows = 1000
pre-request = "please_run_fast"
root-spec = "openapi_v3"
raw-media-types = "application/vnd.pgrst.config"
log-level = "info"
app.settings.test = "test"
app.settings.test2 = "test"
+2 -2
View File
@@ -1,8 +1,8 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
server-port = 49421
role-claim-key = "$(ROLE_CLAIM_KEY)"
jwt-role-claim-key = "$(ROLE_CLAIM_KEY)"
jwt-secret = "reallyreallyreallyreallyverysafe"
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
@@ -7,4 +7,4 @@ server-port = 49421
# Read secret from a file: /dev/stdin (alias for standard input)
jwt-secret = "@/dev/stdin"
secret-is-base64 = false
jwt-secret-is-base64 = false
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
+1 -1
View File
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"
+1 -1
View File
@@ -1,5 +1,5 @@
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-schemas = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
server-host = "127.0.0.1"