mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
2857d07151
The opening and closing mechanic varied between all the various resources. This changes them all to use a HEREDOC with a tilde to remove leading whitespace. This removes the need for the special method to trim the `#print_example` method from shell. Signed-off-by: Franklin Webber <franklin.webber@gmail.com>
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
|
|
require 'utils/erlang_parser'
|
|
require 'utils/file_reader'
|
|
|
|
module Inspec::Resources
|
|
class RabbitmqConf < Inspec.resource(1)
|
|
name 'rabbitmq_config'
|
|
supports platform: 'unix'
|
|
desc 'Use the rabbitmq_config InSpec resource to test configuration data '\
|
|
'for the RabbitMQ service located in /etc/rabbitmq/rabbitmq.config on '\
|
|
'Linux and UNIX platforms.'
|
|
example <<~EXAMPLE
|
|
describe rabbitmq_config.params('rabbit', 'ssl_listeners') do
|
|
it { should cmp 5671 }
|
|
end
|
|
EXAMPLE
|
|
|
|
include FileReader
|
|
|
|
def initialize(conf_path = nil)
|
|
@conf_path = conf_path || '/etc/rabbitmq/rabbitmq.config'
|
|
@content = read_file_content(@conf_path, allow_empty: true)
|
|
end
|
|
|
|
def params(*opts)
|
|
opts.inject(read_params) do |res, nxt|
|
|
res.respond_to?(:key) ? res[nxt] : nil
|
|
end
|
|
end
|
|
|
|
def to_s
|
|
"rabbitmq_config #{@conf_path}"
|
|
end
|
|
|
|
private
|
|
|
|
def read_content
|
|
return @content if defined?(@content)
|
|
@content = read_file_content(@conf_path, allow_empty: true)
|
|
end
|
|
|
|
def read_params
|
|
return @params if defined?(@params)
|
|
return @params = {} if read_content.nil?
|
|
@params = ErlangConfigFile.parse(read_content)
|
|
rescue Parslet::ParseFailed
|
|
raise "Cannot parse RabbitMQ config: \"#{read_content}\""
|
|
end
|
|
end
|
|
end
|