Sha256: b515378c3c1f3b347bec62479b2b4f889c24a7683be4b08f816821121d247272

Contents?: true

Size: 790 Bytes

Versions: 30

Compression:

Stored size: 790 Bytes

Contents

module ForemanOpenscap::Helper
  def self.get_asset(cname, policy_id)
    asset = find_host_by_name_or_uuid(cname).get_asset
    asset.policy_ids += [policy_id]
    asset
  end

  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

  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
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
foreman_openscap-0.7.8 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.7 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.2 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.6 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.1 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.5 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.0 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.4 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.3 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.2 lib/foreman_openscap/helper.rb