Module: Wazuh::Connection

Included in:
Client
Defined in:
lib/wazuh/connection.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wazuh/connection.rb', line 33

def connection
  options = { url: config.api_endpoint, headers: config.http_request_headers, request: config.request, proxy: config.proxy }
  options[:ssl] = {
    ca_file: config.ca_file,
    client_key: ::OpenSSL::PKey::RSA.new(File.read(config.client_key)),
    client_cert: ::OpenSSL::X509::Certificate.new(File.read(config.client_cert))
  } if config.client_cert && config.client_key && config.ca_file

  @connection ||= Faraday.new(options) do |faraday|
    faraday.use Wazuh::Response::RaiseError
    faraday.use Faraday::Response::Logger if ENV['DEBUG'] == '1'
    faraday.use FaradayMiddleware::ParseJson
    faraday.adapter Faraday.default_adapter
  end
end

#delete(url, params = {}) ⇒ Object



25
26
27
# File 'lib/wazuh/connection.rb', line 25

def delete(url, params = {})
  connection.delete(url, params)
end

#get(url, params = {}) ⇒ Object



7
8
9
# File 'lib/wazuh/connection.rb', line 7

def get(url, params = {})
  connection.get(url, params)
end

#post(url, params = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/wazuh/connection.rb', line 11

def post(url, params = {})
  connection.post(url) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end
end

#put(url, params = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/wazuh/connection.rb', line 18

def put(url, params = {})
  connection.put(url) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end
end

#request(method, url, params = {}) ⇒ Object



29
30
31
# File 'lib/wazuh/connection.rb', line 29

def request(method, url, params = {})
  connection.send(method, url, params)
end