Module: Wazuh::Connection
- Included in:
- Client
- Defined in:
- lib/wazuh/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(url, params = {}) ⇒ Object
- #get(url, params = {}) ⇒ Object
- #post(url, params = {}) ⇒ Object
- #put(url, params = {}) ⇒ Object
- #request(method, url, params = {}) ⇒ Object
Instance Method Details
#connection ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wazuh/connection.rb', line 33 def connection = { url: config.api_endpoint, headers: config.http_request_headers, request: config.request, proxy: config.proxy } [: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() 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 |