feat: dump config through Admin API
This commit is contained in:
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- #2887, Add Preference `max-affected` to limit affected resources - @taimoorzaeem
|
- #2887, Add Preference `max-affected` to limit affected resources - @taimoorzaeem
|
||||||
|
- #3171, Add an ability to dump config via admin API - @skywriter
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import qualified Network.Wai.Handler.Warp as Warp
|
|||||||
|
|
||||||
import Control.Monad.Extra (whenJust)
|
import Control.Monad.Extra (whenJust)
|
||||||
|
|
||||||
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
|
|
||||||
import Network.Socket
|
import Network.Socket
|
||||||
import Network.Socket.ByteString
|
import Network.Socket.ByteString
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ import PostgREST.AppState (AppState)
|
|||||||
import PostgREST.Config (AppConfig (..))
|
import PostgREST.Config (AppConfig (..))
|
||||||
|
|
||||||
import qualified PostgREST.AppState as AppState
|
import qualified PostgREST.AppState as AppState
|
||||||
|
import qualified PostgREST.Config as Config
|
||||||
|
|
||||||
import Protolude
|
import Protolude
|
||||||
import Protolude.Partial (fromJust)
|
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
|
respond $ Wai.responseLBS (if isMainAppReachable && isConnectionUp && isSchemaCacheLoaded then HTTP.status200 else HTTP.status503) [] mempty
|
||||||
["live"] ->
|
["live"] ->
|
||||||
respond $ Wai.responseLBS (if isMainAppReachable then HTTP.status200 else HTTP.status503) [] mempty
|
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
|
respond $ Wai.responseLBS HTTP.status404 [] mempty
|
||||||
|
|
||||||
|
|||||||
@@ -632,6 +632,16 @@ def test_change_statement_timeout_held_connection(defaultenv, metapostgrest):
|
|||||||
t.join()
|
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):
|
def test_admin_ready_w_channel(defaultenv):
|
||||||
"Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled"
|
"Should get a success response from the admin server ready endpoint when the LISTEN channel is enabled"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user