Class: SumologicCloudSyslog::SSLTransport
- Inherits:
-
Object
- Object
- SumologicCloudSyslog::SSLTransport
- Defined in:
- lib/sumologic_cloud_syslog/ssl_transport.rb
Overview
Supports SSL connection to remote host
Instance Attribute Summary collapse
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#ssl_version ⇒ Object
readonly
Returns the value of attribute ssl_version.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(host, port, cert: nil, key: nil, ssl_version: :TLSv1_2) ⇒ SSLTransport
constructor
A new instance of SSLTransport.
-
#method_missing(method_sym, *arguments, &block) ⇒ Object
Forward any methods directly to SSLSocket.
Constructor Details
#initialize(host, port, cert: nil, key: nil, ssl_version: :TLSv1_2) ⇒ SSLTransport
Returns a new instance of SSLTransport.
25 26 27 28 29 30 31 32 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 25 def initialize(host, port, cert: nil, key: nil, ssl_version: :TLSv1_2) @host = host @port = port @cert = cert @key = key @ssl_version = ssl_version connect end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
Forward any methods directly to SSLSocket
49 50 51 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 49 def method_missing(method_sym, *arguments, &block) @socket.send(method_sym, *arguments, &block) end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
23 24 25 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23 def cert @cert end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
23 24 25 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
23 24 25 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23 def key @key end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
23 24 25 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
21 22 23 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 21 def socket @socket end |
#ssl_version ⇒ Object (readonly)
Returns the value of attribute ssl_version.
23 24 25 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23 def ssl_version @ssl_version end |
Instance Method Details
#connect ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 34 def connect tcp = TCPSocket.new(host, port) ctx = OpenSSL::SSL::SSLContext.new ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER) ctx.ssl_version = ssl_version ctx.cert = OpenSSL::X509::Certificate.new(File.open(cert)) if cert ctx.key = OpenSSL::PKey::RSA.new(File.open(key)) if key @socket = OpenSSL::SSL::SSLSocket.new(tcp, ctx) @socket.connect end |