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.



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

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.



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

def bin_dir
  @bin_dir
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#compiler_infoObject



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

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



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

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

#openssl_versionObject



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

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



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

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

#to_sObject



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

def to_s
  'Nginx Environment'
end