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.11.1 lib/foreman_openscap/helper.rb
foreman_openscap-0.11.0 lib/foreman_openscap/helper.rb
foreman_openscap-0.10.4 lib/foreman_openscap/helper.rb
foreman_openscap-0.10.3 lib/foreman_openscap/helper.rb
foreman_openscap-0.10.2 lib/foreman_openscap/helper.rb
foreman_openscap-0.10.1 lib/foreman_openscap/helper.rb
foreman_openscap-0.9.3 lib/foreman_openscap/helper.rb
foreman_openscap-0.10.0 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.13 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.6 lib/foreman_openscap/helper.rb
foreman_openscap-0.9.2 lib/foreman_openscap/helper.rb
foreman_openscap-0.9.1 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.5 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.12 lib/foreman_openscap/helper.rb
foreman_openscap-0.9.0 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.4 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.11 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.10 lib/foreman_openscap/helper.rb
foreman_openscap-0.8.3 lib/foreman_openscap/helper.rb
foreman_openscap-0.7.9 lib/foreman_openscap/helper.rb