From 235c77d6074e70d9c8fad69f9fbfd19305f0921c Mon Sep 17 00:00:00 2001 From: Dylan Cochran Date: Thu, 22 Jun 2017 20:16:27 -0400 Subject: [PATCH 1/3] (SIMP-3087) Add libkv::lookup hierav5 backend function Add a libkv::lookup hierav5 function that returns it in hiera style SIMP-3087 #close --- functions/lookup.pp | 37 +++++++++++++++++++++++++++++++++++++ lib/puppet_x/libkv/libkv.rb | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 functions/lookup.pp diff --git a/functions/lookup.pp b/functions/lookup.pp new file mode 100644 index 0000000..483c43e --- /dev/null +++ b/functions/lookup.pp @@ -0,0 +1,37 @@ +function libkv::lookup( + Variant[String, Numeric] $key, + Hash $options, + Puppet::LookupContext $context, +) { + case $key { + "lookup_options": { + $context.not_found + } + "libkv::auth": { + $context.not_found + } + "libkv::url": { + $context.not_found + } + default: { + if ($options["uri"] == undef) { + $_key = "/${key}" + $_url = undef + } else { + if ($options["uri"] =~ /.*:\/\/.*\/.*/) { + $_key = "/${key}" + $_url = $options["uri"] + } else { + $_key = "${uri}/${key}" + $_url = undef + } + + } + if (libkv::exists({ "url" => $_url, "key" => $_key})) { + libkv::get({ "url" => $_url, "key" => $_key}) + } else { + $context.not_found + } + } + } +} diff --git a/lib/puppet_x/libkv/libkv.rb b/lib/puppet_x/libkv/libkv.rb index bee826f..b98ec9d 100644 --- a/lib/puppet_x/libkv/libkv.rb +++ b/lib/puppet_x/libkv/libkv.rb @@ -105,7 +105,7 @@ def sanitize_input(symbol, params) unless (params[name].class.to_s == "String") raise "parameter #{name} should be String, found #{params[name].class.to_s}" end - regex = /^\/[a-zA-Z0-9._\-\/]*$/ + regex = /^\/[a-zA-Z0-9._:\-\/]*$/ error_msg = "the value of '#{name}': '#{params[name]}' does not match regex '#{regex}'" unless (regex =~ params[name]) raise error_msg From 5bb3c88054e1f678a00dd6f13f46869928424033 Mon Sep 17 00:00:00 2001 From: Dylan Cochran Date: Sat, 24 Jun 2017 20:31:02 -0400 Subject: [PATCH 2/3] (SIMP-3360) Use module data for certificate paths Replace hard coded certificate paths with APL lookups SIMP-3360 #close --- data/common.yaml | 1 + data/kernel/FreeBSD.yaml | 1 + hiera.yaml | 3 +++ manifests/consul.pp | 7 ++++--- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 data/kernel/FreeBSD.yaml diff --git a/data/common.yaml b/data/common.yaml index 1b2d0ac..7e1a0f3 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,6 +1,7 @@ lookup_options: libkv::consul::config_hash: merge: hash +libkv::consul::puppet_cert_path: '/etc/puppetlabs/puppet/ssl' libkv::consul::config_hash: acl_datacenter: "dc1" acl_default_policy: "deny" diff --git a/data/kernel/FreeBSD.yaml b/data/kernel/FreeBSD.yaml new file mode 100644 index 0000000..e612713 --- /dev/null +++ b/data/kernel/FreeBSD.yaml @@ -0,0 +1 @@ +libkv::consul::puppet_cert_path: '/var/puppet/ssl' diff --git a/hiera.yaml b/hiera.yaml index fd217b7..811bc7a 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -5,6 +5,9 @@ hierarchy: - name: "OSFamily + Release" backend: "yaml" path: "os/%{facts.osfamily}-%{facts.operatingsystemmajrelease}" + - name: "Kernel" + backend: "yaml" + path: "kernel/%{facts.kernel}" - name: "Common" backend: "yaml" path: "common" diff --git a/manifests/consul.pp b/manifests/consul.pp index f617175..a84c9f8 100644 --- a/manifests/consul.pp +++ b/manifests/consul.pp @@ -12,6 +12,7 @@ $serverhost = undef, $advertise = undef, $datacenter = undef, + $puppet_cert_path, $ca_file_name = undef, $private_file_name = undef, $cert_file_name = undef, @@ -142,9 +143,9 @@ } } } else { - $_cert_file_name_source = "/etc/puppetlabs/puppet/ssl/certs/${::clientcert}.pem" - $_ca_file_name_source = '/etc/puppetlabs/puppet/ssl/certs/ca.pem' - $_private_file_name_source = "/etc/puppetlabs/puppet/ssl/private_keys/${::clientcert}.pem" + $_cert_file_name_source = "${puppet_cert_path}/certs/${::clientcert}.pem" + $_ca_file_name_source = "${puppet_cert_path}/certs/ca.pem" + $_private_file_name_source = "${puppet_cert_path}/private_keys/${::clientcert}.pem" file { '/etc/simp/consul/cert.pem': source => $_cert_file_name_source } From 3f4240e5c18d8499f67f465e712e95a1a0fab625 Mon Sep 17 00:00:00 2001 From: Dylan Cochran Date: Mon, 10 Jul 2017 17:26:04 -0400 Subject: [PATCH 3/3] Release 0.3.1 --- CHANGELOG | 6 +++++- metadata.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 98d4243..abb1646 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,8 @@ -* Sat Jul 10 2017 Dylan Cochran - 0.3.0 +* Mon Jul 10 2017 Dylan Cochran - 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 - 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 diff --git a/metadata.json b/metadata.json index 64072f4..7bc078b 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "simp-libkv", - "version": "0.3.0", + "version": "0.3.1", "author": "simp", "summary": "", "license": "Apache-2.0",