diff --git a/CHANGELOG.md b/CHANGELOG.md index 63ff00c5b2..788f126031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - #2887, Add Preference `max-affected` to limit affected resources - @taimoorzaeem + - #3171, Add an ability to dump config via admin API - @skywriter ### Fixed diff --git a/src/PostgREST/Admin.hs b/src/PostgREST/Admin.hs index 55230712be..b5122f3067 100644 --- a/src/PostgREST/Admin.hs +++ b/src/PostgREST/Admin.hs @@ -11,6 +11,8 @@ import qualified Network.Wai.Handler.Warp as Warp import Control.Monad.Extra (whenJust) +import qualified Data.ByteString.Lazy as LBS + import Network.Socket import Network.Socket.ByteString @@ -18,6 +20,7 @@ import PostgREST.AppState (AppState) import PostgREST.Config (AppConfig (..)) import qualified PostgREST.AppState as AppState +import qualified PostgREST.Config as Config import Protolude import Protolude.Partial (fromJust) @@ -45,6 +48,9 @@ admin appState appConfig req respond = do respond $ Wai.responseLBS (if isMainAppReachable && isConnectionUp && isSchemaCacheLoaded then HTTP.status200 else HTTP.status503) [] mempty ["live"] -> respond $ Wai.responseLBS (if isMainAppReachable then HTTP.status200 else HTTP.status503) [] mempty + ["config"] -> do + config <- AppState.getConfig appState + respond $ Wai.responseLBS HTTP.status200 [] (LBS.fromStrict $ encodeUtf8 $ Config.toText config) _ -> respond $ Wai.responseLBS HTTP.status404 [] mempty diff --git a/test/io/test_io.py b/test/io/test_io.py index e09a4720cc..c4ce5e1edd 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -632,6 +632,16 @@ def sleep(i=i): t.join() +def test_admin_config(defaultenv): + "Should get a success response from the admin server containing current configuration" + + with run(env=defaultenv) as postgrest: + response = postgrest.admin.get("/config") + print(response.text) + assert response.status_code == 200 + assert "admin-server-port" in response.text + + def test_admin_ready_w_channel(defaultenv): "Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled"