-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.rb
59 lines (45 loc) · 1.2 KB
/
dns.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'pry'
require 'fog'
require 'yaml'
require_relative 'provider'
require_relative 'providers/dnsimple'
class DNS
attr_reader :providers
def initialize(*providers)
@providers = providers
end
def update!
domains.each do |domain|
domain, records = domain.first, domain.last
puts "Updating records for #{domain}..."
records.each { |record| update_record record, domain }
end
end
private
def update_record(record, domain)
name = record.first
type = record.last.fetch('type')
content = record.last.fetch('content')
providers.each do |provider|
update_record_for_provider(provider, domain, name, type, content)
end
end
# TODO: ewwwwww dat argument list
def update_record_for_provider(provider, domain, name, type, content)
puts "Updating #{name} #{type} for #{provider}"
provider.create_or_update_record(domain, name, type, content)
end
def domains
@_domains ||= config
end
def config
domains = {}
Dir.glob('domains/*.yml').each do |file|
domains[domain_from_filename(file)] = YAML.load_file file
end
domains
end
def domain_from_filename(file)
file.split('/').last.gsub(/\.yml/, '')
end
end