mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
CFINSPEC-96: Add zfs resource with new matcher
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
b98a802be3
commit
3449285273
1 changed files with 46 additions and 0 deletions
46
lib/inspec/resources/zfs.rb
Normal file
46
lib/inspec/resources/zfs.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require "inspec/resources/zfs_pool"
|
||||
|
||||
module Inspec::Resources
|
||||
class MyCustomResource < ZfsPool
|
||||
# resource's internal name.
|
||||
name "zfs"
|
||||
|
||||
# Restrict to only run on the below platforms
|
||||
supports platform: "unix"
|
||||
|
||||
desc "Use the zfs InSpec audit resource to test if the named ZFS Pool is present and/or has certain properties."
|
||||
|
||||
example <<~EXAMPLE
|
||||
describe zfs("new-pool") do
|
||||
it { should exist }
|
||||
it { should have_property({"failmode" => "wait", "capacity"=>"0"}) }
|
||||
end
|
||||
EXAMPLE
|
||||
|
||||
# Resource initialization is done in the parent class i.e. ZfsPool
|
||||
|
||||
# Unique identity for the resource.
|
||||
def resource_id
|
||||
# @zfs_pool is the zfs pool name assigned during initialization in the parent class i.e. ZfsPool
|
||||
@zfs_pool
|
||||
end
|
||||
|
||||
# Resource appearance in test reports.
|
||||
def to_s
|
||||
"zfs #{resource_id}"
|
||||
end
|
||||
|
||||
# The below matcher checks if the given properties are valid properties of the zfs pool.
|
||||
def has_property?(properties_hash)
|
||||
raise Inspec::Exceptions::ResourceSkipped, "Provide a valid key-value pair of the zfs properties." if properties_hash.empty?
|
||||
|
||||
# Transform all the keys to string, since hash keys provided by user can be symbols or strings.
|
||||
# @params is a hash populated in the parent class with the properties(key-value) of the current zfs pool.
|
||||
# The keys in the @params are of string type.
|
||||
properties_hash.transform_keys(&:to_s)
|
||||
|
||||
# check if the given properties is a subset of @params
|
||||
properties_hash <= @params
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue