Skip to content

Commit

Permalink
feat: dump config through Admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyWriter authored Feb 6, 2024
1 parent a45058b commit 71887e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/PostgREST/Admin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ 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

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)
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 71887e4

Please sign in to comment.