Class: Fluent::Plugin::SslCheck::FileChecker

Inherits:
Object
  • Object
show all
Includes:
SslCommon
Defined in:
lib/fluent/plugin/ssl_check/file_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SslCommon

#ssl_store

Constructor Details

#initialize(filepath, ca_path: nil, ca_file: nil) ⇒ FileChecker

Returns a new instance of FileChecker.



16
17
18
19
20
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 16

def initialize(filepath, ca_path: nil, ca_file: nil)
  @filepath = filepath
  @ca_path = ca_path
  @ca_file = ca_file
end

Instance Attribute Details

#ca_fileObject (readonly)

Returns the value of attribute ca_file.



12
13
14
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 12

def ca_file
  @ca_file
end

#ca_pathObject (readonly)

Returns the value of attribute ca_path.



12
13
14
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 12

def ca_path
  @ca_path
end

#filepathObject (readonly)

Returns the value of attribute filepath.



12
13
14
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 12

def filepath
  @filepath
end

Instance Method Details

#certificateObject



22
23
24
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 22

def certificate
  @certificate ||= OpenSSL::X509::Certificate.new(File.read(filepath_absolute))
end

#filepath_absoluteObject



26
27
28
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 26

def filepath_absolute
  File.expand_path(filepath)
end

#hostnameObject



45
46
47
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 45

def hostname
  Socket.gethostname
end

#ssl_infoObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/ssl_check/file_checker.rb', line 30

def ssl_info
  info = Fluent::Plugin::SslCheck::SslInfo.new(host: hostname, path: filepath_absolute)
  begin
    ca_store = ssl_store(ca_path: ca_path, ca_file: ca_file)
    ca_store.verify(certificate)

    info.cert = certificate
    info.cert_chain = ca_store.chain
    info.error = ca_store.error_string if ca_store.error != 0
  rescue StandardError => e
    info.error = e
  end
  info
end