Sha256: 72bdcc95d326f7cad1232858a9daef5277bc1ea50f89ab2ff598ad1f9a6850e5

Contents?: true

Size: 1.44 KB

Versions: 68

Compression:

Stored size: 1.44 KB

Contents

require "inspec/resources/command"

module Inspec::Resources
  class ZfsDataset < Inspec.resource(1)
    name "zfs_dataset"
    supports platform: "unix"
    desc "
      Use the zfs_dataset InSpec audit resource to test if the named
      ZFS Dataset is present and/or has certain properties.
    "
    example <<~EXAMPLE
      describe zfs_dataset('tank/tmp') do
        its('exec') { should eq('off') }
        its('setuid') { should eq('off') }
      end
    EXAMPLE

    def initialize(zfs_dataset)
      return skip_resource "The `zfs_dataset` resource is not supported on your OS yet." unless inspec.os.bsd?

      @zfs_dataset = zfs_dataset

      @params = gather
    end

    # method called by 'it { should exist }'
    def exists?
      inspec.command("/sbin/zfs get -Hp all #{@zfs_dataset}").exit_status == 0
    end

    def mounted?
      return false unless exists?

      inspec.mount(@params["mountpoint"]).mounted?
    end

    def to_s
      "ZFS Dataset #{@zfs_dataset}"
    end

    def gather
      cmd = inspec.command("/sbin/zfs get -Hp all #{@zfs_dataset}")
      return nil if cmd.exit_status.to_i != 0

      # parse data
      cmd.stdout.chomp.split("\n").each_with_object(Hash.new(0)) do |line, h|
        t = line.split("\t")
        h[t[1].to_s] = t[2].to_s
      end
    end

    # override method
    def exec
      @params["exec"]
    end

    # expose all parameters
    def method_missing(name)
      @params[name.to_s]
    end
  end
end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
inspec-core-4.37.8 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.37.0 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.36.4 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.33.1 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.32.0 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.31.1 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.31.0 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.29.3 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.28.0 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.26.13 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.26.4 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.25.1 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.24.32 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.24.28 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.24.26 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.24.8 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.23.15 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.23.11 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.23.10 lib/inspec/resources/zfs_dataset.rb
inspec-core-4.23.4 lib/inspec/resources/zfs_dataset.rb