mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
Use plain Net::HTTP for bulk renew, include webclient certs
This commit is contained in:
parent
e763411e5c
commit
aac7a63487
1 changed files with 34 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue