Class: Inspec::Resources::Nginx

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/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.



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

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?

  @nginx_path = nginx_path
  cmd = inspec.command("#{nginx_path} -V 2>&1")
  if cmd.exit_status != 0
    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.



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

def bin_dir
  @bin_dir
end

#nginx_pathObject (readonly)

Returns the value of attribute nginx_path.



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

def nginx_path
  @nginx_path
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#compiler_infoObject



49
50
51
52
# File 'lib/inspec/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/inspec/resources/nginx.rb', line 59

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

#openssl_versionObject



44
45
46
47
# File 'lib/inspec/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

#resource_idObject



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

def resource_id
  nginx_path || "nginx"
end

#support_infoObject



54
55
56
57
# File 'lib/inspec/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



67
68
69
# File 'lib/inspec/resources/nginx.rb', line 67

def to_s
  "Nginx Environment"
end