Giter Club home page Giter Club logo

environ's Introduction

Environ

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

Currently, Environ supports three sources; environment variables, Java system properties and the Leiningen project map using the lein-environ plugin.

Installation

Include the following dependency in your project.clj file:

:dependencies [[environ "0.4.0"]]

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

:plugins [[lein-environ "0.4.0"]]

A good place to put this is in your 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)})

You'll likely also want to add .lein-env to your .gitignore file (or the equivalent for your version control system).

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 "_".

You can also use Java system properties:

java -jar app-standalone.jar -Daws.access.key=XX -Daws.secret.key=YY

Note in this case that the "-" character has been replace with ".", since this is the standard separator for system properties.

License

Copyright © 2013 James Reeves

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

environ's People

Contributors

joelittlejohn avatar weavejester avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.