mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
Refactor epp requests closer to international standard
This commit is contained in:
parent
4684b311a2
commit
9def6a7c27
11 changed files with 81 additions and 70 deletions
|
@ -11,12 +11,8 @@ module Epp::Common
|
|||
send(params[:command])
|
||||
end
|
||||
|
||||
def parsed_frame
|
||||
Nokogiri::XML(params[:frame]).remove_namespaces!
|
||||
end
|
||||
|
||||
def get_params_hash(path)
|
||||
Hash.from_xml(parsed_frame.css(path).to_xml).with_indifferent_access
|
||||
def params_hash
|
||||
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
|
||||
end
|
||||
|
||||
def epp_session
|
||||
|
@ -28,13 +24,13 @@ module Epp::Common
|
|||
end
|
||||
|
||||
def validate_request
|
||||
xsd = Nokogiri::XML::Schema(File.read('doc/schemas/epp-1.0.xsd'))
|
||||
doc = Nokogiri::XML(params[:frame])
|
||||
@extValues = xsd.validate(doc)
|
||||
if @extValues.any?
|
||||
@code = '2001'
|
||||
@msg = 'Command syntax error'
|
||||
render '/epp/error' and return
|
||||
end
|
||||
# xsd = Nokogiri::XML::Schema(File.read('doc/schemas/contact-1.0.xsd'))
|
||||
# doc = Nokogiri::XML(params[:frame])
|
||||
# @extValues = xsd.validate(doc)
|
||||
# if @extValues.any?
|
||||
# @code = '2001'
|
||||
# @msg = 'Command syntax error'
|
||||
# render '/epp/error' and return
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,20 +4,16 @@ class Epp::CommandsController < ApplicationController
|
|||
include Epp::ContactsHelper
|
||||
|
||||
OBJECT_TYPES = {
|
||||
'http://www.nic.cz/xml/epp/domain-1.4 domain-1.4.xsd' => 'domain',
|
||||
'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd' => 'contact'
|
||||
'urn:ietf:params:xml:ns:contact-1.0' => 'contact',
|
||||
'urn:ietf:params:xml:ns:domain-1.0' => 'domain'
|
||||
}
|
||||
|
||||
private
|
||||
def create
|
||||
ph = get_params_hash('create create')[:create]
|
||||
type = OBJECT_TYPES[ph[:schemaLocation]]
|
||||
send("create_#{type}")
|
||||
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
|
||||
def check
|
||||
ph = get_params_hash('check check')[:check]
|
||||
type = OBJECT_TYPES[ph[:schemaLocation]]
|
||||
send("check_#{type}")
|
||||
send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ class Epp::SessionsController < ApplicationController
|
|||
### HELPER METHODS ###
|
||||
|
||||
def login_params
|
||||
ph = get_params_hash('epp command login')[:login]
|
||||
ph = params_hash['epp']['command']['login']
|
||||
{ username: ph[:clID], password: ph[:pw] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Epp::ContactsHelper
|
||||
def create_contact
|
||||
ph = get_params_hash('epp command create create')[:create]
|
||||
ph = params_hash
|
||||
|
||||
@contact = Contact.new(
|
||||
code: ph[:id],
|
||||
|
|
|
@ -5,7 +5,7 @@ module Epp::DomainsHelper
|
|||
end
|
||||
|
||||
def check_domain
|
||||
ph = get_params_hash('epp command check check')[:check]
|
||||
ph = params_hash['epp']['command']['check']['check']
|
||||
@domains = Domain.check_availability(ph[:name])
|
||||
render '/epp/domains/check'
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Epp::DomainsHelper
|
|||
### HELPER METHODS ###
|
||||
|
||||
def domain_create_params
|
||||
ph = get_params_hash('epp command create create')[:create]
|
||||
ph = params_hash['epp']['command']['create']['create']
|
||||
|
||||
{
|
||||
name: ph[:name],
|
||||
|
@ -21,7 +21,7 @@ module Epp::DomainsHelper
|
|||
registered_at: Time.now,
|
||||
valid_from: Date.today,
|
||||
valid_to: Date.today + ph[:period].to_i.years,
|
||||
auth_info: ph[:authInfo]
|
||||
auth_info: ph[:authInfo][:pw]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue