From 95503ad1f4869c8ae446dae79e82cb669eaeb12f Mon Sep 17 00:00:00 2001 From: Josh Berman Date: Sun, 14 Jun 2015 10:58:15 +0300 Subject: [PATCH] support remote-server sytax in keter.yaml file, update README --- Keter/Plugin/Postgres.hs | 32 +++++++++++++++++--------------- README.md | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 16 deletions(-) mode change 100644 => 100755 README.md diff --git a/Keter/Plugin/Postgres.hs b/Keter/Plugin/Postgres.hs index 93c13b9..2505ca6 100644 --- a/Keter/Plugin/Postgres.hs +++ b/Keter/Plugin/Postgres.hs @@ -50,7 +50,11 @@ instance Default Settings where "';\nCREATE DATABASE " <> fromText dbiName <> " OWNER " <> fromText dbiUser <> ";" - _ <- readProcess "sudo" ["-u", "postgres", "psql"] $ TL.unpack sql + cmd = [ "-u", "postgres", "psql" + , "-h", (T.unpack $ dbServer dbiServer) + , "-p", (show $ dbPort dbiServer) + , "-U", "postgres"] + _ <- readProcess "sudo" cmd $ TL.unpack sql return () } @@ -70,8 +74,8 @@ data DBServerInfo = DBServerInfo deriving Show randomDBI :: DBServerInfo -> R.StdGen -> (DBInfo, R.StdGen) -randomDBI dbsi r = - S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi)) r +randomDBI dbsi = + S.runState (DBInfo <$> rt <*> rt <*> rt <*> (pure dbsi)) where rt = T.pack <$> replicateM 10 (S.state $ R.randomR ('a', 'z')) @@ -127,21 +131,19 @@ load Settings{..} fp = do return Plugin { pluginGetEnv = \appname o -> case HMap.lookup "postgres" o of - Just (Array x) -> do - let Object o' = V.head x - dbServer = fromMaybe def . parseMaybe parseJSON $ V.head x - x <- newEmptyMVar - writeChan chan $ GetConfig appname dbServer $ putMVar x - edbi <- takeMVar x - edbiToEnv edbi + Just (Array v) -> do + let dbServer = fromMaybe def . parseMaybe parseJSON $ V.head v + doenv chan appname dbServer Just (Bool True) -> do - x <- newEmptyMVar - writeChan chan $ GetConfig appname def $ putMVar x - edbi <- takeMVar x - edbiToEnv edbi + doenv chan appname def _ -> return [] } - + where doenv chan appname dbs = do + x <- newEmptyMVar + writeChan chan $ GetConfig appname dbs $ putMVar x + edbi <- takeMVar x + edbiToEnv edbi + tmpfp = fp <.> "tmp" loop chan = do diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7204168..9710b22 --- a/README.md +++ b/README.md @@ -179,8 +179,22 @@ plugins: postgres: true ``` +* Keter can be configured to connect to a remote postgres server using the following syntax: +```yaml +plugins: + postgres: + - server: remoteServerNameOrIP + port: 1234 +``` + +Different webapps can be configured to use different servers using the above syntax. +Keter will connect to the remote servers using the `postgres` account. This setup +assumes the remote server's `pg_hba.conf` file has been configured to allow connections +from the keter-server IP using the `trust` method. + (Note: The `plugins` configuration option was added in v1.0 of the -keter configuration syntax. If you are using v0.4 then use `postgres: true`.) +keter configuration syntax. If you are using v0.4 then use `postgres: true`. +The remote-postgres server syntax was added in v1.4.2.) * Modify your application to get its database connection settings from the following environment variables: * `PGHOST`