Sha256: 2f6f62da636269ed9c7d9fee9790bcc3551444ceaad4629cc7f8e894aae55212

Contents?: true

Size: 1.36 KB

Versions: 77

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8

module Katello
  module Validators
    class GpgKeyContentValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        if value
          GpgKeyContentValidator.validate_line_length(record, attribute, value)
          gpg_key_line_array = value.split("\n")
          gpg_key_line_array.delete("")

          if gpg_key_line_array.first.match(/-{5}BEGIN PGP PUBLIC KEY BLOCK-{5}/) && gpg_key_line_array.last.match(/-{5}END PGP PUBLIC KEY BLOCK-{5}/)

            gpg_key_line_array.shift
            gpg_key_line_array.pop

            if gpg_key_line_array.empty?
              record.errors[attribute] << _("must contain valid Public GPG Key")
            else
              unless gpg_key_line_array.drop(1).join.match(/[a-zA-Z0-9+\/=]*/)
                record.errors[attribute] << _("must contain valid Public GPG Key")
              end
            end

          else
            record.errors[attribute] << _("must contain valid Public GPG Key")
          end

        else
          record.errors[attribute] << _("must contain GPG Key")
        end
      end

      def self.validate_line_length(record, attribute, value)
        value.each_line do |line|
          record.errors[attribute] << _("must contain valid  Public GPG Key") if line.length > ContentCredential::MAX_CONTENT_LINE_LENGTH
        end
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
katello-4.15.0.rc2 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.15.0.rc1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.0 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.0.rc3 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.0.rc2 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.0.rc1.1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.14.0.rc1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.13.1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.13.0 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.12.1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.13.0.rc1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.12.0 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.12.0.rc3 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.12.0.rc2 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.12.0.rc1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.11.1 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.11.0 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.11.0.rc2 app/lib/katello/validators/gpg_key_content_validator.rb
katello-4.11.0.rc1 app/lib/katello/validators/gpg_key_content_validator.rb