bowbahdoe / caveman

Clojure Web Framework
https://caveman.mccue.dev
12 stars 8 forks source link

Use java system properties instead of dotenv external library #12

Closed souenzzo closed 2 weeks ago

souenzzo commented 3 weeks ago

Replacing start-env with this code

(defn start-env
  []
  (let [p (System/getProperties)
        dot-env (io/file ".env")]
    (when (.exists dot-env)
      (.load p (io/reader dot-env)))))

We are able to replace these Dotenv/.get calls with (System/getProperty "POSTGRES_USERNAME") and (Long/getLong "PORT")

PROS:

CONS:

bowbahdoe commented 3 weeks ago

You missed some cons:

image

As compared to

image

There are cons with .env files in general I am puzzling through how to give advice on. At work we use https://www.doppler.com/ and there is no "maybe accidentally committable .env" lying around. Before that we passed around a file through side channels and just made sure it was loaded into the terminal environment. If I can properly describe that then there is no need for any loader code. Its just (System/getenv ...)

The thing that is pushing me in that direction is nvd-clojure and clj-watson. Those both want an environment variable to have creds for pulling in the vulnerability database. If .env isn't loaded in the terminal thats a little annoying. You'd have to source .env && ...

bowbahdoe commented 3 weeks ago

I guess to note another approach - instead of environment variables passing around a full (maybe nested) config file is possible.

The reason I don't want to recommend that is