From dbe5cb2985371a96d96fb7222fd4fe1db80b6d90 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Sat, 17 Feb 2024 08:23:10 -0600 Subject: [PATCH] Update environment variables to support custom data directory --- README | 16 +++------------- examples/.env.example | 13 +++++++------ src/Core/Configuration.hs | 29 +++++++++++++++++++---------- src/Core/HTTP.hs | 1 - src/Core/SQLite.hs | 3 --- src/Feature/Sharing/HTTP.hs | 1 - src/Lib.hs | 2 +- 7 files changed, 30 insertions(+), 35 deletions(-) diff --git a/README b/README index 15b87bc..e7e2478 100644 --- a/README +++ b/README @@ -1,16 +1,6 @@ purr ----- -STATUS: IT JUST WERKS - -DETAILS: We're on Saltine now and nix builds are working. -The documentation that was in this README for setup isn't 100% accurate -anymore, so I removed it. I'm going to add some functions to gracefully -handle the setup of the new keyfile dependency and will create new build -and development documentation in this repo then. Also, I'll start -using Markdown when I redo the docs like a sensible person. Stay tuned! - - https://purr.eversole.co a work-in-progress web application offering customizable password generation and time-limited sharing of secrets. @@ -29,13 +19,13 @@ that don't offer better authentication methods. - Share text secrets with others without disclosing the secret in the message itself. -- Be really cute compared to the competition. - - Provide a minimal and clean interface for generating and sharing passwords. - Maintain a clean and organized codebase that can be extended to include more utilities than originally anticipated. +- Be really cute compared to the competition. + WHY TRUST YOU? You shouldn't. This is free and open-source software which you can run on your @@ -43,7 +33,7 @@ own hardware. DEPLOYMENT -Updates to this section coming soon. + DEVELOPMENT & SUPPORT diff --git a/examples/.env.example b/examples/.env.example index a1e7089..4236dab 100644 --- a/examples/.env.example +++ b/examples/.env.example @@ -1,6 +1,7 @@ -environment="production" -applicationHost="localhost" -applicationPort="3000" -dbFile="data/Purr.sqlite" -linkLength="24" -adminEmail="admin@purr.example.com" +ENVIRONMENT="production" +APPLICATIONHOST="localhost" +APPLICATIONPORT="3000" +DATAPATH="./" +DBFILE="data/Purr.sqlite" +LINKLENGTH="24" +ADMINEMAIL="admin@purr.example.com" diff --git a/src/Core/Configuration.hs b/src/Core/Configuration.hs index 34efd04..8061ecf 100644 --- a/src/Core/Configuration.hs +++ b/src/Core/Configuration.hs @@ -15,22 +15,31 @@ main = do keyFileInit :: IO () keyFileInit = do - keyExists <- doesFileExist "./data/encryptionKey" + dataPathStr <- dataPath + keyExists <- doesFileExist $ dataPathStr ++ "data/encryptionKey" case keyExists of True -> putStrLn "Using existing key" False -> do key <- newKey - B.writeFile "./data/encryptionKey" (encode key) + B.writeFile (dataPathStr ++ "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" +adminEmail = getEnv "ADMINEMAIL" appPort :: IO String -appPort = getEnv "applicationPort" +appPort = getEnv "APPLICATIONPORT" + +dataPath :: IO String +dataPath = getEnv "DATADIR" + +dbPath :: IO String +dbPath = getEnv "DBFILE" + +confLinkLength :: IO String +confLinkLength = getEnv "LINKLENGTH" + +encKey :: IO B.ByteString +encKey = do + dataPathStr <- dataPath + B.readFile (dataPathStr ++ "data/encryptionKey") diff --git a/src/Core/HTTP.hs b/src/Core/HTTP.hs index bbdca48..69c98f9 100644 --- a/src/Core/HTTP.hs +++ b/src/Core/HTTP.hs @@ -11,7 +11,6 @@ import Control.Monad.Trans (liftIO) import Data.Maybe (Maybe (Nothing)) import Network.Wai.Middleware.RequestLogger (logStdoutDev) import Network.Wai.Middleware.Static -import System.Environment import Web.Scotty app :: PurrApp () diff --git a/src/Core/SQLite.hs b/src/Core/SQLite.hs index 8ef5867..ee275b2 100644 --- a/src/Core/SQLite.hs +++ b/src/Core/SQLite.hs @@ -23,6 +23,3 @@ main = do \ views INT,\ \ maxViews INT)" close conn - -encKey :: IO ByteString -encKey = B.readFile "./data/encryptionKey" diff --git a/src/Feature/Sharing/HTTP.hs b/src/Feature/Sharing/HTTP.hs index 11da604..b2d67f3 100644 --- a/src/Feature/Sharing/HTTP.hs +++ b/src/Feature/Sharing/HTTP.hs @@ -12,7 +12,6 @@ import Control.Monad.Trans (liftIO) import Data.List.Split (splitOn) import Data.Maybe (listToMaybe) import Prelude -import System.Environment import Web.Scotty import qualified Data.Text as T diff --git a/src/Lib.hs b/src/Lib.hs index a55413b..fca3340 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -13,8 +13,8 @@ import Web.Scotty main :: IO () main = do sodiumInit - Configuration.keyFileInit Configuration.main + Configuration.keyFileInit DB.main appPortStr <- Configuration.appPort let appPort = read appPortStr :: Int