A BOSH template merge tool
CI Bot
Latest commit 133dd34 Sep 18, 2018
Permalink
Failed to load latest commit information.
Godeps Add missing comma Oct 30, 2017
assets Add test cases for issue #267 Sep 18, 2018
ci release v1.18.2 Sep 18, 2018
cmd/spruce Add test cases for issue #267 Sep 18, 2018
doc Add (( sort )) operator Jul 30, 2018
examples Adding examples and test cases including test case files for calc ope… Dec 15, 2016
log Key merge no longer panics if target keys' value is sequence or hash (#… Mar 31, 2017
tests More accurately diff different scalar types (bool, strings, int, etc) Oct 30, 2017
vendor Vendor ziutek/netaddr Oct 31, 2017
.gitignore added empty operator with tests Sep 6, 2016
.travis.yml Bump to golang 1.9, support system root CAs when talking to vault Oct 30, 2017
LICENSE Switched license to MIT Mar 5, 2016
Makefile Add support for reading YAML from stdin Jan 23, 2017
README.md Fix minor typo on README Sep 2, 2018
diff.go More accurately diff different scalar types (bool, strings, int, etc) Oct 30, 2017
diff_test.go New `spruce diff` command, finally. (#186) Feb 17, 2017
errors.go Key merge no longer panics if target keys' value is sequence or hash (#… Mar 31, 2017
evaluator.go Add (( sort )) operator Jul 30, 2018
evaluator_test.go Key merge no longer panics if target keys' value is sequence or hash (#… Mar 31, 2017
json.go Json strict mode (#261) May 5, 2018
merge.go Remove unused function shouldReplaceArray Sep 18, 2018
merge_test.go Remove unused function shouldReplaceArray Sep 18, 2018
op_calc.go Fix TYPOs in source files (#263) Jun 18, 2018
op_cartesian_product.go Cartesian product now makes []interface{}, not []string Jul 7, 2017
op_concat.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_defer.go Changed defer phase to Eval Jul 6, 2017
op_empty.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_file.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_grab.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_inject.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_ips.go Add out-of-bounds checking Oct 31, 2017
op_join.go Fix TYPOs in source files (#263) Jun 18, 2018
op_keys.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_null.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_param.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_prune.go Auto-generated op deps passed to <op>.Dependencies Jul 6, 2017
op_sort.go Fix issue 267: different merging behaviour Sep 18, 2018
op_static_ips.go Fix #201 by supporting `azs` key in subnets Jul 11, 2017
op_vault.go allow SOCKS5 thanks to golang 1.9/1.10 [fixes #253] Mar 17, 2018
operator.go Pass `((varname))` through Spruce Dec 21, 2017
operator_test.go Fix TYPOs in source files (#263) Jun 18, 2018
sort_test.go Add (( sort )) operator Jul 30, 2018
vault_test.go implemented vaultinfo command (#207) Apr 19, 2017

README.md

          *          .---. ,---.  ,---.  .-. .-.  ,--,  ,---.         *
         /.\        ( .-._)| .-.\ | .-.\ | | | |.' .')  | .-'        /.\
        /..'\      (_) \   | |-' )| `-'/ | | | ||  |(_) | `-.       /..'\
        /'.'\      _  \ \  | |--' |   (  | | | |\  \    | .-'       /'.'\
       /.''.'\    ( `-'  ) | |    | |\ \ | `-')| \  `-. |  `--.    /.''.'\
       /.'.'.\     `----'  /(     |_| \)\`---(_)  \____\/( __.'    /.'.'.\
"'""""/'.''.'.\""'"'""""""(__)""""""""(__)"""""""""""""(__)""'""""/'.''.'.\""'"'"
      ^^^[_]^^^                                                   ^^^[_]^^^

Build Status Slack ( We'll be in #spruce)

Introducing Spruce

spruce is a general purpose YAML & JSON merging tool.

It is designed to be an intuitive utility for merging YAML/JSON templates together to generate complicated YAML/JSON config files in a repeatable fashion. It can be used to stitch together some generic/top level definitions for the config and pull in overrides for site-specific configurations to DRY your configs up as much as possible.

How do I get started?

spruce is available via Homebrew, just brew tap starkandwayne/cf; brew install spruce

Alternatively, you can download a prebuilt binaries for 64-bit Linux, or Mac OS X or you can install via go get (provided you have installed go):

go get github.com/geofffranks/spruce/...

Is there a playground I can use before installing spruce?

Yes! play.spruce.cf is around for testing out data merging + transformation in a cleanroom environment. It has a number of spruce versions available to it, and can be used to reproduce/troubleshoot bugs that you're seeing in production. Once you've reproduced an issue, or solution to a problem, you can save it, and share with a colleague, or reference in a GitHub issue.

A Quick Example

# Let's build the first yaml file we will merge
$ cat <<EOF first.yml
some_data: this will be overwritten later
a_random_map:
  key1: some data
heres_an_array:
- first element
EOF

# and now build the second yaml file to merge on top of it
$ cat <<EOF second.yml
some_data: 42
a_random_map:
  key2: adding more data
heres_an_array:
- (( prepend ))
- zeroth element
more_data: 84

# what happens when we spruce merge?
$ spruce merge first.yml second.yml
a_random_map:
  key1: some data
  key2: adding more data
heres_an_array:
- zeroth element
- first element
more_data: 84
some_data: 42

The data in second.yml is overlayed on top of the data in first.yml. Check out the merge semantics and array merging for more info on how that was done. Or, check out this example on play.spruce.cf

Documentation

What else can Spruce do for you?

spruce doesn't just stop at merging datastructures together. It also has the following helpful subcommands:

spruce diff - Allows you to get a useful diff of two YAML files, to see where they differ semantically. This is more than a simple diff tool, as it examines the functional differences, rather than just textual (e.g. key-ordering differences would be ignored)

spruce json - Allows you to convert a YAML document into JSON, for consumption by something that requires a JSON input. spruce merge will handle both YAML + JSON documents, but produce only YAML output.

spruce vaultinfo - Takes a list of files that would be merged together, and analyzes what paths in Vault would be looked up. Useful for determining explicitly what access an automated process might need to Vault to obtain the right credentials, and nothing more. Also useful if you need to audit what credentials your configs are retrieving for a system..

License

Licensed under the MIT License