module ForemanOpenscap::Helper

Public Class Methods

find_host_by_name_or_uuid(cname) click to toggle source
# File lib/foreman_openscap/helper.rb, line 12
def self.find_host_by_name_or_uuid(cname)
  if Facets.registered_facets.keys.include?(:subscription_facet)
    host = Katello::Host::SubscriptionFacet.find_by(uuid: cname).try(:host)
    host ||= Host.find_by(name: cname)
  else
    host = Host.find_by(name: cname)
  end

  unless host
    Rails.logger.error "Could not find Host with name: #{cname}"
    raise ActiveRecord::RecordNotFound
  end
  host
end
find_name_or_uuid_by_host(host) click to toggle source
# File lib/foreman_openscap/helper.rb, line 8
def self.find_name_or_uuid_by_host(host)
  host.respond_to?(:subscription_facet) && !host.subscription_facet.nil? ? host.subscription_facet.try(:uuid) : host.name
end
get_asset(cname, policy_id) click to toggle source
# File lib/foreman_openscap/helper.rb, line 2
def self.get_asset(cname, policy_id)
  asset = find_host_by_name_or_uuid(cname).get_asset
  asset.policy_ids += [policy_id]
  asset
end