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>/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. + 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 - #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 - #1823, Add the ability to run postgrest without any configuration. @wolfgangwalther
- #1769, Add the ability to run without `db-schemas`, defaulting to `db-schemas=public`. @wolfgangwalther + #1991, Add the ability to run without `db-uri` using libpq's PG environment variables to connect. @wolfgangwalther
- #1689, Add the ability to run without `db-anon-role` disabling anonymous access. @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 ### Fixed
+1 -6
View File
@@ -2,15 +2,11 @@
module Main (main) where module Main (main) where
import qualified Data.Map.Strict as M
import System.IO (BufferMode (..), hSetBuffering) import System.IO (BufferMode (..), hSetBuffering)
import qualified PostgREST.App as App import qualified PostgREST.App as App
import qualified PostgREST.CLI as CLI import qualified PostgREST.CLI as CLI
import PostgREST.Config (readPGRSTEnvironment)
import Protolude import Protolude
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
@@ -20,8 +16,7 @@ import qualified PostgREST.Unix as Unix
main :: IO () main :: IO ()
main = do main = do
setBuffering setBuffering
hasPGRSTEnv <- not . M.null <$> readPGRSTEnvironment opts <- CLI.readCLIShowHelp
opts <- CLI.readCLIShowHelp hasPGRSTEnv
CLI.main installSignalHandlers runAppInSocket opts CLI.main installSignalHandlers runAppInSocket opts
installSignalHandlers :: App.SignalHandlerInstaller installSignalHandlers :: App.SignalHandlerInstaller
+5 -14
View File
@@ -82,12 +82,12 @@ data Command
| CmdDumpSchema | CmdDumpSchema
-- | Read command line interface options. Also prints help. -- | Read command line interface options. Also prints help.
readCLIShowHelp :: Bool -> IO CLI readCLIShowHelp :: IO CLI
readCLIShowHelp hasEnvironment = readCLIShowHelp =
O.customExecParser prefs opts O.customExecParser prefs opts
where where
prefs = O.prefs $ O.showHelpOnError <> O.showHelpOnEmpty 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 parser = O.helper <*> exampleParser <*> cliParser
progDesc = progDesc =
@@ -96,11 +96,6 @@ readCLIShowHelp hasEnvironment =
<> BS.unpack prettyVersion <> BS.unpack prettyVersion
<> " / create a REST API to an existing Postgres database" <> " / 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 = exampleParser =
O.infoOption exampleConfigFile $ O.infoOption exampleConfigFile $
O.long "example" O.long "example"
@@ -111,12 +106,12 @@ readCLIShowHelp hasEnvironment =
cliParser = cliParser =
CLI CLI
<$> (dumpConfigFlag <|> dumpSchemaFlag) <$> (dumpConfigFlag <|> dumpSchemaFlag)
<*> optionalIf hasEnvironment configFileOption <*> O.optional configFileOption
configFileOption = configFileOption =
O.strArgument $ O.strArgument $
O.metavar "FILENAME" O.metavar "FILENAME"
<> O.help "Path to configuration file (optional with PGRST_ environment variables)" <> O.help "Path to configuration file"
dumpConfigFlag = dumpConfigFlag =
O.flag CmdRun CmdDumpConfig $ O.flag CmdRun CmdDumpConfig $
@@ -128,10 +123,6 @@ readCLIShowHelp hasEnvironment =
O.long "dump-schema" O.long "dump-schema"
<> O.help "Dump loaded schema as JSON and exit (for debugging, output structure is unstable)" <> 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 :: [Char]
exampleConfigFile = exampleConfigFile =
[str|### REQUIRED: [str|### REQUIRED:
+1 -3
View File
@@ -10,13 +10,11 @@ cli:
args: ['-e'] args: ['-e']
- name: dump config - name: dump config
args: ['--dump-config'] args: ['--dump-config']
use_defaultenv: true
- name: dump schema - name: dump schema
args: ['--dump-schema'] args: ['--dump-schema']
use_defaultenv: true use_defaultenv: true
# failures: config files
- name: no config - name: no config
expect: error # failures: config files
- name: non-existant config file - name: non-existant config file
expect: error expect: error
args: ['does_not_exist.conf'] args: ['does_not_exist.conf']