Class: LetsencryptStandalone::Config

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

Constant Summary collapse

@@config =
nil

Instance Attribute Summary collapse

Class Method 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.



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

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.



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

def config
  @config
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.configObject



61
62
63
# File 'lib/letsencrypt_standalone/config.rb', line 61

def config
  @@config
end

.ssl_subdirObject



65
66
67
# File 'lib/letsencrypt_standalone/config.rb', line 65

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

Instance Method Details

#add(domains:) ⇒ Object



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

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

#output_dirObject



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

def output_dir
  config.output_dir || super
end

#push_certs_locations(files:, domain:) ⇒ Object



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

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



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

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



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

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

#triesObject



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

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

#writeObject



56
57
58
# File 'lib/letsencrypt_standalone/config.rb', line 56

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

#www_rootObject



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

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