Class: Inspec::Resources::Nginx

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/nginx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nginx_path = '/usr/sbin/nginx') ⇒ Nginx

Returns a new instance of Nginx.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resources/nginx.rb', line 25

def initialize(nginx_path = '/usr/sbin/nginx')
  return skip_resource 'The `nginx` resource is not yet available on your OS.' if inspec.os.windows?
  return skip_resource 'The `nginx` binary not found in the path provided.' unless inspec.command(nginx_path).exist?

  cmd = inspec.command("#{nginx_path} -V 2>&1")
  if !cmd.exit_status.zero?
    return skip_resource 'Error using the command nginx -V'
  end
  @data = cmd.stdout
  @params = {}
  read_content
end

Instance Attribute Details

#bin_dirObject (readonly)

Returns the value of attribute bin_dir.



23
24
25
# File 'lib/resources/nginx.rb', line 23

def bin_dir
  @bin_dir
end

#paramsObject (readonly)

Returns the value of attribute params.



23
24
25
# File 'lib/resources/nginx.rb', line 23

def params
  @params
end

Instance Method Details

#compiler_infoObject



49
50
51
52
# File 'lib/resources/nginx.rb', line 49

def compiler_info
  result = @data.scan(/built by (\S+)\s(\S+)\s(\S+)/).flatten
  Hashie::Mash.new({ 'compiler' => result[0], 'version' => result[1], 'date' => result[2] })
end

#modulesObject



59
60
61
# File 'lib/resources/nginx.rb', line 59

def modules
  @data.scan(/--with-(\S+)_module/).flatten
end

#openssl_versionObject



44
45
46
47
# File 'lib/resources/nginx.rb', line 44

def openssl_version
  result = @data.scan(/built with OpenSSL\s(\S+)\s(\d+\s\S+\s\d{4})/).flatten
  Hashie::Mash.new({ 'version' => result[0], 'date' => result[1] })
end

#support_infoObject



54
55
56
57
# File 'lib/resources/nginx.rb', line 54

def support_info
  support_info = @data.scan(/(.*\S+) support enabled/).flatten
  support_info.empty? ? nil : support_info.join(' ')
end

#to_sObject



63
64
65
# File 'lib/resources/nginx.rb', line 63

def to_s
  'Nginx Environment'
end