Class: Acmesmith::Config

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

Defined Under Namespace

Classes: ChallengeResponderRule

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



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

def initialize(config)
  @config = config
  validate
end

Class Method Details

.load_yaml(path) ⇒ Object



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

def self.load_yaml(path)
  new YAML.load_file(path)
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @config[key]
end

#account_key_passphraseObject



58
59
60
# File 'lib/acmesmith/config.rb', line 58

def 
  @config['account_key_passphrase']
end

#auto_authorize_on_requestObject



66
67
68
# File 'lib/acmesmith/config.rb', line 66

def auto_authorize_on_request
  @config.fetch('auto_authorize_on_request', true)
end

#bad_nonce_retryObject



54
55
56
# File 'lib/acmesmith/config.rb', line 54

def bad_nonce_retry
  @config['bad_nonce_retry'] || 0
end

#certificate_key_passphraseObject



62
63
64
# File 'lib/acmesmith/config.rb', line 62

def certificate_key_passphrase
  @config['certificate_key_passphrase']
end

#challenge_respondersObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/acmesmith/config.rb', line 90

def challenge_responders
  @challenge_responders ||= begin
    specs = @config['challenge_responders'].kind_of?(Hash) ? @config['challenge_responders'].map { |k,v| [k => v] } : @config['challenge_responders']
    specs.flat_map do |specs_sub|
      specs_sub = specs_sub.dup
      filter = (specs_sub.delete('filter') || {}).map { |k,v| [k.to_sym, v] }.to_h
      specs_sub.map do |k,v|
        responder = ChallengeResponders.find(k).new(**v.map{ |k_,v_| [k_.to_sym, v_]}.to_h)
        ChallengeResponderRule.new(
          challenge_responder: responder,
          filter: ChallengeResponderFilter.new(responder, **filter),
        )
      end
    end
  end
end

#connection_optionsObject



50
51
52
# File 'lib/acmesmith/config.rb', line 50

def connection_options
  @config['connection_options'] || {}
end

#directoryObject



46
47
48
# File 'lib/acmesmith/config.rb', line 46

def directory
  @config.fetch('directory')
end

#fetch(*args) ⇒ Object



38
39
40
# File 'lib/acmesmith/config.rb', line 38

def fetch(*args)
  @config.fetch(*args)
end

#merge!(pair) ⇒ Object



42
43
44
# File 'lib/acmesmith/config.rb', line 42

def merge!(pair)
  @config.merge!(pair)
end

#post_issuing_hooks(common_name) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/acmesmith/config.rb', line 77

def post_issuing_hooks(common_name)
  if @config.key?('post_issuing_hooks') && @config['post_issuing_hooks'].key?(common_name)
    specs = @config['post_issuing_hooks'][common_name]
    specs.flat_map do |specs_sub|
      specs_sub.map do |k, v|
        PostIssuingHooks.find(k).new(**v.map{ |k_,v_| [k_.to_sym, v_]}.to_h)
      end
    end
  else
    []
  end
end

#storageObject



70
71
72
73
74
75
# File 'lib/acmesmith/config.rb', line 70

def storage
  @storage ||= begin
    c = @config['storage'].dup
    Storages.find(c.delete('type')).new(**c.map{ |k,v| [k.to_sym, v]}.to_h)
  end
end

#validateObject



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

def validate
  unless @config['storage']
    raise ArgumentError, "config['storage'] must be provided"
  end

  if @config['endpoint'] and !@config['directory']
    raise ArgumentError, "config['directory'] must be provided, e.g. https://acme-v02.api.letsencrypt.org/directory or https://acme-staging-v02.api.letsencrypt.org/directory\n\nNOTE: We have dropped ACME v1 support since acmesmith v2.0.0. Specify v2 directory API URL using config['directory']."
  end

  unless @config['directory']
    raise ArgumentError, "config['directory'] must be provided, e.g. https://acme-v02.api.letsencrypt.org/directory or https://acme-staging-v02.api.letsencrypt.org/directory"
  end
end