diff options
author | William Carroll <wpcarro@gmail.com> | 2020-07-30T12·58+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-07-30T12·58+0100 |
commit | b6e8389edd486d407025383825a1beaf6b7f63b7 (patch) | |
tree | b38c6fd1231bce0548be7557f2e509cea84b66c1 /src/Types.hs | |
parent | 385164c6afea7995b797cf8ddddefa187c26f646 (diff) |
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.
Diffstat (limited to 'src/Types.hs')
-rw-r--r-- | src/Types.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Types.hs b/src/Types.hs index eed9bf8c1696..135c50f17f4a 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -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 = |