Class: LetsencryptStandalone::Config

Inherits:
Base
  • Object
show all
Defined in:
lib/letsencrypt_standalone/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#endpoint_url, #logger, logger, #path

Constructor Details

#initialize(config_file: nil) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/letsencrypt_standalone/config.rb', line 6

def initialize(config_file: nil)
  @location ||= config_file
  @config = JSON.parse(File.read(@location), :symbolize_names => true)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/letsencrypt_standalone/config.rb', line 5

def config
  @config
end

#locationObject

Returns the value of attribute location.



5
6
7
# File 'lib/letsencrypt_standalone/config.rb', line 5

def location
  @location
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/letsencrypt_standalone/config.rb', line 5

def port
  @port
end

Instance Method Details

#add(domains:) ⇒ Object



33
34
35
36
37
# File 'lib/letsencrypt_standalone/config.rb', line 33

def add(domains:)
  domains.each do |domain|
    @config[:domains] << {host: domain}
  end
end

#output_dirObject



11
12
13
# File 'lib/letsencrypt_standalone/config.rb', line 11

def output_dir
  config.output_dir || super
end

#push_certs_locations(files:, domain:) ⇒ Object



39
40
41
42
43
# File 'lib/letsencrypt_standalone/config.rb', line 39

def push_certs_locations(files:, domain:)
  config[:domains].map! do |d|
    d[:host] == domain.host ? d.merge(certificates: files) : d
  end
end

#push_private_key_name(domain:) ⇒ Object



45
46
47
48
49
# File 'lib/letsencrypt_standalone/config.rb', line 45

def push_private_key_name(domain:)
  config[:domains].map! do |d|
    d[:host] == domain.host ? d.merge(private_key: domain.private_key_name) : d
  end
end

#ssl_subdirObject



21
22
23
# File 'lib/letsencrypt_standalone/config.rb', line 21

def ssl_subdir
  config[:ssl_subdir] || 'ssl_certs'
end

#triesObject



29
30
31
# File 'lib/letsencrypt_standalone/config.rb', line 29

def tries
  config.fetch(:tries, 5)
end

#writeObject



51
52
53
# File 'lib/letsencrypt_standalone/config.rb', line 51

def write
  File.new(location, 'w').write(JSON.pretty_generate(config))
end

#www_rootObject



25
26
27
# File 'lib/letsencrypt_standalone/config.rb', line 25

def www_root
  config[:www_root] || 'public'
end