Sha256: 486d3445d8a6a3171ac4cc4e873855300c44bc76570ac10dff12e6ae30cd24ec

Contents?: true

Size: 1.74 KB

Versions: 9

Compression:

Stored size: 1.74 KB

Contents

module SccManager
  # adapted from https://github.com/SUSE/connect
  def self.get_scc_data(base_url, rest_url, login, password)
    if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
      proxy_config = SETTINGS[:katello][:cdn_proxy]
      uri = URI('')

      uri.scheme = URI.parse(proxy_config[:host]).scheme
      uri.host = URI.parse(proxy_config[:host]).host
      uri.port = proxy_config[:port].try(:to_s)
      uri.user = proxy_config[:user]
      uri.password = proxy_config[:password] if uri.user.present?

      RestClient.proxy = uri.to_s
    end

    url = base_url + rest_url
    auth_header = { Authorization: 'Basic ' + Base64.encode64("#{login}:#{password}").chomp,
                    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

  # Cope for the very weird structure of SCC output
  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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreman_scc_manager-1.8.10 app/lib/scc_manager.rb
foreman_scc_manager-1.8.9 app/lib/scc_manager.rb
foreman_scc_manager-1.8.8 app/lib/scc_manager.rb
foreman_scc_manager-1.8.7 app/lib/scc_manager.rb
foreman_scc_manager-1.8.6 app/lib/scc_manager.rb
foreman_scc_manager-1.8.5 app/lib/scc_manager.rb
foreman_scc_manager-1.8.4 app/lib/scc_manager.rb
foreman_scc_manager-1.7.1 app/lib/scc_manager.rb
foreman_scc_manager-1.8.3 app/lib/scc_manager.rb