Class: SccProduct

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Authorizable, ForemanTasks::Concerns::ActionSubject
Defined in:
app/models/scc_product.rb

Instance Method Summary collapse

Instance Method Details

#pretty_descriptionObject

Remove HTML tags (currently assumed that there are only paragraph tags) Remove second HTML paragraph if available



36
37
38
39
40
41
42
43
44
# File 'app/models/scc_product.rb', line 36

def pretty_description
  new_description = Nokogiri::XML(description).xpath('//p')
  # No tags to remove
  if new_description.count == 0
    description
  else
    new_description.first.children.first.text.strip
  end
end

#pretty_nameObject



30
31
32
# File 'app/models/scc_product.rb', line 30

def pretty_name
  friendly_name + " (id: #{scc_id})"
end

#subscribeObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/scc_product.rb', line 46

def subscribe
  raise 'Product already subscribed!' if product

  new_product = Katello::Product.new
  new_product.name = pretty_name
  new_product.description = pretty_description
  ForemanTasks.sync_task(::Actions::Katello::Product::Create, new_product, .organization)
  new_product.reload
  scc_repositories.each do |repo|
    uniq_repo_name = repo.uniq_name(self)
    label = Katello::Util::Model.labelize(uniq_repo_name)
    unprotected = true
    gpg_key = new_product.gpg_key
    new_repo = new_product.add_repo(label, uniq_repo_name, repo.url, 'yum', unprotected, gpg_key)
    new_repo.arch = arch || 'noarch'
    new_repo.mirroring_policy = .mirroring_policy
    new_repo.download_policy = .download_policy
    if new_repo.has_attribute?('upstream_authentication_token')
      new_repo.upstream_authentication_token = repo.token
      new_repo.url = repo.url
    else
      new_repo.url = repo.full_url
    end
    new_repo.verify_ssl_on_sync = true
    ForemanTasks.sync_task(::Actions::Katello::Repository::Create, new_repo, false, false)
  end
  update!(product: new_product)
end

#uniq_nameObject



26
27
28
# File 'app/models/scc_product.rb', line 26

def uniq_name
  "#{scc_id} " + friendly_name
end