57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/resources/elasticsearch.rb', line 57
def initialize(opts = {})
return skip_resource 'Package `curl` not avaiable on the host' unless inspec.command('curl').exist?
@url = opts.fetch(:url, 'http://localhost:9200')
username = opts.fetch(:username, nil)
password = opts.fetch(:password, nil)
ssl_verify = opts.fetch(:ssl_verify, true)
cmd = inspec.command(curl_command_string(username, password, ssl_verify))
begin
verify_curl_success!(cmd)
rescue => e
return skip_resource e.message
end
begin
content = JSON.parse(cmd.stdout)
verify_json_payload!(content)
rescue JSON::ParserError => e
return skip_resource "Couldn't parse the Elasticsearch response: #{e.message}"
rescue => e
return skip_resource e.message
end
@nodes = parse_cluster(content)
end
|