Read env variables using envy library

Using my dear friend's, dmjio's, excellent library, envy -- to read and parse
variables from the system environment.

I added and git-ignored the .envrc file that contains API secrets. I'm using
Envy to read these values, so that I don't hard-code these values into the
source code.
This commit is contained in:
William Carroll 2020-07-30 13:58:50 +01:00
parent 385164c6af
commit b6e8389edd
5 changed files with 33 additions and 13 deletions

View file

@ -16,6 +16,7 @@ import Database.SQLite.Simple.ToField
import GHC.Generics
import Web.Cookie
import Servant.API
import System.Envy (FromEnv, fromEnv, env)
import Crypto.Random.Types (MonadRandom)
import qualified Crypto.KDF.BCrypt as BC
@ -26,6 +27,17 @@ import qualified Data.Text.Encoding as TE
import qualified Data.UUID as UUID
--------------------------------------------------------------------------------
-- | Top-level application configuration.
data Config = Config
{ mailgunAPIKey :: Text
, dbFile :: FilePath
} deriving (Eq, Show)
instance FromEnv Config where
fromEnv _ =
Config <$> env "MAILGUN_API_KEY"
<*> env "DB_FILE"
-- TODO(wpcarro): Properly handle NULL for columns like profilePicture.
forNewtype :: (Typeable b) => (Text -> b) -> FieldParser b
forNewtype wrapper field =