Remove Dhall dependency and ReaderT; use dotenv; create encryption key on startup if it doesn't exist

This commit is contained in:
2024-02-17 07:46:09 -06:00
parent 8545b969f3
commit 5484699565
14 changed files with 131 additions and 130 deletions

View File

@@ -1,11 +1,36 @@
module Core.Configuration ( main ) where
module Core.Configuration where
import qualified Data.ByteString as B
import Core.Types
import Crypto.Saltine.Core.SecretBox (newKey)
import Crypto.Saltine.Class (encode)
import Configuration.Dotenv
import System.Directory (doesFileExist)
import System.Environment (getEnv)
import Dhall
instance FromDhall DhallConfig
main :: IO DhallConfig
main :: IO ()
main = do
input auto "./config.dhall"
loadFile defaultConfig
keyFileInit :: IO ()
keyFileInit = do
keyExists <- doesFileExist "./data/encryptionKey"
case keyExists of
True -> putStrLn "Using existing key"
False -> do
key <- newKey
B.writeFile "./data/encryptionKey" (encode key)
putStrLn "Creating new encryption key; any pre-existing DB entries will not decrypt"
dbPath :: IO String
dbPath = getEnv "dbFile"
confLinkLength :: IO String
confLinkLength = getEnv "linkLength"
adminEmail :: IO String
adminEmail = getEnv "adminEmail"
appPort :: IO String
appPort = getEnv "applicationPort"