Sha256: 477d8da8809eb6955cdad3d482e423a3c34b2af82f3471212560f7ade5c4c4ee

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

module Wazuh
  module Sawyer
    module Connection
      private
      def connection
        options = {
          headers: {
            'Accept' => 'application/json; charset=utf-8',
            'Content-Type' => 'application/json'
          },
          ssl: {}
        }

        options[:headers]['User-Agent'] = user_agent if user_agent
        options[:ssl].merge!({ client_cert: client_cert, client_key: client_key }) if client_cert || client_key
        options[:ssl][:ca_file] = ca_file if ca_file

        options[:ssl].merge!({ verify: false }) unless verify_ssl

        opts = {
          links_parser: ::Sawyer::LinkParsers::Simple.new
        }

        case api_version
        when 3
          if basic_user || basic_password
            options[:headers].merge!({'Authorization' => "Basic " + Base64.strict_encode64(basic_user + ':' + basic_password).strip})
          end
        when 4
          raise "user and password is required on v4 api" if !basic_user || !basic_password
          opts[:faraday] = ::Faraday.new(options) do |conn|
            conn.request :authorization, 'Bearer', Token.jwt(endpoint, options, basic_user, basic_password)
          end
        end

        opts[:faraday].proxy = nil if ignore_env_proxy

        conn = ::Sawyer::Agent.new(endpoint, opts)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wazuh-ruby-client-0.3.7 lib/wazuh/sawyer/connection.rb
wazuh-ruby-client-0.3.6 lib/wazuh/sawyer/connection.rb
wazuh-ruby-client-0.3.5 lib/wazuh/sawyer/connection.rb