Class: WebHDFS::SSL

Inherits:
Object
  • Object
show all
Defined in:
lib/webhdfs/ssl.rb

Overview

SSL class for http requests

Constant Summary collapse

SSL_VERIFY_MODES =
[:none, :peer].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SSL

Constructor



11
12
13
14
15
16
17
# File 'lib/webhdfs/ssl.rb', line 11

def initialize(options = {})
  @ca_file = options[:ca_file]
  self.verify_mode = options[:verify_mode]
  @cert = options[:cert]
  @key = options[:key]
  @version = options[:version]
end

Instance Attribute Details

#ca_fileObject (readonly)

Returns the value of attribute ca_file.



6
7
8
# File 'lib/webhdfs/ssl.rb', line 6

def ca_file
  @ca_file
end

#certObject (readonly)

Returns the value of attribute cert.



7
8
9
# File 'lib/webhdfs/ssl.rb', line 7

def cert
  @cert
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/webhdfs/ssl.rb', line 7

def key
  @key
end

#verify_modeObject

Returns the value of attribute verify_mode.



6
7
8
# File 'lib/webhdfs/ssl.rb', line 6

def verify_mode
  @verify_mode
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/webhdfs/ssl.rb', line 7

def version
  @version
end

Instance Method Details

#apply_to(connection) ⇒ Object

Apply ssl to a http connection



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webhdfs/ssl.rb', line 28

def apply_to(connection)
  connection.use_ssl = true
  connection.ca_file = @ca_file if @ca_file
  if @verify_mode
    connection.verify_mode = case @verify_mode
                             when :none then OpenSSL::SSL::VERIFY_NONE
                             when :peer then OpenSSL::SSL::VERIFY_PEER
                             end
  end
  connection.cert = @cert if @cert
  connection.key = @key if @key
  connection.ssl_version = @version if @version

  connection
end