internetee-registry/app/models/dnskey.rb
2014-10-07 18:00:14 +03:00

54 lines
1.3 KiB
Ruby

class Dnskey < ActiveRecord::Base
include EppErrors
belongs_to :domain
validates :alg, :protocol, :flags, :public_key, presence: true
validate :validate_algorithm
validate :validate_protocol
validate :validate_flags
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
PROTOCOLS = %w(3)
FLAGS = %w(0 256 257)
def epp_code_map
{
'2005' => [
[:alg, :invalid, { value: { obj: 'alg', val: alg } }],
[:protocol, :invalid, { value: { obj: 'protocol', val: protocol } }],
[:flags, :invalid, { value: { obj: 'flags', val: flags } }]
],
'2302' => [
[:public_key, :taken, { value: { obj: 'pubKye', val: public_key } }]
],
'2303' => [
[:base, :dnskey_not_found, { value: { obj: 'pubKey', val: public_key } }]
],
'2306' => [
[:alg, :blank],
[:protocol, :blank],
[:flags, :blank],
[:public_key, :blank]
]
}
end
def validate_algorithm
return if alg.blank?
return if %w(3 5 6 7 8 252 253 254 255).include?(alg.to_s)
errors.add(:alg, :invalid)
end
def validate_protocol
return if protocol.blank?
return if %w(3).include?(protocol.to_s)
errors.add(:protocol, :invalid)
end
def validate_flags
return if flags.blank?
return if %w(0 256 257).include?(flags.to_s)
errors.add(:flags, :invalid)
end
end