Use plain Net::HTTP for bulk renew, include webclient certs

This commit is contained in:
Karl Erik Õunapuu 2020-12-21 16:49:39 +02:00
parent e763411e5c
commit aac7a63487
No known key found for this signature in database
GPG key ID: C9DD647298A34764

View file

@ -1,11 +1,40 @@
class ReppApi
def self.bulk_renew(domains, period, registrar)
payload = { domains: domains, renew_period: period }
token = Base64.urlsafe_encode64("#{registrar.username}:#{registrar.plain_text_password}")
headers = { Authorization: "Basic #{token}" }
uri = URI.parse("#{ENV['repp_url']}domains/renew/bulk")
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = payload.to_json
request.basic_auth(registrar.username, registrar.plain_text_password)
RestClient.post("#{ENV['repp_url']}domains/renew/bulk", payload, headers)
rescue RestClient::ExceptionWithResponse => e
e.response
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.body
end
end