Version information
This version is compatible with:
- Puppet Enterprise 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
- Puppet 4.x
- ,
Start using this module
Add this module to your Puppetfile:
mod 'simp-libkv', '0.6.1'
Learn more about managing modules with a PuppetfileDocumentation
Table of Contents
-
- libkv::get
- libkv::put
- libkv::delete
- libkv::exists
- libkv::list
- libkv::deletetree
- libkv::atomic_create
- libkv::atomic_delete
- libkv::atomic_get
- libkv::atomic_put
- libkv::atomic_list
- libkv::empty_value
- libkv::info
- libkv::supports
- libkv::pop_error
- libkv::provider
- libkv::watch
- libkv::watchtree
- libkv::newlock
Description
libkv is an abstract library that allows puppet to access a distributed key value store, like consul or etcd. This library implements all the basic key/value primitives, get, put, list, delete. It also exposes any 'check and set' functionality the underlying store supports. This allows building of safe atomic operations, to build complex distributed systems. This library supports loading 'provider' modules that exist in other modules, and provides a first class api.
libkv uses lookup to store authentication information. This information can range from ssl client certificates, access tokens, or usernames and passwords. It is exposed as a hash named libkv::auth, and will be merged by default. The keys in the auth token are passed as is to the provider, and can vary between providers. Please read the documentation on configuring 'libkv::auth' for each provider
libkv currently supports the following providers:
mock
- Useful for testing, as it provides a kv store that is destroyed after each catalog compilationconsul
- Allows connectivity to an existing consul service
With the intention to support the following:
etcd
- Allows connectivity to an existing etcd servicesimp6-legacy
- Implements the SIMP 6 legacy file storage api.file
- Implements a non-ha flat file storage api.
This module is a component of the System Integrity Management Platform, a compliance-management framework built on Puppet.
If you find any issues, they may be submitted to our bug tracker.
Usage
As an example, you can use the following to store hostnames, and then read all the known hostnames from consul and generate a hosts file:
libkv::put("/hosts/${::clientcert}", $::ipaddress)
$hosts = libkv::list("/hosts")
$hosts.each |$host, $ip | {
host { $host:
ip => $ip,
}
}
Each key specified must contain only the following characters:
- a-z
- A-Z
- 0-9
- The following special characters:
._:-/
Additionally, /./
and /../
are disallowed in all providers as key
components. The key name also must begin with /
When any libkv function is called, it will first call lookup()
and attempt to
find a value for libkv::url from hiera. This url specifies the provider name,
the host, the port, and the path in the underlying store. For example:
libkv::url: 'consul://127.0.0.1:8500/puppet'
libkv::url: 'consul+ssl://1.2.3.4:8501/puppet'
libkv::url: 'file://'
libkv::url: 'etcd://127.0.0.1:2380/puppet/%{environment}/'
libkv::url: 'consul://127.0.0.1:8500/puppet/%{trusted.extensions.pp_department}/%{environment}'
Testing
Manual and automated tests require a shim to kick off Consul inside of Docker, before running. Travis is programmed to run the shim. To do so manually, first ensure you have set up Docker properly.
Next, run the shim:
$ ./prep_ci.sh
NOTE: There is a bug which will not allow the containers to deploy if selinux is enforcing. Set to permissive or disabled.
Run the unit tests:
$ bundle exec rake spec
Function reference
Connects to the backend and retrieves the data stored at key
Any $data = libkv::get(String key)
Returns: Any
Usage:
Sets the data at key
to the specified value
Boolean $suceeeded = libkv::put(String key, Any value)
Returns: Boolean
Usage:
Deletes the specified key
. Must be a single key
Boolean $suceeeded = libkv::delete(String key)
Returns: Boolean
Usage:
Returns true if key
exists
Boolean $exists = libkv::exists(String key)
Returns: Boolean
Usage:
Lists all keys in the folder named key
Hash $list = libkv::list(String key)
Returns: Hash
Usage:
Deletes the whole folder named key
. This action is inherently unsafe.
Boolean $succeeded = libkv::deletetree(String key)
Returns: Boolean
Usage:
Store value
in key
, but only if key does not exist already, and do so atomically
Boolean $suceeeded = libkv::atomic_create(String key, Any value)
Returns: Boolean
Usage:
Delete key
, but only if key still matches the value of previous
Boolean $suceeded = libkv::atomic_delete(String key, Hash previous)
Returns: Boolean
Usage:
Get the value of key, but return it in a hash suitable for use with other atomic functions
Hash $previous = libkv::atomic_get(String key)
Returns: Hash
Usage:
Set key
to value
, but only if the key is still set to previous
Boolean $suceeeded = libkv::atomic_put(String key, Any value, Hash previous)
Returns: Boolean
Usage:
List all keys in folder key
, but return them in a format suitable for other atomic functions
Hash $list = libkv::atomic_list(String key)
Returns: Hash
Usage:
Return an hash suitable for other atomic functions, that represents an empty value
Hash $empty_value = libkv::empty_value()
Returns: Hash
Usage:
Return a hash of informtion on the underlying provider. Provider specific
Hash $provider_information = libkv::info()
Returns: Hash
Usage:
Return an array of all supported functions
Array $supported_functions = libkv::supports()
Returns: Array
Usage:
Return the error message for the last call
Return the name of the current provider
String $provider_name = libkv::provider()
Returns: String
Usage:
Development
Please read our Contribution Guide.
Acceptance tests
This module includes Beaker acceptance tests using the SIMP Beaker Helpers. By default the tests use Vagrant with VirtualBox as a back-end; Vagrant and VirtualBox must both be installed to run these tests without modification. To execute the tests run the following:
bundle install
bundle exec rake beaker:suites
Please refer to the SIMP Beaker Helpers documentation for more information.
- Thu Oct 26 2017 Nick Markowski nicholas.markowski@onyxpoint.com - 0.6.0
- (SIMP-3923) Moved libkv::consul to pupmod-simp-simp_consul
- Updated README
- Updated travis with CI credentials
- Wed Oct 25 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.5.0
- (SIMP-3445) Add acceptance test for consul configuration and bootstrap
- (SIMP-3629) libkv::atomic_put returns false for a successful put on consul >0.9.0
- Thu Aug 24 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.4.3
- (SIMP-3623) libkv::lookup_key backend should turn softfail on by default
- Add fix for 0.9.x consul installations
- Tue Jul 18 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.4.2
- (SIMP-3001) Prevent '.' and '..' from being used in keys
- (SIMP-3446) Add parameters to reconfigure http and https listen
- (SIMP-3429) libkv::list isn't always removing keys
- Tue Jul 18 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.4.1
- Always copy over consul-acl, and update metadata
- Tue Jul 18 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.4.0
- (SIMP-3275) libkv auto-config uses the root acl
- Tue Jul 11 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.3.3
- (SIMP-3406) Fix docker containers for travisci
- (SIMP-3128) Delete .meta keys
- Tue Jul 11 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.3.2
- (SIMP-3407) Fix idempoency on acl token generation
- (SIMP-3403) Spurious 'undefined method unpack'
- Mon Jul 10 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.3.1
- (SIMP-3360) Use module data for certificate paths
- (SIMP-3087) Add libkv::lookup hierav5 backend function
- Mon Jul 10 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.3.0
- (SIMP-2961) Add automatic cluster creation for consul.
- (SIMP-3130) metadata needs to default to 'String'.
- (SIMP-3129) atomic_create needs to create metadata
- (SIMP-3127) libkv can't list / since metadata update
- (SIMP-3122) Move the libkv wrapper outside the loader
- (SIMP-3125) Move key regex match into libkv wrapper
- (SIMP-3110) Use .meta to convert a value to the correct type
- (SIMP-3060) Fix travisci tests
- (SIMP-3109) Create a .meta key to store type
- Sat Apr 29 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.2.0
- (SIMP-2978) Fix readme generation
- (SIMP-3019) Add ssl/tls support to consul backend
- (SIMP-2962) Add consul_members fact
- (SIMP-3097) Add 'serialize' and 'mode' parameters to all libkv functions
- (SIMP-3102) Flesh out spec tests
- (SIMP-2964) Add generic 'libkv::auth' parameter
- Fri Jan 6 2017 Dylan Cochran dylan.cochran@onyxpoint.com - 0.1.0
- Initial release
Dependencies
- puppetlabs/stdlib (>= 4.9.0 < 5.0.0)
libkv - Per Section 105 of the Copyright Act of 1976, these works are not entitled to domestic copyright protection under US Federal law. The US Government retains the right to pursue copyright protections outside of the United States. The United States Government has unlimited rights in this software and all derivatives thereof, pursuant to the contracts under which it was developed and the License under which it falls. --- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.