mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 23:54:44 +02:00
Fix CC issues
This commit is contained in:
parent
fbad7b00b2
commit
3979fc5f8f
4 changed files with 65 additions and 95 deletions
|
@ -26,36 +26,70 @@ class Registrar
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def do_request(request, uri)
|
def process_response(response:, start_notice: "", active_tab:)
|
||||||
if Rails.env.test?
|
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
if response.code == '200'
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
notices = [start_notice]
|
||||||
http.request(request)
|
|
||||||
end
|
notices << "#{t('registrar.tech_contacts.process_request.affected_domains')}: " \
|
||||||
elsif Rails.env.development?
|
"#{parsed_response[:data][:affected_domains].join(', ')}"
|
||||||
client_cert = File.read(ENV['cert_path'])
|
|
||||||
client_key = File.read(ENV['key_path'])
|
if parsed_response[:data][:skipped_domains]
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
notices << "#{t('registrar.tech_contacts.process_request.skipped_domains')}: " \
|
||||||
use_ssl: (uri.scheme == 'https'),
|
"#{parsed_response[:data][:skipped_domains].join(', ')}"
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
flash[:notice] = notices.join(', ')
|
||||||
|
redirect_to registrar_domains_url
|
||||||
else
|
else
|
||||||
client_cert = File.read(ENV['cert_path'])
|
@error = response.code == '404' ? 'Contact(s) not found' : parsed_response[:message]
|
||||||
client_key = File.read(ENV['key_path'])
|
render file: 'registrar/bulk_change/new', locals: { active_tab: active_tab }
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_request(request, uri)
|
||||||
|
response = if Rails.env.test?
|
||||||
|
do_test_request(request, uri)
|
||||||
|
elsif Rails.env.development?
|
||||||
|
do_dev_request(request, uri)
|
||||||
|
else
|
||||||
|
do_live_request(request, uri)
|
||||||
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def do_live_request(request, uri)
|
||||||
|
client_cert = File.read(ENV['cert_path'])
|
||||||
|
client_key = File.read(ENV['key_path'])
|
||||||
|
Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
cert: OpenSSL::X509::Certificate.new(client_cert),
|
||||||
|
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_dev_request(request, uri)
|
||||||
|
client_cert = File.read(ENV['cert_path'])
|
||||||
|
client_key = File.read(ENV['key_path'])
|
||||||
|
Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
||||||
|
cert: OpenSSL::X509::Certificate.new(client_cert),
|
||||||
|
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_test_request(request, uri)
|
||||||
|
Net::HTTP.start(uri.hostname, uri.port,
|
||||||
|
use_ssl: (uri.scheme == 'https'),
|
||||||
|
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||||
|
http.request(request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ready_to_renew?
|
def ready_to_renew?
|
||||||
domain_ids_for_bulk_renew.present? && params[:renew].present?
|
domain_ids_for_bulk_renew.present? && params[:renew].present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,32 +25,7 @@ class Registrar
|
||||||
current_registrar_user.plain_text_password)
|
current_registrar_user.plain_text_password)
|
||||||
|
|
||||||
|
|
||||||
if Rails.env.test?
|
response = do_request(request, uri)
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
elsif Rails.env.development?
|
|
||||||
client_cert = File.read(ENV['cert_path'])
|
|
||||||
client_key = File.read(ENV['key_path'])
|
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
client_cert = File.read(ENV['cert_path'])
|
|
||||||
client_key = File.read(ENV['key_path'])
|
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
|
|
@ -18,32 +18,7 @@ class Registrar
|
||||||
request.basic_auth(current_registrar_user.username,
|
request.basic_auth(current_registrar_user.username,
|
||||||
current_registrar_user.plain_text_password)
|
current_registrar_user.plain_text_password)
|
||||||
|
|
||||||
if Rails.env.test?
|
response = do_request(request, uri)
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
elsif Rails.env.development?
|
|
||||||
client_cert = File.read(ENV['cert_path'])
|
|
||||||
client_key = File.read(ENV['key_path'])
|
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
client_cert = File.read(ENV['cert_path'])
|
|
||||||
client_key = File.read(ENV['key_path'])
|
|
||||||
response = Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
|
||||||
cert: OpenSSL::X509::Certificate.new(client_cert),
|
|
||||||
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
|
|
||||||
http.request(request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
class Registrar
|
class Registrar
|
||||||
class TechContactsController < BulkChangeController
|
class TechContactsController < BulkChangeController
|
||||||
BASE_URL = URI.parse("#{ENV['repp_url']}domains/contacts").freeze
|
BASE_URL = URI.parse("#{ENV['repp_url']}domains/contacts").freeze
|
||||||
|
ACTIVE_TAB = :technical_contact
|
||||||
|
|
||||||
def update
|
def update
|
||||||
authorize! :manage, :repp
|
authorize! :manage, :repp
|
||||||
|
|
||||||
uri = BASE_URL
|
uri = BASE_URL
|
||||||
|
|
||||||
request = Net::HTTP::Patch.new(uri)
|
request = Net::HTTP::Patch.new(uri)
|
||||||
request.set_form_data(current_contact_id: params[:current_contact_id],
|
request.set_form_data(current_contact_id: params[:current_contact_id],
|
||||||
new_contact_id: params[:new_contact_id])
|
new_contact_id: params[:new_contact_id])
|
||||||
|
@ -15,25 +15,11 @@ class Registrar
|
||||||
|
|
||||||
response = do_request(request, uri)
|
response = do_request(request, uri)
|
||||||
|
|
||||||
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
start_notice = t('registrar.tech_contacts.process_request.replaced')
|
||||||
|
|
||||||
if response.code == '200'
|
process_response(response: response,
|
||||||
notices = [t('.replaced')]
|
start_notice: start_notice,
|
||||||
|
active_tab: ACTIVE_TAB)
|
||||||
notices << "#{t('.affected_domains')}: " \
|
|
||||||
"#{parsed_response[:data][:affected_domains].join(', ')}"
|
|
||||||
|
|
||||||
if parsed_response[:data][:skipped_domains]
|
|
||||||
notices << "#{t('.skipped_domains')}: " \
|
|
||||||
"#{parsed_response[:data][:skipped_domains].join(', ')}"
|
|
||||||
end
|
|
||||||
|
|
||||||
flash[:notice] = notices.join(', ')
|
|
||||||
redirect_to registrar_domains_url
|
|
||||||
else
|
|
||||||
@error = response.code == '404' ? 'Contact(s) not found' : parsed_response[:message]
|
|
||||||
render file: 'registrar/bulk_change/new', locals: { active_tab: :technical_contact }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue