Create DomainCreate action

This commit is contained in:
Karl Erik Õunapuu 2020-12-08 12:00:04 +02:00
parent b683fe813c
commit ccef1053d9
No known key found for this signature in database
GPG key ID: C9DD647298A34764
6 changed files with 280 additions and 28 deletions

View file

@ -0,0 +1,89 @@
module Deserializers
module Xml
class DnssecKey
attr_reader :frame, :dsa
KEY_INTERFACE = { flags: 'flags', protocol: 'protocol', alg: 'alg', public_key: 'pubKey' }
DS_INTERFACE = { ds_key_tag: 'keyTag', ds_alg: 'alg', ds_digest_type: 'digestType',
ds_digest: 'digest' }
def initialize(frame, dsa)
@frame = frame
@dsa = dsa
end
def call
dsa ? ds_alg_output : xm_copy(frame, KEY_INTERFACE)
end
def ds_alg_output
ds_key = xm_copy(frame, DS_INTERFACE)
ds_key.merge(xm_copy(frame.css('keyData'), KEY_INTERFACE)) if frame.css('keyData').present?
ds_key
end
def other_alg_output
xm_copy(frame, KEY_INTERFACE)
end
private
def xm_copy(entry, map)
result = {}
map.each do |key, elem|
result[key] = entry.css(elem).first.try(:text)
end
result
end
end
class DnssecKeys
attr_reader :frame, :key_data, :ds_data
def initialize(frame)
@key_data = []
@ds_data = []
# schema validation prevents both in the same parent node
if frame.css('dsData').present?
frame.css('dsData').each do |ds_data|
@ds_data << Deserializers::Xml::DnssecKey.new(ds_data, true).call
end
else
frame.css('keyData').each do |key|
@key_data << Deserializers::Xml::DnssecKey.new(key, false).call
end
end
end
def mark_destroy_all(dns_keys)
# if transition support required mark_destroy dns_keys when has ds/key values otherwise ...
dns_keys.map { |inf_data| mark(inf_data) }
end
def mark_destroy(dns_keys)
(ds_data.present? ? ds_filter(dns_keys) : kd_filter(dns_keys)).map do |inf_data|
inf_data.blank? ? nil : mark(inf_data)
end
end
private
def ds_filter(dns_keys)
@ds_data.map do |ds|
dns_keys.find_by(ds.slice(*DS_INTERFACE.keys))
end
end
def kd_filter(dns_keys)
@key_data.map do |key|
dns_keys.find_by(key)
end
end
def mark(inf_data)
{ id: inf_data.id, _destroy: 1 }
end
end
end
end

View file

@ -2,18 +2,21 @@ module Deserializers
module Xml
class Domain
attr_reader :frame
attr_reader :registrar
def initialize(frame)
def initialize(frame, registrar)
@frame = frame
@registrar = registrar
end
def call
attributes = {
name: if_present('name'),
registrar_id: current_user.registrar.id,
registrar_id: registrar,
registrant_id: if_present('registrant'),
reserved_pw: if_present('reserved > pw'),
period: Integer(frame.css('period').text, 1),
period_unit: parsed_frame.css('period').first ? parsed_frame.css('period').first[:unit] : 'y'
period: Integer(frame.css('period').text) || 1,
period_unit: frame.css('period').first ? frame.css('period').first[:unit] : 'y',
}
pw = frame.css('authInfo > pw').text

View file

@ -1,26 +1,46 @@
require 'deserializers/xml/legal_document'
require 'deserializers/xml/ident'
require 'deserializers/xml/contact'
require 'deserializers/xml/domain'
require 'deserializers/xml/nameserver'
require 'deserializers/xml/dnssec'
module Deserializers
module Xml
class ContactUpdate
class DomainCreate
attr_reader :frame
attr_reader :registrar
def initialize(frame)
def initialize(frame, registrar)
@frame = frame
@registrar = registrar
end
def contact
@contact ||= ::Deserializers::Xml::Contact.new(frame).call
def call
obj = domain
obj[:admin_domain_contacts_attributes] = admin_contacts
obj[:tech_domain_contacts_attributes] = tech_contacts
obj[:nameservers_attributes] = nameservers
obj[:dnskeys_attributes] = dns_keys
obj
end
def ident
@ident ||= ::Deserializers::Xml::Ident.new(frame).call
def domain
@domain ||= ::Deserializers::Xml::Domain.new(frame, registrar).call
end
def legal_document
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
def nameservers
@nameservers ||= ::Deserializers::Xml::Nameservers.new(frame).call
end
def admin_contacts
frame.css('contact').map { |c| c.text if c['type'] == 'admin' }
end
def tech_contacts
frame.css('contact').map { |c| c.text if c['type'] == 'tech' }
end
def dns_keys
@dns_keys ||= ::Deserializers::Xml::DnssecKeys.new(frame).key_data
end
end
end