Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Library for managing environment variables in Clojure
Clojure
Tag: 0.2.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
environ.core
environ.lein
.gitignore
README.md
project.clj

README.md

Environ

Environ is a Clojure library for managing environment settings from a number of different sources.

Currently, Environ supports two sources; environment variables, and the Leiningen project map.

Installation

Include the following dependency in your project.clj file:

:dependencies [[environ "0.2.1"]]

If you want to be able to draw settings from the Leiningen project map, you'll need the following plugin and hook:

:plugins [[environ/environ.lein "0.2.1"]]
:hooks [environ.leiningen.hooks]

A good place to put this is in your ~/.lein/profiles.clj file.

Usage

Let's say you have an application that requires an AWS access key and secret key.

You can use Leiningen's profiles to add this information to your development environment in your ~/.lein/profiles.clj file, as it's likely you'll be using the same AWS account for all development:

{:user {:env {:aws-access-key "XXXXXXXXXXXXXXX"
              :aws-secret-key "YYYYYYYYYYYYYYYYYYYYYY"}}}

In your application, you can access these values through the environ.core/env map:

(use 'environ.core)

(def aws-creds
  {:access-key (env :aws-access-key)
   :secret-key (env :aws-secret-key)})

When you deploy to a production environment, you can use standard environment variables to configure the same settings.

AWS_ACCESS_KEY=XXXXXXXXXXXXXXX
AWS_SECRET_KEY=YYYYYYYYYYYYYYYYYYYYYY

Notice that the equivalent environment variables are uppercase, and the "-" character has been replaced with "_".

License

Copyright © 2012 James Reeves

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.