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



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

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

.get(path) ⇒ Object



10
11
12
13
14
15
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 10

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')
  http.request(req)
end

.httpObject



29
30
31
32
33
34
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 29

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



25
26
27
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 25

def self.logger
  Proxy::LoggerFactory.logger
end

.pulp_urlObject



36
37
38
# File 'lib/smart_proxy_pulp_plugin/pulpcore_client.rb', line 36

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