mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +02:00
Refactor bulk_change & tech_contact controllers code to be more reusable
This commit is contained in:
parent
f6a2d91d61
commit
fbad7b00b2
2 changed files with 34 additions and 27 deletions
|
@ -26,6 +26,36 @@ class Registrar
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def do_request(request, uri)
|
||||||
|
if Rails.env.test?
|
||||||
|
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
|
||||||
|
response
|
||||||
|
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
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
class Registrar
|
class Registrar
|
||||||
class TechContactsController < BulkChangeController
|
class TechContactsController < BulkChangeController
|
||||||
|
BASE_URL = URI.parse("#{ENV['repp_url']}domains/contacts").freeze
|
||||||
|
|
||||||
def update
|
def update
|
||||||
authorize! :manage, :repp
|
authorize! :manage, :repp
|
||||||
|
|
||||||
uri = URI.parse("#{ENV['repp_url']}domains/contacts")
|
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],
|
||||||
|
@ -11,32 +13,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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue