feat: Allow running postgrest without configuration

Resolves #1823
This commit is contained in:
Wolfgang Walther
2022-01-22 15:59:26 +01:00
parent c3ade07ad6
commit d9e016be8b
4 changed files with 11 additions and 26 deletions
+4 -3
View File
@@ -12,9 +12,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
+ A `<host>:<admin_server_port>/live` endpoint is available for checking if postgrest is running on its port/socket. 200 OK = alive, 503 = dead.
+ A `<host>:<admin_server_port>/ready` endpoint is available for checking a correct internal state(the database connection plus the schema cache). 200 OK = ready, 503 = not ready.
- #1988, Add the current user to the request log on stdout - @DavidLindbom, @wolfgangwalther
- #1991, Add the ability to run without `db-uri` using libpq's PG environment variables to connect. @wolfgangwalther
- #1769, Add the ability to run without `db-schemas`, defaulting to `db-schemas=public`. @wolfgangwalther
- #1689, Add the ability to run without `db-anon-role` disabling anonymous access. @wolfgangwalther
- #1823, Add the ability to run postgrest without any configuration. @wolfgangwalther
+ #1991, Add the ability to run without `db-uri` using libpq's PG environment variables to connect. @wolfgangwalther
+ #1769, Add the ability to run without `db-schemas`, defaulting to `db-schemas=public`. @wolfgangwalther
+ #1689, Add the ability to run without `db-anon-role` disabling anonymous access. @wolfgangwalther
### Fixed
+1 -6
View File
@@ -2,15 +2,11 @@
module Main (main) where
import qualified Data.Map.Strict as M
import System.IO (BufferMode (..), hSetBuffering)
import qualified PostgREST.App as App
import qualified PostgREST.CLI as CLI
import PostgREST.Config (readPGRSTEnvironment)
import Protolude
#ifndef mingw32_HOST_OS
@@ -20,8 +16,7 @@ import qualified PostgREST.Unix as Unix
main :: IO ()
main = do
setBuffering
hasPGRSTEnv <- not . M.null <$> readPGRSTEnvironment
opts <- CLI.readCLIShowHelp hasPGRSTEnv
opts <- CLI.readCLIShowHelp
CLI.main installSignalHandlers runAppInSocket opts
installSignalHandlers :: App.SignalHandlerInstaller
+5 -14
View File
@@ -82,12 +82,12 @@ data Command
| CmdDumpSchema
-- | Read command line interface options. Also prints help.
readCLIShowHelp :: Bool -> IO CLI
readCLIShowHelp hasEnvironment =
readCLIShowHelp :: IO CLI
readCLIShowHelp =
O.customExecParser prefs opts
where
prefs = O.prefs $ O.showHelpOnError <> O.showHelpOnEmpty
opts = O.info parser $ O.fullDesc <> progDesc <> footer
opts = O.info parser $ O.fullDesc <> progDesc
parser = O.helper <*> exampleParser <*> cliParser
progDesc =
@@ -96,11 +96,6 @@ readCLIShowHelp hasEnvironment =
<> BS.unpack prettyVersion
<> " / create a REST API to an existing Postgres database"
footer =
O.footer $
"To run PostgREST, please pass the FILENAME argument"
<> " or set PGRST_ environment variables."
exampleParser =
O.infoOption exampleConfigFile $
O.long "example"
@@ -111,12 +106,12 @@ readCLIShowHelp hasEnvironment =
cliParser =
CLI
<$> (dumpConfigFlag <|> dumpSchemaFlag)
<*> optionalIf hasEnvironment configFileOption
<*> O.optional configFileOption
configFileOption =
O.strArgument $
O.metavar "FILENAME"
<> O.help "Path to configuration file (optional with PGRST_ environment variables)"
<> O.help "Path to configuration file"
dumpConfigFlag =
O.flag CmdRun CmdDumpConfig $
@@ -128,10 +123,6 @@ readCLIShowHelp hasEnvironment =
O.long "dump-schema"
<> O.help "Dump loaded schema as JSON and exit (for debugging, output structure is unstable)"
optionalIf :: Alternative f => Bool -> f a -> f (Maybe a)
optionalIf True = O.optional
optionalIf False = fmap Just
exampleConfigFile :: [Char]
exampleConfigFile =
[str|### REQUIRED:
+1 -3
View File
@@ -10,13 +10,11 @@ cli:
args: ['-e']
- name: dump config
args: ['--dump-config']
use_defaultenv: true
- name: dump schema
args: ['--dump-schema']
use_defaultenv: true
# failures: config files
- name: no config
expect: error
# failures: config files
- name: non-existant config file
expect: error
args: ['does_not_exist.conf']