Sha256: 1dd92723908756c31b52a8cbb454a434a8a953ad2db2cd31c315c1da5f323ac7

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'openscap'
require 'openscap/ds/sds'

module Scaptimony
  class Policy < ActiveRecord::Base
    attr_accessible :description, :name, :period, :scap_content_id, :scap_content_profile_id,
                    :weekday, :day_of_month, :cron_line
    belongs_to :scap_content
    belongs_to :scap_content_profile
    has_many :arf_reports, :dependent => :destroy
    has_many :asset_policies
    has_many :assets, :through => :asset_policies

    validates :name, :presence => true

    scoped_search :on => :name, :complete_value => true

    def assign_assets(a)
      self.asset_ids = (self.asset_ids + a.collect(&:id)).uniq
    end

    def to_html
      if self.scap_content.blank? || self.scap_content_profile.blank?
        return warn(_('Cannot generate HTML guide for %{scap_content}/%{profile}') %
          { :scap_content => self.scap_content, :profile => self.scap_content_profile })
      end

      sds = OpenSCAP::DS::Sds.new self.scap_content.source
      sds.select_checklist
      profile_id = self.scap_content_profile.nil? ? nil : self.scap_content_profile.profile_id
      html = sds.html_guide profile_id
      sds.destroy
      html
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scaptimony-0.3.0 app/models/scaptimony/policy.rb