Class: Proxy::ContainerGateway::ForemanApi

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_container_gateway/foreman_api.rb

Instance Method Summary collapse

Instance Method Details

#fetch_host_repositories(uuid, params) ⇒ Object



35
36
37
# File 'lib/smart_proxy_container_gateway/foreman_api.rb', line 35

def fetch_host_repositories(uuid, params)
  registry_request(nil, params, '_catalog', uuid: uuid, cert: true)
end

#fetch_token(auth_header, params) ⇒ Object



27
28
29
# File 'lib/smart_proxy_container_gateway/foreman_api.rb', line 27

def fetch_token(auth_header, params)
  registry_request(auth_header, params, 'token')
end

#fetch_user_repositories(auth_header, params) ⇒ Object



31
32
33
# File 'lib/smart_proxy_container_gateway/foreman_api.rb', line 31

def fetch_user_repositories(auth_header, params)
  registry_request(auth_header, params, '_catalog')
end

#process_params(params_in) ⇒ Object



22
23
24
25
# File 'lib/smart_proxy_container_gateway/foreman_api.rb', line 22

def process_params(params_in)
  params = params_in.slice('scope', 'account').compact
  URI.encode_www_form(params)
end

#registry_request(auth_header, params, suffix, uuid: '', cert: false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smart_proxy_container_gateway/foreman_api.rb', line 7

def registry_request(auth_header, params, suffix, uuid: '', cert: false)
  uri = URI.join(Proxy::SETTINGS.foreman_url, Proxy::ContainerGateway::Plugin.settings.katello_registry_path, suffix)
  uri.query = process_params(params)

  req = Net::HTTP::Get.new(uri)
  req.add_field('Authorization', auth_header) unless cert
  req.add_field('Accept', 'application/json')
  req.add_field('HostUUID', uuid) if cert
  req.content_type = 'application/json'
  http = Net::HTTP.new(uri.hostname, uri.port)
  http.use_ssl = true

  http.request(req)
end