diff --git a/lib/puppet/ssl/ssl_context.rb b/lib/puppet/ssl/ssl_context.rb index 3a63e3894f0..4b34a820a04 100644 --- a/lib/puppet/ssl/ssl_context.rb +++ b/lib/puppet/ssl/ssl_context.rb @@ -1,6 +1,9 @@ require_relative '../../puppet/ssl' module Puppet::SSL + # Struct in Ruby >= 2.5 uses the `keyword_init: true` option to allow for + # keyword arguments. Ruby >= 3.2 allows Struct.new to use keyword arguments + # without `keyword_init: true` SSLContext = Struct.new( :store, :cacerts, @@ -9,22 +12,16 @@ module Puppet::SSL :client_cert, :client_chain, :revocation, - :verify_peer + :verify_peer, + keyword_init: true ) do - DEFAULTS = { - cacerts: [], - crls: [], - client_chain: [], - revocation: true, - verify_peer: true - }.freeze - - # This is an idiom to initialize a Struct from keyword - # arguments. Ruby 2.5 introduced `keyword_init: true` for - # that purpose, but we need to support older versions. - def initialize(kwargs = {}) - super({}) - DEFAULTS.merge(**kwargs).each { |k,v| self[k] = v } + def initialize(*) + super + self[:cacerts] ||= [] + self[:crls] ||= [] + self[:client_chain] ||= [] + true unless self[:revocation] + true unless self[:verify_peer] end end end