Sha256: 6f3763992b3b77363ad098e8e6c3f0e177d99988b3b20033a49fc2d8dd0afad8

Contents?: true

Size: 799 Bytes

Versions: 8

Compression:

Stored size: 799 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

  private

  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}"
      fail ActiveRecord::RecordNotFound
    end
    host
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman_openscap-0.7.1 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.7 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.0 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.6 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.5 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.4 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.3 lib/foreman_openscap/helper.rb
foreman_openscap-0.6.2 lib/foreman_openscap/helper.rb