Class: Katello::Validators::GpgKeyContentTypeValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/lib/katello/validators/gpg_key_content_type_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/lib/katello/validators/gpg_key_content_type_validator.rb', line 4

def validate(record)
  # need to verify, that gpg_key is of GpgKey.content type "gpg_key" and
  # ssl_ca_cert, ssl_client_cert, ssl_client_key of GpgKey.content type "cert"

  if !record.gpg_key.blank? && record.gpg_key.content_type != "gpg_key"
    record.errors[:gpg_key] << _("Wrong content type submitted.")
  end

  if record.instance_of?(Katello::Product)
    [:ssl_ca_cert, :ssl_client_cert, :ssl_client_key].each do |cert|
      if !record.send(cert).blank? && record.send(cert).content_type != "cert"
        record.errors[cert] << _("Wrong content type submitted.")
      end
    end
  end
end