mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
updated approach for loading schemas in xml console
This commit is contained in:
parent
ad23a7cbd2
commit
5b8b18f584
18 changed files with 258 additions and 55 deletions
|
@ -1,15 +1,22 @@
|
|||
class Registrar
|
||||
class XmlConsolesController < DeppController
|
||||
PREFS = %w[
|
||||
domain-ee
|
||||
contact-ee
|
||||
eis
|
||||
epp-ee
|
||||
].freeze
|
||||
|
||||
authorize_resource class: false
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def create
|
||||
begin
|
||||
@result = depp_current_user.server.request(params[:payload])
|
||||
checking_schema_valid_path(params[:payload])
|
||||
rescue
|
||||
|
||||
check_schema_path(params[:payload])
|
||||
rescue StandardError
|
||||
@result = 'CONNECTION ERROR - Is the EPP server running?'
|
||||
end
|
||||
render :show
|
||||
|
@ -19,31 +26,78 @@ class Registrar
|
|||
cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}"
|
||||
xml_dir_path = Rails.root + 'app/views/registrar/xml_consoles/epp_requests'
|
||||
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
xml = prepare_payload(xml, cl_trid)
|
||||
|
||||
render plain: xml
|
||||
end
|
||||
|
||||
private
|
||||
protected
|
||||
|
||||
def checking_schema_valid_path(payload)
|
||||
path = regex_to_find_domain_schema(payload)
|
||||
def check_schema_path(payload)
|
||||
path = nil
|
||||
path = regex_to_find_domain_schema(payload) if regex_to_find_domain_schema(payload).present?
|
||||
path = regex_to_find_contact_schema(payload) if regex_to_find_contact_schema(payload).present?
|
||||
path = regex_to_find_poll_schema(payload) if regex_to_find_poll_schema(payload).present?
|
||||
|
||||
@result = template_wrong_path unless array_valid_paths.include? path
|
||||
end
|
||||
@result = wrong_path_response unless array_valid_paths.include? path
|
||||
end
|
||||
|
||||
def array_valid_paths
|
||||
Xsd::Schema::PREFIXES.map{|prefix| Xsd::Schema.filename(for_prefix: prefix)}
|
||||
end
|
||||
def array_valid_paths
|
||||
Xsd::Schema::PREFIXES.map { |prefix| Xsd::Schema.filename(for_prefix: prefix) }
|
||||
end
|
||||
|
||||
def template_wrong_path
|
||||
'Wrong schema path'
|
||||
def wrong_path_response
|
||||
cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}"
|
||||
|
||||
<<~XML
|
||||
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<epp xmlns=\"https://epp.tld.ee/schema/epp-ee-1.0.xsd\"
|
||||
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
|
||||
xsi:schemaLocation=\"lib/schemas/epp-ee-1.0.xsd\">
|
||||
<response>
|
||||
<result code=\"2100\">
|
||||
<msg lang=\"en\">Wrong schema</msg>
|
||||
</result>
|
||||
<trID>
|
||||
<clTRID>#{cl_trid}</clTRID>
|
||||
<svTRID>eePrx-#{Time.zone.now.to_i}</svTRID>
|
||||
</trID>
|
||||
</response>
|
||||
</epp>
|
||||
XML
|
||||
end
|
||||
|
||||
def regex_to_find_domain_schema(payload)
|
||||
domain_schema_tag = payload.scan(/xmlns:domain[\S]+/)
|
||||
schema_path = domain_schema_tag.to_s.match(/https?:\/\/[\S]+/)[0]
|
||||
path = schema_path.split('\\')[0]
|
||||
path
|
||||
domain_schema_tag = payload.scan(/xmlns:domain\S+/)
|
||||
return if domain_schema_tag.empty?
|
||||
|
||||
schema_path = domain_schema_tag.to_s.match(%r{https?://\S+})[0]
|
||||
schema_path.split('\\')[0]
|
||||
end
|
||||
|
||||
def regex_to_find_contact_schema(payload)
|
||||
contact_schema_tag = payload.scan(/xmlns:contact\S+/)
|
||||
return if contact_schema_tag.empty?
|
||||
|
||||
schema_path = contact_schema_tag.to_s.match(%r{https?://\S+})[0]
|
||||
schema_path.split('\\')[0]
|
||||
end
|
||||
|
||||
def regex_to_find_poll_schema(payload)
|
||||
contact_schema_tag = payload.scan(/poll\S+/)
|
||||
return if contact_schema_tag.empty?
|
||||
|
||||
'https://epp.tld.ee/schema/epp-ee-1.0.xsd'
|
||||
end
|
||||
|
||||
def prepare_payload(xml, cl_trid)
|
||||
PREFS.map do |pref|
|
||||
xml.gsub!('"' + pref.to_s + '"',
|
||||
"\"#{Xsd::Schema.filename(for_prefix: pref.to_s)}\"")
|
||||
end
|
||||
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
xml
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue