Sha256: 5082dbf849b762266c40b87ec29501904ad493ef83eda387a0a0c632cf4cc0e5

Contents?: true

Size: 903 Bytes

Versions: 15

Compression:

Stored size: 903 Bytes

Contents

require 'openssl'

module LogStashLogger
  module Device
    class TCP < Socket
      attr_reader :ssl_certificate

      def initialize(opts)
        super

        @ssl_certificate = opts[:ssl_certificate]
        @use_ssl = !!(@ssl_certificate || opts[:use_ssl] || opts[:ssl_enable])
      end

      def use_ssl?
        @use_ssl || !@ssl_certificate.nil?
      end

      protected

      def connect
        if use_ssl?
          ssl_connect
        else
          non_ssl_connect
        end

        @io
      end

      def non_ssl_connect
        @io = TCPSocket.new(@host, @port).tap do |socket|
          socket.sync = sync unless sync.nil?
        end
      end

      def ssl_connect
        non_ssl_connect
        #openssl_cert = OpenSSL::X509::Certificate.new(::File.read(@ssl_certificate))
        @io = OpenSSL::SSL::SSLSocket.new(@io)
        @io.connect
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
logstash-logger-0.14.1 lib/logstash-logger/device/tcp.rb
logstash-logger-0.14.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.13.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.12.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.11.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.10.3 lib/logstash-logger/device/tcp.rb
logstash-logger-0.10.2 lib/logstash-logger/device/tcp.rb
logstash-logger-0.10.1 lib/logstash-logger/device/tcp.rb
logstash-logger-0.10.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.9.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.8.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.7.0 lib/logstash-logger/device/tcp.rb
logstash-logger-0.6.2 lib/logstash-logger/device/tcp.rb
logstash-logger-0.6.1 lib/logstash-logger/device/tcp.rb
logstash-logger-0.6.0 lib/logstash-logger/device/tcp.rb