LocustHorde
LocustHorde

Reputation: 6400

Operating system agnostic way to get config file in clojure

I have a few clojure applications that load the sensitive info off of .properties file in /etc/ and this has worked well so far.

Recently, I have had to deal with a few windows machines added into our server collection and I need to run the clojure applications on there as well. Windows doesn't obviously have or understand /etc/ path and I got around that fact by looking at /etc/ and if that's missing then looking at d:\configs.

But I don't quite like this way of doing it, because, if there is another windows developer looking into it and he doesn't have d:\ or prefers elsewhere for configs it would get messy.

Is there any way I can load a file from clojure, no matter what operating system it is? My initial thoughts were of saving a key-path in the Environment variable and accessing it from clojure.

I am just wondering if there is a better way of doing it. Thanks.

Upvotes: 2

Views: 244

Answers (1)

xsc
xsc

Reputation: 6073

Have a look at environ. It offers some flexibility when it comes to configuring your Clojure app, letting you choose between a number of options:

  • environment variables: This seems to be the way to go in Clojureland, so I'd say your initial thought wasn't the worst;
  • in ~/.lein/profiles.clj: You can store them in the :user profile as Clojure data - that sounds quite nice, I guess;
  • Java CLI properties: Finally, you can pass them to the java executable directly via the command line.

environ will collect data from all these places.

Upvotes: 1

Related Questions