Class: Acmesmith::SaveCertificateService

Inherits:
Object
  • Object
show all
Defined in:
lib/acmesmith/save_certificate_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert, key_mode: '0600', certificate_mode: '0644', version_file: nil, key_file: nil, fullchain_file: nil, chain_file: nil, certificate_file: nil, atomic: true, verbose: false) ⇒ SaveCertificateService

Returns a new instance of SaveCertificateService.

[View source]

3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/acmesmith/save_certificate_service.rb', line 3

def initialize(cert, key_mode: '0600', certificate_mode: '0644', version_file: nil, key_file: nil, fullchain_file: nil, chain_file: nil, certificate_file: nil, atomic: true, verbose: false)
  @cert = cert
  @key_mode = key_mode
  @certificate_mode = certificate_mode
  @version_file = version_file
  @key_file = key_file
  @fullchain_file = fullchain_file
  @chain_file = chain_file
  @certificate_file = certificate_file
  @atomic = atomic
  @verbose = verbose
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.


16
17
18
# File 'lib/acmesmith/save_certificate_service.rb', line 16

def cert
  @cert
end

#certificate_fileObject (readonly)

Returns the value of attribute certificate_file.


18
19
20
# File 'lib/acmesmith/save_certificate_service.rb', line 18

def certificate_file
  @certificate_file
end

#certificate_modeObject (readonly)

Returns the value of attribute certificate_mode.


17
18
19
# File 'lib/acmesmith/save_certificate_service.rb', line 17

def certificate_mode
  @certificate_mode
end

#chain_fileObject (readonly)

Returns the value of attribute chain_file.


18
19
20
# File 'lib/acmesmith/save_certificate_service.rb', line 18

def chain_file
  @chain_file
end

#fullchain_fileObject (readonly)

Returns the value of attribute fullchain_file.


18
19
20
# File 'lib/acmesmith/save_certificate_service.rb', line 18

def fullchain_file
  @fullchain_file
end

#key_fileObject (readonly)

Returns the value of attribute key_file.


18
19
20
# File 'lib/acmesmith/save_certificate_service.rb', line 18

def key_file
  @key_file
end

#key_modeObject (readonly)

Returns the value of attribute key_mode.


17
18
19
# File 'lib/acmesmith/save_certificate_service.rb', line 17

def key_mode
  @key_mode
end

#version_fileObject (readonly)

Returns the value of attribute version_file.


18
19
20
# File 'lib/acmesmith/save_certificate_service.rb', line 18

def version_file
  @version_file
end

Instance Method Details

#atomic?Boolean

Returns:

  • (Boolean)
[View source]

19
# File 'lib/acmesmith/save_certificate_service.rb', line 19

def atomic?; !!@atomic; end

#local_versionObject

[View source]

35
36
37
38
39
40
41
42
43
# File 'lib/acmesmith/save_certificate_service.rb', line 35

def local_version
  @local_version ||= begin
    if version_file && File.exist?(version_file)
      File.read(version_file).chomp
    else
      nil
    end
  end
end

#perform!Object

[View source]

21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/acmesmith/save_certificate_service.rb', line 21

def perform!
  if local_version == cert.version
    return
  end

  log "Saving certificate CN=#{cert.common_name} (ver: #{cert.version})"

  write_file(key_file, key_mode, cert.private_key)
  write_file(certificate_file, certificate_mode, cert.certificate.to_pem)
  write_file(chain_file, certificate_mode, cert.chain)
  write_file(fullchain_file, certificate_mode, cert.fullchain)
  write_file(version_file, certificate_mode, cert.version)
end