mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Attach nameservers with attributes
This commit is contained in:
parent
356835bebf
commit
d46640713b
6 changed files with 79 additions and 3 deletions
|
@ -53,7 +53,9 @@ module Epp::DomainsHelper
|
||||||
def domain_nameservers
|
def domain_nameservers
|
||||||
ph = params_hash['epp']['command']['create']['create']['ns']
|
ph = params_hash['epp']['command']['create']['create']['ns']
|
||||||
return [] unless ph
|
return [] unless ph
|
||||||
ph[:hostObj]
|
return ph[:hostObj] if ph[:hostObj]
|
||||||
|
return ph[:hostAttr] if ph[:hostAttr]
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_errors
|
def handle_errors
|
||||||
|
|
|
@ -63,8 +63,20 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach_nameservers(ns_list)
|
def attach_nameservers(ns_list)
|
||||||
ns_list.each do |x|
|
ns_list.each do |ns|
|
||||||
self.nameservers.build(hostname: x)
|
#ns with detailed attributes
|
||||||
|
if ns.is_a?(Hash)
|
||||||
|
attrs = {hostname: ns[:hostName]}
|
||||||
|
|
||||||
|
ns[:hostAddr].each do |ip|
|
||||||
|
attrs[:ip] = ip unless attrs[:ip]
|
||||||
|
end if ns[:hostAddr]
|
||||||
|
|
||||||
|
self.nameservers.build(attrs)
|
||||||
|
#ns with just hostname
|
||||||
|
else
|
||||||
|
self.nameservers.build(hostname: ns)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
save
|
save
|
||||||
|
@ -76,6 +88,14 @@ class Domain < ActiveRecord::Base
|
||||||
errors.empty?
|
errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def validate_nameservers
|
||||||
|
# nameservers.each do |x|
|
||||||
|
# x.errors.each do |err|
|
||||||
|
# errors.add(:nameservers)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
def add_child_collection_errors(attr_key, epp_obj_name)
|
def add_child_collection_errors(attr_key, epp_obj_name)
|
||||||
send(attr_key).each do |obj|
|
send(attr_key).each do |obj|
|
||||||
obj.errors.keys.each do |key|
|
obj.errors.keys.each do |key|
|
||||||
|
|
|
@ -3,4 +3,5 @@ class Nameserver < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :domains
|
has_and_belongs_to_many :domains
|
||||||
|
|
||||||
validates :hostname, hostname: true
|
validates :hostname, hostname: true
|
||||||
|
validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true}
|
||||||
end
|
end
|
||||||
|
|
15
app/validators/nameserver_ip_validator.rb
Normal file
15
app/validators/nameserver_ip_validator.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class NameserverIpValidator < ActiveModel::EachValidator
|
||||||
|
def validate_each(record, attribute, value)
|
||||||
|
if record.domain_
|
||||||
|
|
||||||
|
if !self.class.validate_format(value)
|
||||||
|
record.errors.add(attribute, (options[:message] || :invalid))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def validate_format(value)
|
||||||
|
!!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -84,6 +84,14 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:result_code]).to eq('2005')
|
expect(response[:result_code]).to eq('2005')
|
||||||
expect(response[:msg]).to eq('Hostname is invalid')
|
expect(response[:msg]).to eq('Hostname is invalid')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
it 'creates domain with nameservers with ips' do
|
||||||
|
response = epp_request('domains/create_w_host_attrs.xml')
|
||||||
|
expect(Domain.first.nameservers.count).to eq(2)
|
||||||
|
ns = Domain.first.nameservers.first
|
||||||
|
expect(ns.ip).to eq('192.0.2.2')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with juridical persion as an owner' do
|
context 'with juridical persion as an owner' do
|
||||||
|
|
30
spec/epp/requests/domains/create_w_host_attrs.xml
Normal file
30
spec/epp/requests/domains/create_w_host_attrs.xml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<create>
|
||||||
|
<domain:create
|
||||||
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
|
<domain:name>example.ee</domain:name>
|
||||||
|
<domain:period unit="y">1</domain:period>
|
||||||
|
<domain:ns>
|
||||||
|
<domain:hostAttr>
|
||||||
|
<domain:hostName>ns1.example.net</domain:hostName>
|
||||||
|
<domain:hostAddr ip="v4">192.0.2.2</domain:hostAddr>
|
||||||
|
<domain:hostAddr ip="v6">1080:0:0:0:8:800:200C:417A</domain:hostAddr>
|
||||||
|
</domain:hostAttr>
|
||||||
|
<domain:hostAttr>
|
||||||
|
<domain:hostName>ns2.example.net</domain:hostName>
|
||||||
|
</domain:hostAttr>
|
||||||
|
</domain:ns>
|
||||||
|
<domain:registrant>jd1234</domain:registrant>
|
||||||
|
<domain:contact type="admin">sh8013</domain:contact>
|
||||||
|
<domain:contact type="tech">sh8013</domain:contact>
|
||||||
|
<domain:contact type="tech">sh801333</domain:contact>
|
||||||
|
<domain:authInfo>
|
||||||
|
<domain:pw>2fooBAR</domain:pw>
|
||||||
|
</domain:authInfo>
|
||||||
|
</domain:create>
|
||||||
|
</create>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue