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, lookupEnv) main :: IO () main = do envFile <- lookupEnv "PURRNOFILE" case envFile of Nothing -> loadFile defaultConfig _ -> putStrLn "Not using dotenv file" keyFileInit :: IO () keyFileInit = do dataPathStr <- dataPath keyExists <- doesFileExist $ dataPathStr ++ "data/encryptionKey" case keyExists of True -> putStrLn "Using existing key" False -> do key <- newKey B.writeFile (dataPathStr ++ "data/encryptionKey") (encode key) putStrLn "Creating new encryption key; any pre-existing DB entries will not decrypt" adminEmail :: IO String adminEmail = getEnv "ADMINEMAIL" appPort :: IO String appPort = getEnv "APPLICATIONPORT" dataPath :: IO String dataPath = getEnv "DATADIR" dbPath :: String dbPath = "data/Purr.sqlite" confLinkLength :: IO String confLinkLength = getEnv "LINKLENGTH" encKey :: IO B.ByteString encKey = do dataPathStr <- dataPath B.readFile (dataPathStr ++ "data/encryptionKey")