Skip to content

Commit

Permalink
make in-db config work and change config name
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Nov 23, 2023
1 parent 8b79806 commit 5e3eb97
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/PostgREST/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ toText conf =
where
-- apply conf to all pgrst settings
pgrstSettings = (\(k, v) -> (k, v conf)) <$>
[("db-aggregates", T.toLower . show . configDbAggregates)
[("db-aggregates-enabled", T.toLower . show . configDbAggregates)
,("db-anon-role", q . T.decodeUtf8 . fromMaybe "" . configDbAnonRole)
,("db-channel", q . configDbChannel)
,("db-channel-enabled", T.toLower . show . configDbChannelEnabled)
Expand Down Expand Up @@ -232,7 +232,7 @@ parser :: Maybe FilePath -> Environment -> [(Text, Text)] -> RoleSettings -> Rol
parser optPath env dbSettings roleSettings roleIsolationLvl =
AppConfig
<$> parseAppSettings "app.settings"
<*> (fromMaybe False <$> optBool "db-aggregates")
<*> (fromMaybe False <$> optBool "db-aggregates-enabled")
<*> (fmap encodeUtf8 <$> optString "db-anon-role")
<*> (fromMaybe "pgrst" <$> optString "db-channel")
<*> (fromMaybe True <$> optBool "db-channel-enabled")
Expand Down
3 changes: 2 additions & 1 deletion src/PostgREST/Config/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ prefix = "pgrst."
dbSettingsNames :: [Text]
dbSettingsNames =
(prefix <>) <$>
["db_anon_role"
["db_aggregates_enabled"
,"db_anon_role"
,"db_pre_config"
,"db_extra_search_path"
,"db_max_rows"
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/aliases.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = false
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
db-channel-enabled = true
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/boolean-numeric.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = false
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
db-channel-enabled = true
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/boolean-string.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = false
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
db-channel-enabled = true
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/defaults.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = false
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
db-channel-enabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = true
db-aggregates-enabled = false
db-anon-role = "pre_config_role"
db-channel = "postgrest"
db-channel-enabled = false
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/no-defaults-with-db.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = true
db-aggregates-enabled = false
db-anon-role = "anonymous"
db-channel = "postgrest"
db-channel-enabled = false
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/no-defaults.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = true
db-aggregates-enabled = true
db-anon-role = "root"
db-channel = "postgrest"
db-channel-enabled = false
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/expected/types.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = false
db-aggregates-enabled = false
db-anon-role = ""
db-channel = "pgrst"
db-channel-enabled = true
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/no-defaults-env.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PGRST_APP_SETTINGS_test2: test
PGRST_APP_SETTINGS_test: test
PGRST_DB_AGGREGATES: true
PGRST_DB_AGGREGATES_ENABLED: true
PGRST_DB_ANON_ROLE: root
PGRST_DB_CHANNEL: postgrest
PGRST_DB_CHANNEL_ENABLED: false
Expand Down
2 changes: 1 addition & 1 deletion test/io/configs/no-defaults.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db-aggregates = true
db-aggregates-enabled = true
db-anon-role = "root"
db-channel = "postgrest"
db-channel-enabled = false
Expand Down
4 changes: 2 additions & 2 deletions test/io/db_config.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ALTER ROLE db_config_authenticator SET pgrst.openapi_server_proxy_uri = 'https:/
ALTER ROLE db_config_authenticator SET pgrst.jwt_secret = 'REALLY=REALLY=REALLY=REALLY=VERY=SAFE';
ALTER ROLE db_config_authenticator SET pgrst.jwt_secret_is_base64 = 'false';
ALTER ROLE db_config_authenticator SET pgrst.jwt_role_claim_key = '."a"."role"';
ALTER ROLE db_config_authenticator SET pgrst.db_aggregates = 'true';
ALTER ROLE db_config_authenticator SET pgrst.db_aggregates_enabled = 'false';
ALTER ROLE db_config_authenticator SET pgrst.db_anon_role = 'anonymous';
ALTER ROLE db_config_authenticator SET pgrst.db_tx_end = 'commit-allow-override';
ALTER ROLE db_config_authenticator SET pgrst.db_pre_config = 'postgrest.preconf';
Expand Down Expand Up @@ -53,7 +53,7 @@ ALTER ROLE other_authenticator SET pgrst.jwt_aud = 'https://otherexample.org';
ALTER ROLE other_authenticator SET pgrst.openapi_server_proxy_uri = 'https://otherexample.org/api';
ALTER ROLE other_authenticator SET pgrst.jwt_secret = 'ODERREALLYREALLYREALLYREALLYVERYSAFE';
ALTER ROLE other_authenticator SET pgrst.jwt_secret_is_base64 = 'true';
ALTER ROLE other_authenticator SET pgrst.db_aggregates = 'true';
ALTER ROLE other_authenticator SET pgrst.db_aggregates_enabled = 'false';
ALTER ROLE other_authenticator SET pgrst.db_schemas = 'test, other_tenant1, other_tenant2';
ALTER ROLE other_authenticator SET pgrst.db_root_spec = 'other_root';
ALTER ROLE other_authenticator SET pgrst.db_plan_enabled = 'true';
Expand Down

0 comments on commit 5e3eb97

Please sign in to comment.