Giter Site home page Giter Site logo

yummy's Introduction

yummy: YAML configuration for Clojure application

Build Status Clojars Project

Yummy allows reading in configuration from YAML files and provides optional facilities for:

  • Environment based configuration
  • Validation through clojure.spec

Yummy only provides YAML parsing, no generation facilities are present.

Using

Auto determined configuration file paths:

(spec/def ::config (spec/keys :req-un [::http ::logging ::database]))
(yummy.config/load-config {:program-name :mydaemon :spec ::config})

Yummy will look for a configuration-file path in the mydaemon.configuration system property or the MYDAEMON_CONFIGURATION environment variable.

A path can outright be given as well:

(spec/def ::config (spec/keys :req-un [::http ::logging ::database]))
(yummy.config/load-config {:path "/etc/mydaemon.yml" :spec ::config})

Alternately configuration can be loaded from a string:

(yummy.config/load-config-string "a: b" {})

Additional YAML Tags

To make integration as simple as possible, Yummy understands a number of custom tag parsers, namely:

  • envdir: loads a map from a directory, treating file names as keys and content as values
  • envvar: loads a value from the environment, optionally taking in defaults
  • keyword: coerce a string to a keyword
  • envfmt: produce a string from a format string and environment variables to pull in
  • slurp: produce a string from the given file content
  • uuid: produce a UUID from the given string

Example

a: !keyword b
b: !envvar HOME
c: !envvar [NOPE, hello]
d: !envdir /tmp/foo
e: !envfmt ["user=%s, home=%s", USER, HOME]
f: !slurp "/etc/hostname"
g: !uuid fc716a9b-fb1e-4ebd-b781-5ca13039aa55

Documentation

http://exoscale.github.io/yummy

Installation

    [[exoscale/yummy "0.2.6"]]

yummy's People

Contributors

greut avatar mpenet avatar pilosus avatar pyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yummy's Issues

add !slurp

use case

kubernetes:
  bearer: !slurp "/var/secrets/.../token"

spec/conform instead of spec/assert?

At the moment, yummy performs spec/assert against the data. This is fine, but there is no chance to coerce the data as spec/conform does. Imagine I've got a date string in my yaml file or a regex pattern. There aren't such tags in yummy so far as well as I believe this is wrong way to extend yummy when we have spec.

My suggestion is to use spec/conform for validation and return the final value with coerced types. In my example, the string pattern might be adapted with ease:

(s/def ::pattern (s/conformer re-pattern))

If the result of conforming was ::invalid, we do explain-data and raise an ex-info manually.

Would you like me to submit a PR?

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.