pleasetrythisathome / aero

Light and fluffy configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aero

(aero is edn really, ok?)

Light and fluffy configuration.

Light and fluffy configuration

Installation

Add the following dependency to your project.clj file

[aero "0.1.1"]

Status

Please note that being a 0.x.y version indicates the provisional status of this library, and that features are subject to change.

Getting started

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

Design goals

Explicit and intentional

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.

Avoid duplication ...

Config files are often duplicated on a per-environment basis, attracting all the problems associated with duplication.

... but allow for difference

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.

Allow config to be stored in the repository ...

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 hiding passwords

While it is good to keep config in source code control, it is important to ensure passwords and other sensitive information remain hidden.

Config should be data

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!

Use environment variables sparingly

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.

Use edn

Fortunately, most of the tech to read configuration in a safe, secure and extensible way already exists in the Clojure core library (EDN).

Tag literals

Aero provides a small library of tag literals.

env

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]}

cond

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

References

Aero is built on Clojure's edn.

Aero is influenced by nomad, but explicitly avoids environmental factors, such as hostname.

Copyright & License

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.

About

Light and fluffy configuration

License:MIT License


Languages

Language:Clojure 100.0%