mirror of
https://github.com/internetee/registry.git
synced 2025-06-14 00:24:44 +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
|
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 }
|
||||||
token = Base64.urlsafe_encode64("#{registrar.username}:#{registrar.plain_text_password}")
|
uri = URI.parse("#{ENV['repp_url']}domains/renew/bulk")
|
||||||
headers = { Authorization: "Basic #{token}" }
|
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)
|
if Rails.env.test?
|
||||||
rescue RestClient::ExceptionWithResponse => e
|
response =
|
||||||
e.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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue