mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Move webclient cert appending to separate method
This commit is contained in:
parent
aac7a63487
commit
aff8e025bc
1 changed files with 14 additions and 32 deletions
|
@ -2,39 +2,21 @@ class ReppApi
|
||||||
def self.bulk_renew(domains, period, registrar)
|
def self.bulk_renew(domains, period, registrar)
|
||||||
payload = { domains: domains, renew_period: period }
|
payload = { domains: domains, renew_period: period }
|
||||||
uri = URI.parse("#{ENV['repp_url']}domains/renew/bulk")
|
uri = URI.parse("#{ENV['repp_url']}domains/renew/bulk")
|
||||||
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
||||||
request.body = payload.to_json
|
req.body = payload.to_json
|
||||||
request.basic_auth(registrar.username, registrar.plain_text_password)
|
|
||||||
|
|
||||||
if Rails.env.test?
|
ReppApi.request(req, uri, registrar: registrar).body
|
||||||
response =
|
end
|
||||||
Net::HTTP.start(uri.hostname, uri.port,
|
|
||||||
use_ssl: (uri.scheme == 'https'),
|
def self.request(request, uri, registrar:)
|
||||||
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
request.basic_auth(registrar.username, registrar.plain_text_password) if registrar
|
||||||
http.request(request)
|
http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https'))
|
||||||
end
|
unless Rails.env.test?
|
||||||
elsif Rails.env.development?
|
http.cert = OpenSSL::X509::Certificate.new(File.read(ENV['cert_path']))
|
||||||
client_cert = File.read(ENV['cert_path'])
|
http.key = OpenSSL::PKey::RSA.new(File.read(ENV['key_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
|
end
|
||||||
response.body
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development? || Rails.env.test?
|
||||||
|
|
||||||
|
http.request(request)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue