Pass from file
This commit is contained in:
parent
63411532c4
commit
94f4593fdc
@ -3,7 +3,7 @@ let config = ./dhall/package.dhall
|
||||
in { amqp = config.AMQP::{
|
||||
, vhost = "reddit"
|
||||
, username = env:AMQP_USER as Text ? "reddit_pub"
|
||||
, password = env:AMQP_PASS as Text ? "tester"
|
||||
, password = config.Password.Type.Password (env:AMQP_PASS as Text ? "tester")
|
||||
, host = env:AMQP_HOST as Text ? "127.0.0.1"
|
||||
-- , host = "10.233.5.2"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{ vhost : Text
|
||||
, username : Text
|
||||
, password : Text
|
||||
, password : ../Password/Type.dhall
|
||||
, host : Text
|
||||
}
|
||||
|
1
dhall/Password/Type.dhall
Normal file
1
dhall/Password/Type.dhall
Normal file
@ -0,0 +1 @@
|
||||
< Password : Text | File : Text >
|
1
dhall/Password/package.dhall
Normal file
1
dhall/Password/package.dhall
Normal file
@ -0,0 +1 @@
|
||||
{ Type = ./Type.dhall }
|
@ -2,4 +2,5 @@
|
||||
, default = ./default.dhall
|
||||
, AMQP = ./AMQP/package.dhall
|
||||
, Fetcher = ./Fetcher/package.dhall
|
||||
, Password = ./Password/package.dhall
|
||||
}
|
||||
|
@ -11,10 +11,17 @@ import Dhall.Deriving
|
||||
import Numeric.Natural (Natural)
|
||||
import Data.SubReddit (SubReddit)
|
||||
|
||||
data Password
|
||||
= Password Text
|
||||
| File FilePath
|
||||
deriving stock (Generic, Show)
|
||||
deriving (FromDhall, ToDhall)
|
||||
via (Codec AsIs Password)
|
||||
|
||||
data AMQP = AMQP
|
||||
{ amqpVhost :: Text
|
||||
, amqpUsername :: Text
|
||||
, amqpPassword :: Text
|
||||
, amqpPassword :: Password
|
||||
, amqpHost :: Text
|
||||
}
|
||||
deriving stock (Generic, Show)
|
||||
@ -30,7 +37,7 @@ vhost = lens amqpVhost (\ am txt -> am{amqpVhost=txt})
|
||||
username :: Lens' AMQP Text
|
||||
username = lens amqpUsername (\ am txt -> am{amqpUsername=txt})
|
||||
|
||||
password :: Lens' AMQP Text
|
||||
password :: Lens' AMQP Password
|
||||
password = lens amqpPassword (\ am txt -> am{amqpPassword=txt})
|
||||
|
||||
data Fetcher = Fetcher
|
||||
|
@ -35,6 +35,7 @@ import Network.Wreq.Session (newSession)
|
||||
import Publish (Publish(..))
|
||||
import Data.Aeson.Lens (key, _String)
|
||||
import Data.Bool (bool)
|
||||
import qualified Data.Text.IO as TI
|
||||
|
||||
data MessageType = Create | Update
|
||||
deriving stock (Show, Eq, Generic)
|
||||
@ -70,11 +71,12 @@ amqpPublisher sqlConn channel exchange = Publish $ \msg -> do
|
||||
defaultMain :: FilePath -> IO ()
|
||||
defaultMain path = do
|
||||
conf <- readConfig path
|
||||
pass <- getPassword (conf ^. amqp . password)
|
||||
let rabbitConnect = openConnection
|
||||
(conf ^. amqp . host . T.unpacked)
|
||||
(conf ^. amqp . vhost)
|
||||
(conf ^. amqp . username)
|
||||
(conf ^. amqp . password)
|
||||
pass
|
||||
bracket rabbitConnect closeConnection $ \conn -> do
|
||||
SQL.withConnection (conf ^. sqlite) $ \sqlConn -> do
|
||||
SQL.execute_ sqlConn "create table if not exists membership (reddit_id primary key)"
|
||||
@ -87,3 +89,7 @@ defaultMain path = do
|
||||
for_ (conf ^. fetchers) $ \fetcher -> do
|
||||
print fetcher
|
||||
publishEntries (toMessage >$< publisher) sess fetcher
|
||||
|
||||
getPassword :: Password -> IO Text
|
||||
getPassword (Password p) = pure p
|
||||
getPassword (File path) = TI.readFile path
|
||||
|
Loading…
Reference in New Issue
Block a user