jsonconsul

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2015 License: MIT Imports: 14 Imported by: 0

README

jsonconsul

Build Status

jsonconsul allows the creation of json files from the values that are located in Consul. It also contains the ability to import KV keys into Consul.

Usage

Set

To set a key and also verify that the value is valid JSON run the following command.

jsonconsul set path/to/key \"validjsonvalue\"
Import

A json config can be used to update key values in Consul.

Here is an example file named example.json

{"foo":{"bar":"test","blah":"Test","do":"TEST","loud":{"asd":{"bah":"test"}}}}

Now if we want to import this into the root prefix then we'd do the following:

jsonconsul import example.json

To import into an alternate prefix the following needs to be done:

jsonconsul import -prefix='vsco/buzz' example.json
Export

There are five ways to run jsonconsul export. There are:

  • Output to STDOUT
  • Output to file
  • Output to file but timestamp the output file and symlink to name.
  • Poll and output to file after a duration.
  • Poll and output to file after a duration but with timestamped output file.

Options:

  • -json-values Convert the values from Consul and treat them as JSON values.
Output to STDOUT
jsonconsul export -prefix="foo"

If we don't want to include the prefix in the outputed json:

jsonconsul export -include-prefix=false -prefix="foo"
Output to file
jsonconsul export -prefix="foo" foo.json
Output to file with timestamp
jsonconsul export -prefix="foo" -timestamp foo.json

This generates a file called foo.json.<unixtimestamp>. foo.json will then be a symbolic link to foo.json.<unixtimestamp>.

Watch and output to file
jsonconsul watch -prefix="foo" foo.json

This polls consul every minute for changes and outputs those values to json. If an alternate frequency is preferred then include the -watch-frequency flag.

Watch and output to file with timestamp
jsonconsul watch -prefix="foo" -timestamp foo.json

License

The MIT License (MIT)

Copyright (c) 2015 Visual Supply, Co.

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.

Documentation

Overview

Methods which interact directly with Consul. Should isolate the code for consul here.

Index

Examples

Constants

View Source
const (
	Undefined int = iota
	Bool
	Number
	String
	Array
	Object
)
View Source
const (
	Name = "jsonconsul"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonExport

type JsonExport struct {
	// KV Path in Consul
	Prefix string
	// Place to put the config file
	ConfigFile string
	// If we are overwriting the ConfigFile should we timestamp
	// the versions so that there is a trail.
	Timestamp bool
	// Should we poll for consul changes.
	Watch bool
	// Should the output include the nodes in the included prefix?
	IncludePrefix bool
	// Parse the Values as Json
	JsonValues bool

	FlattenedKVs map[string]interface{}
	// contains filtered or unexported fields
}

func (*JsonExport) GenerateJson

func (c *JsonExport) GenerateJson() ([]byte, error)

func (*JsonExport) ParseFlags

func (c *JsonExport) ParseFlags(args []string)

func (*JsonExport) Run

func (c *JsonExport) Run() error

func (*JsonExport) RunWatcher

func (c *JsonExport) RunWatcher()

func (*JsonExport) WriteFile

func (c *JsonExport) WriteFile(newJson []byte) error

type JsonImport

type JsonImport struct {
	// Prefix to load the config under. If empty then loads to the
	// root kv node.
	Prefix string
	// File containing the Json to be converted to KVs.
	Filename string

	FlattenedKVs map[string]interface{}
}

func (*JsonImport) ParseFlags

func (ji *JsonImport) ParseFlags(args []string)

func (*JsonImport) Run

func (ji *JsonImport) Run() error
Example
ji := &JsonImport{Filename: "example.json"}
ji.Run()

je := &JsonExport{Prefix: "foo", IncludePrefix: true, JsonValues: true}
je.Run()
Output:

{"foo":{"bar":"test","blah":"Test","bool":true,"do":"TEST","float":1.23,"loud":{"asd":{"bah":"test"}},"null":null}}

type JsonSet

type JsonSet struct {
	// The Consul Key to set.
	Key string
	// The value that was passed by the command line.
	Value string
	// What we expect the value type to be.
	ExpectedType int
	// The actual Json Value that is going to be saved to Consul.
	JsonValue []byte
}

func (*JsonSet) ParseFlags

func (js *JsonSet) ParseFlags(args []string)

func (*JsonSet) Run

func (js *JsonSet) Run() error

type Runner added in v0.4.0

type Runner struct {
	sync.RWMutex

	// Prefix is the KeyPrefixDependency associated with this Runner.
	Prefix *dep.StoreKeyPrefix

	// ErrCh and DoneCh are channels where errors and finish notifications occur.
	ErrCh  chan error
	DoneCh chan struct{}

	// ExitCh is a channel for parent processes to read exit status values from
	// the child processes.
	ExitCh chan int
	// contains filtered or unexported fields
}

func NewRunner added in v0.4.0

func NewRunner(config *JsonExport, once bool) (*Runner, error)

NewRunner accepts a JsonExport, and boolean value for once mode.

func (*Runner) Receive added in v0.4.0

func (r *Runner) Receive(d dep.Dependency, data interface{})

Receive accepts data from Consul and maps that data to the prefix.

func (*Runner) Run added in v0.4.0

func (r *Runner) Run()

Run executes and manages the child process with the correct environment. The current enviornment is also copied into the child process environment.

func (*Runner) Start added in v0.4.0

func (r *Runner) Start()

Start creates a new runner and begins watching dependencies and quiescence timers. This is the main event loop and will block until finished.

func (*Runner) Stop added in v0.4.0

func (r *Runner) Stop()

Stop halts the execution of this runner and its subprocesses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL