Class: Fluent::Plugin::SslCheck::SslInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/ssl_check/ssl_info.rb

Overview

ssl info

to encapsulate extracted ssl information

Constant Summary collapse

OK =
1
KO =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: nil, port: nil, path: nil, cert: nil, cert_chain: nil, ssl_version: nil, error: nil, time: nil) ⇒ SslInfo

rubocop:disable Metrics/ParameterLists



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 17

def initialize(host: nil, port: nil, path: nil, cert: nil, cert_chain: nil, ssl_version: nil,
               error: nil, time: nil)
  @host = host
  @port = port
  @path = path
  @cert = cert
  @cert_chain = cert_chain
  @ssl_version = ssl_version
  @error = error
  @time = time
end

Instance Attribute Details

#certObject

Returns the value of attribute cert.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def cert
  @cert
end

#cert_chainObject

Returns the value of attribute cert_chain.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def cert_chain
  @cert_chain
end

#errorObject

Returns the value of attribute error.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def error
  @error
end

#hostObject

Returns the value of attribute host.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def host
  @host
end

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def path
  @path
end

#portObject

Returns the value of attribute port.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def port
  @port
end

#ssl_versionObject

Returns the value of attribute ssl_version.



14
15
16
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 14

def ssl_version
  @ssl_version
end

Instance Method Details

#error_classObject



65
66
67
68
69
70
71
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 65

def error_class
  return unless error

  return error if error.is_a?(String)

  error.class.to_s
end

#expire_in_daysObject



34
35
36
37
38
39
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 34

def expire_in_days
  return unless cert&.not_after

  expire_in = cert.not_after
  ((expire_in - time) / 3600 / 24).to_i
end

#not_afterObject



41
42
43
44
45
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 41

def not_after
  return unless cert

  cert.not_after.iso8601(3)
end

#serialObject



47
48
49
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 47

def serial
  cert&.serial&.to_s(16)&.downcase
end

#statusObject



51
52
53
54
55
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 51

def status
  return KO if error

  OK
end

#subject_sObject

rubocop:enable Metrics/ParameterLists



30
31
32
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 30

def subject_s
  cert.subject.to_utf8 if cert&.subject
end

#timeObject



57
58
59
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 57

def time
  @time ||= Time.now.utc
end

#time_utcObject



61
62
63
# File 'lib/fluent/plugin/ssl_check/ssl_info.rb', line 61

def time_utc
  time.utc
end