class Inspec::Resources::Nginx

def compiler_info

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

def initialize(nginx_path = '/usr/sbin/nginx')

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

def modules

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

def openssl_version

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

def parse_config

def parse_config
  @params[:prefix] = @data.scan(/--prefix=(\S+)\s/).flatten.first
  @params[:service] = 'nginx'
  @params[:version] = @data.scan(%r{nginx version: nginx\/(\S+)\s}).flatten.first
end

def parse_http_path

def parse_http_path
  @params[:http_client_body_temp_path] = @data.scan(/--http-client-body-temp-path=(\S+)\s/).flatten.first
  @params[:http_proxy_temp_path] = @data.scan(/--http-proxy-temp-path=(\S+)\s/).flatten.first
  @params[:http_fastcgi_temp_path] = @data.scan(/--http-fastcgi-temp-path=(\S+)\s/).flatten.first
  @params[:http_uwsgi_temp_path] = @data.scan(/--http-uwsgi-temp-path=(\S+)\s/).flatten.first
  @params[:http_scgi_temp_path] = @data.scan(/--http-scgi-temp-path=(\S+)\s/).flatten.first
end

def parse_path

def parse_path
  @params[:sbin_path] = @data.scan(/--sbin-path=(\S+)\s/).flatten.first
  @params[:modules_path] = @data.scan(/--modules-path=(\S+)\s/).flatten.first
  @params[:error_log_path] = @data.scan(/--error-log-path=(\S+)\s/).flatten.first
  @params[:http_log_path] = @data.scan(/--http-log-path=(\S+)\s/).flatten.first
  @params[:lock_path] = @data.scan(/--lock-path=(\S+)\s/).flatten.first
end

def read_content

def read_content
  parse_config
  parse_path
  parse_http_path
end

def support_info

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

def to_s

def to_s
  'Nginx Environment'
end