commit dbe5cb2985371a96d96fb7222fd4fe1db80b6d90
parent 5484699565bc640aa4be907b816aaf9266f8e91d
Author: James Eversole <james@eversole.co>
Date: Sat, 17 Feb 2024 08:23:10 -0600
Update environment variables to support custom data directory
Diffstat:
7 files changed, 29 insertions(+), 34 deletions(-)
diff --git 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
@@ -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
@@ -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"
+adminEmail :: IO String
+adminEmail = getEnv "ADMINEMAIL"
+
+appPort :: IO String
+appPort = getEnv "APPLICATIONPORT"
+
+dataPath :: IO String
+dataPath = getEnv "DATADIR"
+
dbPath :: IO String
-dbPath = getEnv "dbFile"
+dbPath = getEnv "DBFILE"
confLinkLength :: IO String
-confLinkLength = getEnv "linkLength"
-
-adminEmail :: IO String
-adminEmail = getEnv "adminEmail"
+confLinkLength = getEnv "LINKLENGTH"
-appPort :: IO String
-appPort = getEnv "applicationPort"
+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
@@ -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
@@ -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
@@ -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
@@ -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