gateway/app/jobs/dns_update_job.rb

31 lines
756 B
Ruby
Raw Normal View History

2022-03-31 16:03:11 +02:00
require "dnsimple"
class DnsUpdateJob < ApplicationJob
queue_as :default
2022-03-31 19:48:14 +02:00
def client
@client ||= Dnsimple::Client.new(access_token: Rails.application.credentials.simple_token)
end
def simple_id
Rails.application.credentials.simple_id
end
def my_ip
2022-04-02 20:49:32 +02:00
HTTParty.get("https://jsonip.com/")["ip"]
2022-03-31 19:48:14 +02:00
end
def find_record(name , host)
zones = client.zones.list_zone_records(simple_id, host, filter: { type: 'A' , name: name })
zones.data.first
end
2022-04-02 20:49:32 +02:00
def same_ip
my_ip == find_record("gateway" , "hubfeenix.fi").content
end
2022-03-31 19:48:14 +02:00
def update_ip
record = find_record("gateway" , "hubfeenix.fi")
client.zones.update_zone_record(simple_id,"hubfeenix.fi", record.id , content: my_ip)
end
2022-03-31 16:03:11 +02:00
def perform(*args)
end
end