inspec/examples/profile/libraries/gordon_config.rb

44 lines
936 B
Ruby
Raw Normal View History

2015-12-14 13:23:41 +00:00
require 'yaml'
# Custom resource based on the InSpec resource DSL
2015-12-14 13:23:41 +00:00
class GordonConfig < Inspec.resource(1)
name 'gordon_config'
desc "
Gordon's resource description ...
"
example "
describe gordon_config do
its('version') { should eq('1.0') }
its('size') { should > 1 }
end
"
# Load the configuration file on initialization
2015-12-14 13:23:41 +00:00
def initialize
@path = '/tmp/gordon/config.yaml'
2015-12-14 13:23:41 +00:00
@file = inspec.file(@path)
return skip_resource "Can't find file \"#{@path}\"" if !@file.file?
# Protect from invalid YAML content
begin
@params = YAML.load(@file.content)
rescue Exception
return skip_resource "#{@file}: #{$!}"
end
add_some_extra_params
end
# Extra Ruby helper method
def add_some_extra_params
@params['size']=@file.size
@params['md5sum']=@file.md5sum
2015-12-14 13:23:41 +00:00
end
# Expose all parameters
2015-12-14 13:23:41 +00:00
def method_missing(name)
@params[name.to_s]
end
end