Module: SccManager
- Defined in:
- app/lib/scc_manager.rb
Class Method Summary collapse
-
.get_scc_data(base_url, rest_url, login, password) ⇒ Object
adapted from https://github.com/SUSE/connect.
-
.sanitize_products(products, result = {}) ⇒ Object
Cope for the very weird structure of SCC output.
Class Method Details
.get_scc_data(base_url, rest_url, login, password) ⇒ Object
adapted from https://github.com/SUSE/connect
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/lib/scc_manager.rb', line 3 def self.get_scc_data(base_url, rest_url, login, password) RestClient.proxy = ::HttpProxy.default_global_content_proxy.full_url if ::HttpProxy.default_global_content_proxy url = base_url + rest_url credentials = Base64.encode64("#{login}:#{password}").chomp auth_header = { Authorization: "Basic #{credentials}", Accept: 'application/vnd.scc.suse.com.v4+json' } results = [] loop do response = RestClient.get url, auth_header raise 'Connection to SUSE costomer center failed.' unless response.code == 200 links = (response.headers[:link] || '').split(', ').map do |link| href, rel = /<(.*?)>; rel="(\w+)"/.match(link).captures [rel.to_sym, href] end links = Hash[*links.flatten] results += JSON.parse response url = links[:next] break unless url end results ensure RestClient.proxy = '' end |
.sanitize_products(products, result = {}) ⇒ Object
Cope for the very weird structure of SCC output
30 31 32 33 34 35 36 37 38 |
# File 'app/lib/scc_manager.rb', line 30 def self.sanitize_products(products, result = {}) products.reduce(result) do |res, product| sanitize_products(product['extensions'].tap do |extensions| product['extensions'] = extensions.map { |extension| { 'id' => extension['id'] } } res[product['id']] = product.merge(result.fetch(product['id'], {})) res[product['id']]['extensions'] |= product['extensions'] end, res) end end |