class PoiseTlsRemoteFile::Resources::PoiseTlsRemoteFile::Fetcher

Fetcher class for `tls_remote_file`.

@see Resource

Public Instance Methods

fetch() click to toggle source
Calls superclass method
# File lib/poise_tls_remote_file/resources/poise_tls_remote_file.rb, line 120
def fetch
  client_cert = new_resource.client_cert_obj
  client_key = new_resource.client_key_obj
  ca = new_resource.ca_objs
  begin
    Chef::HTTP::Simple.singleton_class.send(:define_method, :new) do |*args|
      super(*args).tap do |http_simple|
        http_simple.singleton_class.prepend(Module.new {
          define_method(:http_client) do |*inner_args|
            super(*inner_args).tap do |client|
              client.http_client.cert = client_cert if client_cert
              client.http_client.key = client_key if client_key
              # cert_store is nil if this is not an HTTPS URL.
              ca.each {|cert| client.http_client.cert_store.add_cert(cert) if cert } if client.http_client.cert_store
            end
          end
        })
      end
    end
    super
  ensure
    Chef::HTTP::Simple.singleton_class.send(:remove_method, :new)
  end
end