Class: Hiera::Httpcache
- Defined in:
- puppet/modules/wmflib/lib/hiera/httpcache.rb
Instance Method Summary collapse
-
#initialize ⇒ Httpcache
constructor
A new instance of Httpcache.
- #read(path, _expected_type = Hash, _default = nil) ⇒ Object
- #read_file(path) ⇒ Object
Constructor Details
#initialize ⇒ Httpcache
Returns a new instance of Httpcache.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'puppet/modules/wmflib/lib/hiera/httpcache.rb', line 3 def initialize super require 'httpclient' require 'yaml' require 'json' config = Config[:httpyaml] @url_prefix = config[:url_prefix] @http = HTTPClient.new(:agent_name => 'HieraHttpCache/0.1') # Use the operating system's certificate store, not ruby-httpclient's cacert.p7s which doesn't # even have the root used to sign Let's Encrypt CAs (DST Root CA X3) @http.ssl_config.clear_cert_store @http.ssl_config.set_default_paths @stat_ttl = config[:cache_ttl] || 60 if defined? @http.ssl_config.ssl_version @http.ssl_config.ssl_version = 'TLSv1' else # Note: this seem to work in later versions of the library, # but has no effect. How cute, I <3 ruby. @http.ssl_config. = OpenSSL::SSL::OP_NO_SSLv3 end end |
Instance Method Details
#read(path, _expected_type = Hash, _default = nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'puppet/modules/wmflib/lib/hiera/httpcache.rb', line 27 def read(path, _expected_type = Hash, _default = nil) read_file(path) rescue => detail # When failing to read data, we raise an exception, see https://phabricator.wikimedia.org/T78408 error = "Reading data from #{path} failed: #{detail.class}: #{detail}" raise error end |
#read_file(path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'puppet/modules/wmflib/lib/hiera/httpcache.rb', line 35 def read_file(path) if stale?(path) data = get_from_http(path) @cache[path][:data] = data unless @cache[path][:data].is_a?(Object) raise TypeError, "Data retrieved from #{path} is #{data.class} not Object" end end @cache[path][:data] end |