Class: ContainerConfig::Coercer::SslCertificate

Inherits:
Base
  • Object
show all
Defined in:
lib/container_config/coercer/ssl_certificate.rb

Overview

SSL certificate type coercer

Instance Method Summary collapse

Instance Method Details

#coerce(value) ⇒ OpenSSL::X509::Certificate

Coerces the given value into an SSL certificate

Parameters:

  • value (Object)

    SSL certificate path

Returns:

  • (OpenSSL::X509::Certificate)

    coerced value



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/container_config/coercer/ssl_certificate.rb', line 28

def coerce(value)
  return if value.nil?

  return value if value.is_a?(OpenSSL::X509::Certificate)

  cert_path = value.to_s

  unless File.exist?(cert_path)
    ContainerConfig.logger.warn { "Could not find SSL certificate at #{cert_path}" }
    return nil
  end

  OpenSSL::X509::Certificate.new(File.read(cert_path))
rescue OpenSSL::X509::CertificateError => e
  ContainerConfig.logger.warn { "Could not parse SSL certificate #{cert_path} successfully: #{e}" }
  nil
end

#nameObject

See Also:



12
13
14
# File 'lib/container_config/coercer/ssl_certificate.rb', line 12

def name
  "SSL Certificate"
end

#typeObject

See Also:



17
18
19
# File 'lib/container_config/coercer/ssl_certificate.rb', line 17

def type
  :ssl_certificate
end