Sha256: cbbc2de6203dd60336a2699419a3ee7ecf0516cd4e4be8ff6fd2a9e2899364c9
Contents?: true
Size: 1.57 KB
Versions: 10
Compression:
Stored size: 1.57 KB
Contents
module ForemanOpenscap class DataStreamValidator < ActiveModel::Validator def validate(data_stream_content) return unless data_stream_content.scap_file_changed? content_type = data_type(data_stream_content) unless SmartProxy.with_features('Openscap').any? data_stream_content.errors.add(:base, _('No proxy with OpenSCAP feature was found.')) return false end if data_stream_content.proxy_url.nil? data_stream_content.errors.add(:base, _('No proxy with OpenSCAP feature is running.')) return false end begin api = ProxyAPI::Openscap.new(:url => data_stream_content.proxy_url) errors = api.validate_scap_file(data_stream_content.scap_file, content_type) if errors && errors['errors'].any? errors['errors'].each { |error| data_stream_content.errors.add(:scap_file, _(error)) } return false end rescue *ProxyAPI::Openscap::HTTP_ERRORS => e data_stream_content.errors.add(:base, _('No available proxy to validate. Returned with error: %s') % e) return false end is_scap_content = content_type == 'scap_content' if is_scap_content && !(data_stream_content.scap_content_profiles.map(&:profile_id) - data_stream_content.fetch_profiles.keys).empty? data_stream_content.errors.add(:scap_file, _('Changed file does not include existing SCAP content profiles')) return false end end private def data_type(data_stream_content) data_stream_content.class.to_s.demodulize.underscore end end end
Version data entries
10 entries across 10 versions & 1 rubygems