This commit introduces a new prog that will periodically check the ip addresses of globally blocked dnsnames. This way, the list will be kept fresh and the new VMs will be provisioned with the new list. In future, we might introduce a system here to trigger a firewall rule update for existing VMs as well.
28 lines
720 B
Ruby
28 lines
720 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "socket"
|
|
require "open-uri"
|
|
require "net/http"
|
|
class Prog::ResolveGloballyBlockedDnsnames < Prog::Base
|
|
label def wait
|
|
GloballyBlockedDnsname.each do |globally_blocked_dnsname|
|
|
dns_name = globally_blocked_dnsname.dns_name
|
|
|
|
begin
|
|
addr_info = Socket.getaddrinfo(dns_name, nil)
|
|
rescue SocketError
|
|
Clog.emit("Failed to resolve blocked dns name") { {dns_name: dns_name} }
|
|
next
|
|
end
|
|
|
|
ip_list = addr_info.map do |info|
|
|
info[3]
|
|
end.uniq
|
|
|
|
globally_blocked_dnsname.update(ip_list: Sequel.lit("ARRAY[#{ip_list.map { |ip| "'#{ip}'::inet" }.join(",")}]"), last_check_at: Time.now)
|
|
end
|
|
|
|
nap 60 * 60
|
|
end
|
|
end
|