Class: Scaptimony::DataStreamValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/scaptimony/scap_content.rb

Instance Method Summary collapse

Instance Method Details

#validate(scap_content) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/scaptimony/scap_content.rb', line 9

def validate(scap_content)
  return unless scap_content.scap_file_changed?

  allowed_type = 'SCAP Source Datastream'
  if scap_content.source.try(:type) != allowed_type
    scap_content.errors[:base] << _("Uploaded file is not #{allowed_type}.")
    return false
  end

  begin
    scap_content.source.validate!
  rescue OpenSCAP::OpenSCAPError => e
    scap_content.errors[:base] << e.message
  end

  unless (scap_content.scap_content_profiles.map(&:profile_id) - scap_content.benchmark_profiles.profiles.keys).empty?
    scap_content.errors[:base] << _('Changed file does not include existing SCAP Content profiles.')
    return false
  end
end