mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Added xml epp console required endpoints and sample xml files
This commit is contained in:
parent
30fd6d2465
commit
aaa0e89cfe
21 changed files with 460 additions and 4 deletions
57
app/controllers/concerns/epp_requestable.rb
Normal file
57
app/controllers/concerns/epp_requestable.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
module EppRequestable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :validate_epp_user, only: :create
|
||||
end
|
||||
|
||||
def create
|
||||
result = server.request(request_params[:payload])
|
||||
render_success(data: { xml: result })
|
||||
rescue StandardError
|
||||
handle_non_epp_errors(nil, I18n.t('errors.messages.epp_conn_error'))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_epp_user
|
||||
tag = current_user.username
|
||||
password = current_user.plain_text_password
|
||||
res = server.open_connection
|
||||
unless Nokogiri::XML(res).css('greeting')
|
||||
server.close_connection # just in case
|
||||
handle_non_epp_errors(nil, I18n.t('errors.messages.failed_epp_conn'))
|
||||
return
|
||||
end
|
||||
|
||||
ex = EppXml::Session.new(cl_trid_prefix: tag)
|
||||
xml = ex.login(clID: { value: tag }, pw: { value: password })
|
||||
res = server.send_request(xml)
|
||||
|
||||
if Nokogiri::XML(res).css('result').first['code'] != '1000'
|
||||
handle_non_epp_errors(nil, Nokogiri::XML(res).css('result').text)
|
||||
end
|
||||
|
||||
server.close_connection
|
||||
rescue OpenSSL::SSL::SSLError => e
|
||||
Rails.logger.error "INVALID CERT: #{e}"
|
||||
Rails.logger.error "INVALID CERT DEBUG INFO: epp_hostname: #{ENV['epp_hostname']}," \
|
||||
"port: #{ENV['epp_port']}, cert_path: #{ENV['cert_path']}, key_path: #{ENV['key_path']}"
|
||||
handle_non_epp_errors(nil, I18n.t('errors.messages.invalid_cert'))
|
||||
end
|
||||
|
||||
def server
|
||||
client_cert = File.read(ENV['cert_path'])
|
||||
client_key = File.read(ENV['key_path'])
|
||||
port = ENV['epp_port'] || 700
|
||||
@server ||= Epp::Server.new({ server: ENV['epp_hostname'], tag: current_user.username,
|
||||
password: current_user.plain_text_password,
|
||||
port: port,
|
||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
||||
key: OpenSSL::PKey::RSA.new(client_key) })
|
||||
end
|
||||
|
||||
def request_params
|
||||
params.require(:xml_console).permit(:payload)
|
||||
end
|
||||
end
|
55
app/controllers/repp/v1/registrar/xml_console_controller.rb
Normal file
55
app/controllers/repp/v1/registrar/xml_console_controller.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Repp
|
||||
module V1
|
||||
module Registrar
|
||||
class XmlConsoleController < BaseController
|
||||
include EppRequestable
|
||||
|
||||
PREFS = %w[
|
||||
domain-ee
|
||||
contact-ee
|
||||
eis
|
||||
epp-ee
|
||||
].freeze
|
||||
|
||||
def load_xml
|
||||
cl_trid = "#{current_user.username}-#{Time.zone.now.to_i}"
|
||||
xml_dir_path = Rails.root.join('app/views/epp/sample_requests').to_s
|
||||
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
|
||||
xml = prepare_payload(xml, cl_trid)
|
||||
|
||||
render_success(data: { xml: xml })
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_payload(xml, cl_trid)
|
||||
PREFS.map do |pref|
|
||||
xml = load_schema_by_prefix(pref, xml)
|
||||
end
|
||||
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
xml
|
||||
end
|
||||
|
||||
def load_schema_by_prefix(pref, xml)
|
||||
case pref
|
||||
when 'epp-ee'
|
||||
insert_prefix_and_version(xml, pref, '1.0')
|
||||
when 'eis'
|
||||
insert_prefix_and_version(xml, pref, '1.0')
|
||||
when 'contact-ee'
|
||||
insert_prefix_and_version(xml, pref, '1.1')
|
||||
else
|
||||
insert_prefix_and_version(xml, pref, '1.2')
|
||||
end
|
||||
end
|
||||
|
||||
def insert_prefix_and_version(xml, pref, version)
|
||||
xml.gsub!("\"#{pref}\"",
|
||||
"\"#{Xsd::Schema.filename(for_prefix: pref.to_s, for_version: version)}\"")
|
||||
xml
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue