Class: PoiseTlsRemoteFile::Resources::PoiseTlsRemoteFile::Fetcher

Inherits:
Chef::Provider::RemoteFile::HTTP
  • Object
show all
Defined in:
lib/poise_tls_remote_file/resources/poise_tls_remote_file.rb

Overview

Fetcher class for tls_remote_file.

See Also:

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#fetchObject

Since:

  • 1.0.0



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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