Class: PulpProxy::PulpcoreClient

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

Class Method Summary collapse

Class Method Details

.capabilitiesObject



15
16
17
18
19
20
21
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 15

def self.capabilities
  body = JSON.parse(get("/pulp/api/v3/status/").body)
  body['versions'].map{|item| item['component'] }
rescue => e
  logger.error("Could not fetch capabilities: #{e.message}")
  []
end

.get(path) ⇒ Object



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

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

.httpObject



27
28
29
30
31
32
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 27

def self.http
  uri = URI.parse(pulp_url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'
  http
end

.loggerObject



23
24
25
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 23

def self.logger
  Proxy::LoggerFactory.logger
end

.pulp_urlObject



34
35
36
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 34

def self.pulp_url
  ::PulpProxy::PulpcorePlugin.settings.pulp_url.to_s
end