Class: Acmesmith::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/acmesmith/config.rb
Defined Under Namespace
Classes: ChainPreference, ChallengeResponderRule
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config) ⇒ Config
Returns a new instance of Config.
17
18
19
20
|
# File 'lib/acmesmith/config.rb', line 17
def initialize(config)
@config = config
validate
end
|
Class Method Details
.load_yaml(path) ⇒ Object
13
14
15
|
# File 'lib/acmesmith/config.rb', line 13
def self.load_yaml(path)
new YAML.load_file(path)
end
|
Instance Method Details
#[](key) ⇒ Object
40
41
42
|
# File 'lib/acmesmith/config.rb', line 40
def [](key)
@config[key]
end
|
#account_key_passphrase ⇒ Object
64
65
66
|
# File 'lib/acmesmith/config.rb', line 64
def account_key_passphrase
@config['account_key_passphrase']
end
|
#auto_authorize_on_request ⇒ Object
72
73
74
|
# File 'lib/acmesmith/config.rb', line 72
def auto_authorize_on_request
@config.fetch('auto_authorize_on_request', true)
end
|
#bad_nonce_retry ⇒ Object
60
61
62
|
# File 'lib/acmesmith/config.rb', line 60
def bad_nonce_retry
@config['bad_nonce_retry'] || 0
end
|
#certificate_key_passphrase ⇒ Object
68
69
70
|
# File 'lib/acmesmith/config.rb', line 68
def certificate_key_passphrase
@config['certificate_key_passphrase']
end
|
#chain_preferences ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/acmesmith/config.rb', line 113
def chain_preferences
@preferred_chains ||= begin
specs = @config['chain_preferences'] || []
specs.flat_map do |spec|
filter = spec.fetch('filter', {}).map { |k,v| [k.to_sym, v] }.to_h
ChainPreference.new(
root_issuer_name: spec['root_issuer_name'],
root_issuer_key_id: spec['root_issuer_key_id'],
filter: DomainNameFilter.new(**filter),
)
end
end
end
|
#challenge_responders ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/acmesmith/config.rb', line 96
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_options ⇒ Object
56
57
58
|
# File 'lib/acmesmith/config.rb', line 56
def connection_options
@config['connection_options'] || {}
end
|
#directory ⇒ Object
52
53
54
|
# File 'lib/acmesmith/config.rb', line 52
def directory
@config.fetch('directory')
end
|
#fetch(*args) ⇒ Object
44
45
46
|
# File 'lib/acmesmith/config.rb', line 44
def fetch(*args)
@config.fetch(*args)
end
|
#merge!(pair) ⇒ Object
48
49
50
|
# File 'lib/acmesmith/config.rb', line 48
def merge!(pair)
@config.merge!(pair)
end
|
#post_issuing_hooks(common_name) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/acmesmith/config.rb', line 83
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
|
#storage ⇒ Object
76
77
78
79
80
81
|
# File 'lib/acmesmith/config.rb', line 76
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
|
#validate ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/acmesmith/config.rb', line 22
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
if @config.key?('chain_preferences') && !@config.fetch('chain_preferences').kind_of?(Array)
raise ArgumentError, "config['chain_preferences'] must be an Array"
end
end
|