(aero is edn really, ok?)
Light and fluffy configuration.
Add the following dependency to your project.clj
file
[aero "0.1.1"]
Please note that being a 0.x.y version indicates the provisional status of this library, and that features are subject to change.
Create a file called config.edn
containing the following
{:greeting "World!"}
In your code, read the configuration like this
(require '[aero.core :refer (read-config)])
(read-config "config.edn")
Configuration should be explicit, obvious, not clever. It should be easy to understand what the config is, and where it is declared.
Determining config while diagnosing a support issue should not be a wild goose chase.
Config files are often duplicated on a per-environment basis, attracting all the problems associated with duplication.
When looking at a config file, a reader will usually ask: "Does the value differ from the default, and if so how?". It's clearly better to answer that question in-place.
When config is left out of source code control it festers and diverges from the code base. Better to keep a single config file in source code control.
While it is good to keep config in source code control, it is important to ensure passwords and other sensitive information remain hidden.
While it can be very flexible to have 'clever' configuration 'programs', it can be unsafe, lead to exploits and compromise security. Configuration is a key input to a program. Always use data for configuration and avoid turing-complete languages!
We suggest using environment variables sparingly, the way Unix intends, and not go mad. After all, we want to keep configuration explicit and intentional.
Also, see these arguments against.
Fortunately, most of the tech to read configuration in a safe, secure and extensible way already exists in the Clojure core library (EDN).
Aero provides a small library of tag literals.
Use #env
to reference an environment variable.
{:password #env DATABASE_PASSWORD}
When you need to hide a configuration detail, such as a password, use this feature. If you're using AWS Beanstalk, you can set environment variables in the console, which keeps them safe from unauthorised access.
Use #env
with a vector to provide a default if the environment variable doesn't exist.
{:password #env [PORT 8080]}
Use cond as a kind of reader conditional.
#cond
expects a map, from which is extracts the entry corresponding to the of profile.
{:webserver
{:port #cond {:default 8000
:dev 8001
:test 8002}}}
You can specify the value of profile when you read the config.
(read-config "config.edn" {:profile :dev})
which will return
{:webserver
{:port 8001}}
Aero is built on Clojure's edn.
Aero is influenced by nomad, but explicitly avoids environmental factors, such as hostname.
The MIT License (MIT)
Copyright © 2015 JUXT LTD.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.