2015-12-14 13:23:41 +00:00
|
|
|
require 'yaml'
|
|
|
|
|
2016-03-24 19:19:14 +00:00
|
|
|
# Custom resource based on the InSpec resource DSL
|
2015-12-14 13:23:41 +00:00
|
|
|
class GordonConfig < Inspec.resource(1)
|
|
|
|
name 'gordon_config'
|
|
|
|
|
2016-03-24 19:19:14 +00:00
|
|
|
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
|
2016-03-24 19:19:14 +00:00
|
|
|
@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?
|
|
|
|
|
2016-03-24 19:19:14 +00:00
|
|
|
# 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
|
2016-03-24 19:50:29 +00:00
|
|
|
@params['size'] = @file.size
|
|
|
|
@params['md5sum'] = @file.md5sum
|
2015-12-14 13:23:41 +00:00
|
|
|
end
|
|
|
|
|
2016-03-24 19:19:14 +00:00
|
|
|
# Expose all parameters
|
2015-12-14 13:23:41 +00:00
|
|
|
def method_missing(name)
|
|
|
|
@params[name.to_s]
|
|
|
|
end
|
|
|
|
end
|