Giter Club home page Giter Club logo

consulsync's Introduction

consulsync

Syncs a collection of YAML / JSON files to consul KV.

The source files are authoritative and sync is one way (for now). Key & content diffing is performed so only differences will cause KV writes to happen.

Usage

consulsync -datacenter ams2 -consul-address demo.consul.io -kv-prefix test jsonfile1.json yamlfile1.yaml yamlfile2.yaml

You may specify -dryrun to only show the changes that would be made and -quiet to silence any output.

When multiple files are provided, each one is processed in turn in to the same map. This means that the contents of the later files will override the earlier ones.

String filters

While the main purpose of consulsync is to mirror structures from version controlled config files in to KV prefixes, there are some specific serialisation features to make some things nicer to do. These filters cause the subtree of a key to be marshaled in to a string format and stored in the key that contained the trigger tag.

You can specify a trigger tag by appending either !env, !yaml or !json to a key. Please note that everything in the key before the tag is arbitrary and need not contain .json for the json filter for example.

JSON

The following will store the string { "somevalue": "test", "someothervalue": "test" } in the service1/configfile.json key.

The subtree is simply serialized to JSON. Please note that the subtree must be a map / hash type (and not a scalar / list type).

service1:
  configfile.json!json:
    somevalue: test
    someothervalue: test

YAML

The following will store the string somevalue: test\nsomeothervalue: test\n in the service1/configfile.yaml key.

The subtree is simply serialized to YAML.

service1:
  configfile.yaml!yaml:
    somevalue: test
    someothervalue: test

ENV

The following will store the string SOME_VALUE=test\nSOMEOTHERVALUE=test in the service1/configfile.env key.

The subtree is traversed and flattened. All keys are uppercased and nested keys are joined with _. Please note that no escaping is performed on keys nor values at this time.

service1:
  configfile.env!env:
    some:
      value: test
    someothervalue: test

Status

Only tested on a prototype project but PRs welcome.

ACL tokens nor CA certificates are supported at this time but since we are using github.com/hashicorp/consul/api for the consul client, support is there; we just need to expose the options to configure it.

consulsync's People

Contributors

mikesimons avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.