Update environment variables to support custom data directory

This commit is contained in:
James Eversole 2024-02-17 08:23:10 -06:00
parent 5484699565
commit dbe5cb2985
7 changed files with 30 additions and 35 deletions

16
README
View File

@ -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

View File

@ -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"

View File

@ -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")

View File

@ -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 ()

View File

@ -23,6 +23,3 @@ main = do
\ views INT,\
\ maxViews INT)"
close conn
encKey :: IO ByteString
encKey = B.readFile "./data/encryptionKey"

View File

@ -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

View File

@ -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