Sha256: 7653c0bc6a12559eccc8bbd87cc126dd1439ed71b86217152f2b9bdb9268df7e

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

module ForemanOpenscap
  class ScapContent < ApplicationRecord
    include Authorizable
    include Taxonomix
    include DataStreamContent
    audited :except => [ :scap_file ]

    has_many :scap_content_profiles, :dependent => :destroy
    has_many :policies

    validates :title, :presence => true, :length => { :maximum => 255 }
    validates :original_filename, :length => { :maximum => 255 }

    scoped_search :on => :title,             :complete_value => true
    scoped_search :on => :original_filename, :complete_value => true, :rename => :filename

    default_scope do
      with_taxonomy_scope do
        order("foreman_openscap_scap_contents.title")
      end
    end

    def used_location_ids
      Location.joins(:taxable_taxonomies).where(
        'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::ScapContent',
        'taxable_taxonomies.taxable_id' => id
      ).pluck("#{Location.arel_table.name}.id")
    end

    def used_organization_ids
      Organization.joins(:taxable_taxonomies).where(
        'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::ScapContent',
        'taxable_taxonomies.taxable_id' => id
      ).pluck("#{Location.arel_table.name}.id")
    end

    def to_label
      title
    end

    def as_json(*args)
      hash = super
      hash["scap_file"] = scap_file.to_s.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')
    end

    def fetch_profiles
      api = ProxyAPI::Openscap.new(:url => proxy_url)
      profiles = api.fetch_policies_for_scap_content(scap_file)
      profiles
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_openscap-0.8.3 app/models/foreman_openscap/scap_content.rb
foreman_openscap-0.8.2 app/models/foreman_openscap/scap_content.rb
foreman_openscap-0.8.1 app/models/foreman_openscap/scap_content.rb