mirror of
https://github.com/internetee/registry.git
synced 2025-06-13 16:14:47 +02:00
Nameserver deserializer
This commit is contained in:
parent
b39de0885a
commit
7459d7e0c5
4 changed files with 53 additions and 21 deletions
|
@ -1,7 +1,9 @@
|
||||||
|
require 'serializers/registrant_api/domain'
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class DomainsController < BaseController
|
class DomainsController < BaseController
|
||||||
before_action :set_authorized_domain, only: [:transfer_info]
|
before_action :set_authorized_domain, only: %i[transfer_info]
|
||||||
|
before_action :set_domain, only: %i[show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
records = current_user.registrar.domains
|
records = current_user.registrar.domains
|
||||||
|
@ -11,6 +13,10 @@ module Repp
|
||||||
render_success(data: { domains: domains, total_number_of_records: records.count })
|
render_success(data: { domains: domains, total_number_of_records: records.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json })
|
||||||
|
end
|
||||||
|
|
||||||
def transfer_info
|
def transfer_info
|
||||||
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
||||||
zip country_code statuses]
|
zip country_code statuses]
|
||||||
|
@ -66,12 +72,16 @@ module Repp
|
||||||
params.permit(:id)
|
params.permit(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_domain
|
||||||
|
@domain = Domain.find_by(registrar: current_user.registrar, name: params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def set_authorized_domain
|
def set_authorized_domain
|
||||||
@epp_errors ||= []
|
@epp_errors ||= []
|
||||||
h = {}
|
h = {}
|
||||||
h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id]
|
h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id]
|
||||||
@domain = Domain.find_by!(h)
|
@domain = Domain.find_by!(h)
|
||||||
|
return if @domain.registrar == current_user.registrar
|
||||||
return if @domain.transfer_code.eql?(request.headers['Auth-Code'])
|
return if @domain.transfer_code.eql?(request.headers['Auth-Code'])
|
||||||
|
|
||||||
@epp_errors << { code: 2202, msg: I18n.t('errors.messages.epp_authorization_error') }
|
@epp_errors << { code: 2202, msg: I18n.t('errors.messages.epp_authorization_error') }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'deserializers/xml/legal_document'
|
require 'deserializers/xml/legal_document'
|
||||||
|
require 'deserializers/xml/nameserver'
|
||||||
class Epp::Domain < Domain
|
class Epp::Domain < Domain
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ class Epp::Domain < Domain
|
||||||
at[:nameservers_attributes] = nameservers_attrs(frame, action)
|
at[:nameservers_attributes] = nameservers_attrs(frame, action)
|
||||||
at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action)
|
at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action)
|
||||||
at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action)
|
at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action)
|
||||||
|
puts "JHDFHJDGFKDJHF"
|
||||||
pw = frame.css('authInfo > pw').text
|
pw = frame.css('authInfo > pw').text
|
||||||
at[:transfer_code] = pw if pw.present?
|
at[:transfer_code] = pw if pw.present?
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ class Epp::Domain < Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
def nameservers_attrs(frame, action)
|
def nameservers_attrs(frame, action)
|
||||||
ns_list = nameservers_from(frame)
|
ns_list = ::Deserializers::Xml::Nameservers.new(frame).call
|
||||||
|
|
||||||
if action == 'rem'
|
if action == 'rem'
|
||||||
to_destroy = []
|
to_destroy = []
|
||||||
|
@ -215,21 +215,6 @@ class Epp::Domain < Domain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def nameservers_from(frame)
|
|
||||||
res = []
|
|
||||||
frame.css('hostAttr').each do |x|
|
|
||||||
host_attr = {
|
|
||||||
hostname: x.css('hostName').first.try(:text),
|
|
||||||
ipv4: x.css('hostAddr[ip="v4"]').map(&:text).compact,
|
|
||||||
ipv6: x.css('hostAddr[ip="v6"]').map(&:text).compact
|
|
||||||
}
|
|
||||||
|
|
||||||
res << host_attr.delete_if { |_k, v| v.blank? }
|
|
||||||
end
|
|
||||||
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
def admin_domain_contacts_attrs(frame, action)
|
def admin_domain_contacts_attrs(frame, action)
|
||||||
admin_attrs = domain_contact_attrs_from(frame, action, 'admin')
|
admin_attrs = domain_contact_attrs_from(frame, action, 'admin')
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :domains do
|
resources :domains, constraints: { id: /.*/ } do
|
||||||
collection do
|
collection do
|
||||||
get ':id/transfer_info', to: 'domains#transfer_info', constraints: { id: /.*/ }
|
get ':id/transfer_info', to: 'domains#transfer_info', constraints: { id: /.*/ }
|
||||||
post 'transfer', to: 'domains#transfer'
|
post 'transfer', to: 'domains#transfer'
|
||||||
|
|
37
lib/deserializers/xml/nameserver.rb
Normal file
37
lib/deserializers/xml/nameserver.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
module Deserializers
|
||||||
|
module Xml
|
||||||
|
class Nameserver
|
||||||
|
attr_reader :frame
|
||||||
|
|
||||||
|
def initialize(frame)
|
||||||
|
@frame = frame
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
{
|
||||||
|
hostname: frame.css('hostName').text,
|
||||||
|
ipv4: frame.css('hostAddr[ip="v4"]').map(&:text).compact,
|
||||||
|
ipv6: frame.css('hostAddr[ip="v6"]').map(&:text).compact
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Nameservers
|
||||||
|
attr_reader :frame
|
||||||
|
|
||||||
|
def initialize(frame)
|
||||||
|
@frame = frame
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
res = []
|
||||||
|
frame.css('hostAttr').each do |ns|
|
||||||
|
ns = Deserializers::Xml::Nameserver.new(ns).call
|
||||||
|
res << ns.delete_if { |_k, v| v.blank? }
|
||||||
|
end
|
||||||
|
|
||||||
|
res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue