diff --git a/lib/puppet/parser/functions/osquery_sorted_json.rb b/lib/puppet/parser/functions/osquery_sorted_json.rb deleted file mode 100644 index 6081326..0000000 --- a/lib/puppet/parser/functions/osquery_sorted_json.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'json' - -def sorted_json(obj) - case obj - when String, Fixnum, Float, TrueClass, FalseClass, NilClass - return obj.to_json - when Array - arrayRet = [] - obj.each do |a| - arrayRet.push(sorted_json(a)) - end - return "[" << arrayRet.join(',') << "]"; - when Hash - ret = [] - obj.keys.sort.each do |k| - ret.push(k.to_json << ":" << sorted_json(obj[k])) - end - return "{" << ret.join(",") << "}"; - else - raise Exception("Unable to handle object of type <%s>" % obj.class.to_s) - end -end - -def pretty_sorted_json(obj, indent=0) - # calculate the number of spaces to indent - prefix = " ".*(indent) - # use a leading space before new structures except on the first - leading_space = indent == 0 ? '' : ' ' - case obj - when String, Fixnum, Float, TrueClass, FalseClass, NilClass - return "#{prefix}#{obj.to_json}" - when Array - arrayRet = [] - obj.each do |a| - arrayRet.push(pretty_sorted_json(a, indent+2)) - end - return "#{leading_space}[\n" << arrayRet.join(",\n") << "\n#{prefix}]"; - when Hash - ret = [] - obj.keys.sort.each do |k| - ret.push( ' ' + prefix + k.to_json << ":" << pretty_sorted_json(obj[k], indent+2)) - end - return "#{leading_space}{\n" << ret.join(",\n") << "\n#{prefix}}"; - else - raise Exception("Unable to handle object of type <%s>" % obj.class.to_s) - end -end - -module Puppet::Parser::Functions - newfunction(:osquery_sorted_json, :type => :rvalue, :doc => <<-EOS -This function takes data, outputs making sure the hash keys are sorted - -*Examples:* - - osquery_sorted_json({'key'=>'value'}, 'simple') - -Would return: {'key':'value'} - - osquery_sorted_json({'key'=> ['value','another']}, 'pretty') - -Would return: -{ - 'key': [ - 'value', - 'another' - ] -} - EOS - ) do |arguments| - raise(Puppet::ParseError, "osquery_sorted_json(): Wrong number of arguments " + - "given (#{arguments.size} for 2)") if arguments.size != 2 - - input = arguments[0] - if arguments[1] == 'pretty' - return pretty_sorted_json(input) - elsif arguments[1] == 'simple' - return sorted_json(input) - else - raise(Puppet::ParseError, "osquery_sorted_json(): Invalid format given") - end - end -end diff --git a/manifests/config.pp b/manifests/config.pp index 7c9b6ce..7ea25a2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,14 +1,9 @@ # class osquery::config - manage json config in /etc/osquery -class osquery::config ( - - $format = 'simple' - -){ - include '::stdlib' +class osquery::config { file { $::osquery::config: ensure => present, - content => osquery_sorted_json($::osquery::settings, $format), # format as JSON + content => to_json_pretty($::osquery::settings), owner => $::osquery::config_user, group => $::osquery::config_group, require => Package[$::osquery::package_name], @@ -17,8 +12,6 @@ if has_key($::osquery::settings, 'packs') { $packs = keys($::osquery::settings['packs']) - osquery::pack { $packs: - format => $format, - } + osquery::pack { $packs: } } } diff --git a/manifests/pack.pp b/manifests/pack.pp index d50bf49..8a8590a 100644 --- a/manifests/pack.pp +++ b/manifests/pack.pp @@ -1,7 +1,6 @@ # define osquery::pack - manage json config in pack file define osquery::pack( $pack_file = $::osquery::settings['packs'][$title], - $format = 'simple', $pack_input = hiera_hash("osquery::pack::${title}", undef), $owner = 'root', $group = 'root', @@ -13,7 +12,7 @@ ensure => present, owner => $owner, group => $group, - content => osquery_sorted_json($pack_input, $format), # convert to JSON + content => to_json_pretty($pack_input), require => Package[$::osquery::package_name], notify => Service[$::osquery::service_name], } diff --git a/metadata.json b/metadata.json index 0632817..c033df1 100644 --- a/metadata.json +++ b/metadata.json @@ -8,14 +8,20 @@ "project_page": "https://github.com/BIAndrews/puppet-osquery", "issues_url": "https://github.com/BIAndrews/puppet-osquery/issues", "dependencies": [ - {"name":"puppetlabs-apt","version_requirement":">= 2.0.0"}, - {"name":"puppetlabs-stdlib","version_requirement":">= 2.2.1"} + { + "name":"puppetlabs-apt", + "version_requirement":">= 2.0.0" + }, + { + "name":"puppetlabs-stdlib", + "version_requirement": ">= 4.25.0 < 9.0.0" + } ], "tags": ["osquery","security","compliance","pci-dss","audit"], "requirements": [ { "name": "puppet", - "version_requirement": ">= 3.3.0" + "version_requirement": ">= 6.1.0 < 8.0.0" } ], "operatingsystem_support": [