Sha256: e0b16d0d145ace976863d20fc0bd2fb5217017c49cb8b8bc8a393c5206df73f2

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

module ForemanOpenscap
  module DataStreamContent
    require 'digest/sha2'

    extend ActiveSupport::Concern

    included do
      validates :digest, :presence => true
      validates :scap_file, :presence => true

      validates_with ForemanOpenscap::DataStreamValidator

      after_save :create_profiles

      before_validation :redigest, :if => lambda { |ds_content| ds_content.persisted? && ds_content.scap_file_changed? }
      before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:policies)
    end

    def proxy_url
      @proxy_url ||= SmartProxy.with_features('Openscap').find do |proxy|
        available = ProxyAPI::AvailableProxy.new(:url => proxy.url)
        available.available?
      end.try(:url)
      @proxy_url
    end

    def digest
      self[:digest] ||= Digest::SHA256.hexdigest(scap_file.to_s)
    end

    private

    def redigest
      self[:digest] = Digest::SHA256.hexdigest(scap_file.to_s)
    end

    def create_profiles
      fetch_profiles.each do |key, title|
        ScapContentProfile.where(:profile_id => key, :title => title, "#{self.class.to_s.demodulize.underscore}_id".to_sym => id).first_or_create
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_openscap-0.8.1 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.5 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.8.0 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.4 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.3 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.2 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.1 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.6.7 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.7.0 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.6.6 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.6.5 app/models/concerns/foreman_openscap/data_stream_content.rb
foreman_openscap-0.6.4 app/models/concerns/foreman_openscap/data_stream_content.rb