Class: PulpProxy::PulpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_pulp_plugin/pulp_client.rb

Class Method Summary collapse

Class Method Details

.get(path) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/smart_proxy_pulp_plugin/pulp_client.rb', line 8

def self.get(path)
  uri = URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s)
  req = Net::HTTP::Get.new(URI.join(uri.to_s.chomp('/') + '/', path))
  req.add_field('Accept', 'application/json')
  req.content_type = 'application/json'
  response = self.http.request(req)
end

.httpObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/smart_proxy_pulp_plugin/pulp_client.rb', line 16

def self.http
  uri = URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  if http.use_ssl?
    if Proxy::SETTINGS.ssl_ca_file && !Proxy::SETTINGS.ssl_ca_file.to_s.empty?
      http.ca_file = Proxy::SETTINGS.ssl_ca_file
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

    if Proxy::SETTINGS.ssl_certificate && !Proxy::SETTINGS.ssl_certificate.to_s.empty? && Proxy::SETTINGS.ssl_private_key && !Proxy::SETTINGS.ssl_private_key.to_s.empty?
      http.cert = OpenSSL::X509::Certificate.new(File.read(Proxy::SETTINGS.ssl_certificate))
      http.key  = OpenSSL::PKey::RSA.new(File.read(Proxy::SETTINGS.ssl_private_key), nil)
    end
  end
  http
end