Class: Acmesmith::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/acmesmith/config.rb
Defined Under Namespace
Classes: ChainPreference, ChallengeResponderRule, ProfileRule
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config) ⇒ Config
Returns a new instance of Config.
19
20
21
22
|
# File 'lib/acmesmith/config.rb', line 19
def initialize(config)
@config = config
validate
end
|
Class Method Details
.load_yaml(path) ⇒ Object
15
16
17
|
# File 'lib/acmesmith/config.rb', line 15
def self.load_yaml(path)
new YAML.load_file(path)
end
|
Instance Method Details
#[](key) ⇒ Object
46
47
48
|
# File 'lib/acmesmith/config.rb', line 46
def [](key)
@config[key]
end
|
#account_key_passphrase ⇒ Object
70
71
72
|
# File 'lib/acmesmith/config.rb', line 70
def account_key_passphrase
@config['account_key_passphrase']
end
|
#auto_authorize_on_request ⇒ Object
78
79
80
|
# File 'lib/acmesmith/config.rb', line 78
def auto_authorize_on_request
@config.fetch('auto_authorize_on_request', true)
end
|
#bad_nonce_retry ⇒ Object
66
67
68
|
# File 'lib/acmesmith/config.rb', line 66
def bad_nonce_retry
@config['bad_nonce_retry'] || 0
end
|
#certificate_key_passphrase ⇒ Object
74
75
76
|
# File 'lib/acmesmith/config.rb', line 74
def certificate_key_passphrase
@config['certificate_key_passphrase']
end
|
#chain_preferences ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/acmesmith/config.rb', line 119
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/acmesmith/config.rb', line 102
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
62
63
64
|
# File 'lib/acmesmith/config.rb', line 62
def connection_options
@config['connection_options'] || {}
end
|
#directory ⇒ Object
58
59
60
|
# File 'lib/acmesmith/config.rb', line 58
def directory
@config.fetch('directory')
end
|
#fetch(*args) ⇒ Object
50
51
52
|
# File 'lib/acmesmith/config.rb', line 50
def fetch(*args)
@config.fetch(*args)
end
|
#merge!(pair) ⇒ Object
54
55
56
|
# File 'lib/acmesmith/config.rb', line 54
def merge!(pair)
@config.merge!(pair)
end
|
#post_issuing_hooks(common_name) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/acmesmith/config.rb', line 89
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
|
#profile_rules ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/acmesmith/config.rb', line 133
def profile_rules
@profile_rules ||= begin
specs = @config['profiles'] || []
specs.map do |spec|
filter = spec.fetch('filter', {}).map { |k,v| [k.to_sym, v] }.to_h
ProfileRule.new(name: spec['name'], filter: SubjectNameFilter.new(**filter))
end
end
end
|
#storage ⇒ Object
82
83
84
85
86
87
|
# File 'lib/acmesmith/config.rb', line 82
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/acmesmith/config.rb', line 24
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
if @config.key?('profiles') && !@config.fetch('profiles').kind_of?(Array)
raise ArgumentError, "config['profiles'] must be an Array"
end
end
|