Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A small HTTP configuration server. Eats YAML, returns JSON, XML and YAML. Restricts requests to local subnet.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
log
test
.gitignore
README.textile
config.ru
lane_groove.gemspec

README.textile

lane_groove

Version 0.1 breaking changes

  • .XML (upcased) and .rb are no longer supported.
  • Static files are served under url /static now.
  • HTTP accept headers are taken into account in addition to file endings
  • format defaults to json

Getting started

Put your config-files as yaml into one dir, cd to this dir and enter lane_groove:

$: lane_groove
[26/07 17:40:41] Working directory is /Users/niko/laut/config_server/config
=> Pid not found, process seems don't exist!
=> Process demonized with pid 92822 with Forever v.0.2.3

The lane_groove daemon gets started on port 6666, a log and a pid file get generated within the same dir.

Retrieving the configuration

With two files in a directory, production.yaml and staging.yaml, and lane_groove being started within this directory:

curl localhost:6666/production.yaml

will get your production configuration in yaml format.

Supported formats are json, xml, yaml and line (see below).

If you need other formats just open an issue.

XML output and nil values

Keys with nil values are removed from the XML output as there’s no canonical way to represent these in XML.

Line output

Line output is special as it only supports single attributes. The URL contains a comma separated list of nodes and returns a single line with just these attributes separated by spaces. For nodes that are not leaves, the just their values returned recursively. This way the output can easily be parsed with awk:

mysql `curl localhost:6666/db/host,/db/user,/db/database,/db/password.line | awk '{print "--host="$1" --user="$2" --password="$4" "$3}'`

or even:

mysql `curl localhost:6666/db.line | awk '{print "--host="$1" --user="$2" --password="$4" "$3}'`

You can specify a separator in the query string:

mysql `curl localhost:6666/db/host,/db/user,/db/database,/db/password.line?F=, | awk -F ',' '{print "--host="$1" --user="$2" --password="$4" "$3}'`

Real live example shell script:

#!/bin/bash

MYSQL='show tables'

CMD=`curl confserver:6666/conf/mysql/host,/conf/mysql/username,/conf/mysql/database,/conf/mysql/password.line?F=,  | awk -F ',' -v MYSQL="$MYSQL" '{print "mysql \x27--host="$1"\x27 \x27--user="$2"\x27 \x27--password="$4"\x27 \x27--execute="MYSQL"\x27 "$3}'`

# echo $CMD
eval $CMD

Reloading

lane_groove keeps the configuration in memory. To reload the config files, just add a reload query string:

curl localhost:6666/production.yaml?reload=true

Performance

lane_groove is just single threaded, but most of the time it will server the content out of memory. On my MBP I benchmarked over 1000 requests per second when not reloading and over 400 requests per second when reloading two simple files (both with a json representation of the configuration; xml and yaml is slightly slower). Of course, with larger files this will be less, but still enough even for large files and large networks.

Testing config files

lane_groove provides a second binary, lane_groove_test. If you run that within your config file directory you can test the syntax of your configuration files. It will output parsed and re-encoded yaml.

Static files

If your lane_groove directory contains a subdirectory called “static” it will serve the files in there as static files:

curl localhost:6666/static/some.txt

Stopping lane_groove

Stop the lane_groove server: cd to the directory and lane_groove stop.

The daemon

lane_groove uses foreverb

Security

Requests are restricted to the local network (127.0.0.1 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16). For more security… uhm… use a firewall or something.

Requirements

Requirements are xml-simple, sinatra, sinatra/respond_with and rack-contrib. For tests rack-test.

License

Copyright © 2011 Niko Dittmann

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.

Something went wrong with that request. Please try again.