Skip to content

Commit f2c9a90

Browse files
authored
Merge pull request #9073 from mhashizume/maint/7.x/keyword-struct
(maint) Simplifies SSLContext intialization
2 parents 5ab8d48 + aa41b45 commit f2c9a90

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

lib/puppet/ssl/ssl_context.rb

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative '../../puppet/ssl'
22

33
module Puppet::SSL
4+
# The `keyword_init: true` option is no longer needed in Ruby >= 3.2
45
SSLContext = Struct.new(
56
:store,
67
:cacerts,
@@ -9,22 +10,16 @@ module Puppet::SSL
910
:client_cert,
1011
:client_chain,
1112
:revocation,
12-
:verify_peer
13+
:verify_peer,
14+
keyword_init: true
1315
) do
14-
DEFAULTS = {
15-
cacerts: [],
16-
crls: [],
17-
client_chain: [],
18-
revocation: true,
19-
verify_peer: true
20-
}.freeze
21-
22-
# This is an idiom to initialize a Struct from keyword
23-
# arguments. Ruby 2.5 introduced `keyword_init: true` for
24-
# that purpose, but we need to support older versions.
25-
def initialize(kwargs = {})
26-
super({})
27-
DEFAULTS.merge(**kwargs).each { |k,v| self[k] = v }
16+
def initialize(*)
17+
super
18+
self[:cacerts] ||= []
19+
self[:crls] ||= []
20+
self[:client_chain] ||= []
21+
self[:revocation] = true if self[:revocation].nil?
22+
self[:verify_peer] = true if self[:verify_peer].nil?
2823
end
2924
end
3025
end

0 commit comments

Comments
 (0)