Remove Dhall dependency and ReaderT; use dotenv; create encryption key on startup if it doesn't exist
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user