mirror of
https://github.com/inspec/inspec
synced 2024-12-25 20:43:13 +00:00
43 lines
940 B
Ruby
43 lines
940 B
Ruby
require 'yaml'
|
|
|
|
# Custom resource based on the InSpec resource DSL
|
|
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
|
|
def initialize
|
|
@path = '/tmp/gordon/config.yaml'
|
|
@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
|
|
end
|
|
|
|
# Expose all parameters
|
|
def method_missing(name)
|
|
@params[name.to_s]
|
|
end
|
|
end
|