From a2b804ac1dda1ed52f3c8194447b75c145406791 Mon Sep 17 00:00:00 2001 From: varac Date: Thu, 11 Jun 2015 14:19:28 +0200 Subject: added facts couchdb_version and couchdb_pwhash_alg couchdb v1.3 changed the default pw hashing algorithm from sha1 to pbkdf2, see http://docs.couchdb.org/en/1.4.x/configuring.html the "couchdb_pwhash_alg" fact shows the currently used algorithm by checking the "couchdb_version" fact. --- lib/facter/couchdb_pwhash_alg.rb | 43 ++++++++++++++++++++++++++++++++++++++++ lib/facter/couchdb_version.rb | 34 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 lib/facter/couchdb_pwhash_alg.rb create mode 100644 lib/facter/couchdb_version.rb diff --git a/lib/facter/couchdb_pwhash_alg.rb b/lib/facter/couchdb_pwhash_alg.rb new file mode 100644 index 0000000..42b96b7 --- /dev/null +++ b/lib/facter/couchdb_pwhash_alg.rb @@ -0,0 +1,43 @@ +require 'facter' + +def version_parts ( version ) + # gives back a hash containing major, minor and patch numbers + # of a give version string + + parts = Hash.new + first, *rest = version.split(".") + parts["major"] = first + parts["minor"] = rest[0] + parts["patch"] = rest[1] + return parts +end + +def couchdb_pwhash_alg + # couchdb uses sha1 as pw hash algorithm until v. 1.2, + # but pbkdf2 from v.1.3 on. + # see http://docs.couchdb.org/en/1.4.x/configuring.html for + # details + + couchdb_version = Facter.value(:couchdb_version) + version = version_parts (couchdb_version) + major = version["major"].to_i + alg = case major + when 0 then alg = 'n/a' + when 1 then + minor = version['minor'].to_i + if minor < 3 + alg = 'sha1' + else + alg = 'pbkdf2' + end + else + alg = 'pbkdf2' + end + return alg +end + +Facter.add(:couchdb_pwhash_alg) do + setcode do + couchdb_pwhash_alg + end +end diff --git a/lib/facter/couchdb_version.rb b/lib/facter/couchdb_version.rb new file mode 100644 index 0000000..3a72116 --- /dev/null +++ b/lib/facter/couchdb_version.rb @@ -0,0 +1,34 @@ +require 'facter' + +def deb_installed_version ( name ) + # returns an empty string if package is not installed, + # otherwise the version + + version = `apt-cache policy #{name} | grep Installed 2>&1` + version.slice! " Installed: " + version.slice! "(none)" + return version.strip.chomp +end + +def couchdb_version + bigcouch = deb_installed_version("bigcouch") + if bigcouch.empty? + couchdb = deb_installed_version("couchdb") + if couchdb.empty? + version = 'n/a' + else + version = couchdb + end + else + # bigcouch is currently only available in one version (0.4.2), + # which includes couchdb 1.1.1 + version = '1.1.1' + end + return version +end + +Facter.add(:couchdb_version) do + setcode do + couchdb_version + end +end -- cgit v1.2.3