hetzner rdns: allow 404
This commit is contained in:
parent
a0900306e2
commit
4a5caddd23
@ -24,12 +24,12 @@ module Lxc
|
|||||||
def put(path, params={})
|
def put(path, params={})
|
||||||
req = Net::HTTP::Put.new(uri_for(path))
|
req = Net::HTTP::Put.new(uri_for(path))
|
||||||
req.set_form_data(params)
|
req.set_form_data(params)
|
||||||
resp = perform_request(req)
|
resp = perform_request(req, allow_404)
|
||||||
JSON.parse(resp.body)
|
JSON.parse(resp.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(path)
|
def delete(path, allow_404: false)
|
||||||
perform_request(Net::HTTP::Delete.new(uri_for(path)))
|
perform_request(Net::HTTP::Delete.new(uri_for(path)), allow_404: allow_404)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -39,12 +39,12 @@ module Lxc
|
|||||||
u
|
u
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_request(req)
|
def perform_request(req, allow_404: false)
|
||||||
req.basic_auth(@user, @password)
|
req.basic_auth(@user, @password)
|
||||||
resp = Net::HTTP.start(BASE_URI.hostname, BASE_URI.port, use_ssl: true) do |http|
|
resp = Net::HTTP.start(BASE_URI.hostname, BASE_URI.port, use_ssl: true) do |http|
|
||||||
http.request(req)
|
http.request(req)
|
||||||
end
|
end
|
||||||
if resp.code.start_with? "2"
|
if resp.code.start_with?("2") || (allow_404 && resp.code == "404")
|
||||||
return resp
|
return resp
|
||||||
else
|
else
|
||||||
raise StandardError.new("failed to perform request for '#{req.path}': #{resp.code} - #{resp.body}")
|
raise StandardError.new("failed to perform request for '#{req.path}': #{resp.code} - #{resp.body}")
|
||||||
|
@ -32,7 +32,7 @@ def update_hetzner_rdns6(user, password, domain, subnet, network)
|
|||||||
end
|
end
|
||||||
records.each do |ip, ptr|
|
records.each do |ip, ptr|
|
||||||
puts "delete ptr: #{ip} -> #{ptr}"
|
puts "delete ptr: #{ip} -> #{ptr}"
|
||||||
api.delete("/rnds/#{ip}")
|
api.delete("/rnds/#{ip}", allow_404: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user