Method: Inspec::Resources::Host#initialize

Defined in:
lib/resources/host.rb

#initialize(hostname, params = {}) ⇒ Host

Returns a new instance of Host.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/resources/host.rb', line 47

def initialize(hostname, params = {})
  @hostname = hostname
  @port = params[:port]

  if params[:proto]
    warn '[DEPRECATION] The `proto` parameter is deprecated. Use `protocol` instead.'
    @protocol = params[:proto]
  else
    @protocol = params.fetch(:protocol, 'icmp')
  end

  @host_provider = nil
  if inspec.os.linux?
    @host_provider = LinuxHostProvider.new(inspec)
  elsif inspec.os.windows?
    return skip_resource 'Invalid protocol: only `tcp` and `icmp` protocols are support for the `host` resource on your OS.' unless
      %w{icmp tcp}.include?(@protocol)

    @host_provider = WindowsHostProvider.new(inspec)
  elsif inspec.os.darwin?
    @host_provider = DarwinHostProvider.new(inspec)
  else
    return skip_resource 'The `host` resource is not supported on your OS yet.'
  end

  missing_requirements = @host_provider.missing_requirements(protocol)
  return skip_resource 'The following requirements are not met for this resource: ' \
    "#{missing_requirements.join(', ')}" unless missing_requirements.empty?
end