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
|
# File 'lib/amazon_static_site/client/cloudflare.rb', line 4
def configure_dns
in_cloudflare do |connection|
account_id = cloudflare_account_id(connection)
puts " find or create #{domain_for_cloudflare} in account: #{account_id}"
zone = fetch_zone(connection)
unless zone
connection.zones.create(domain_for_cloudflare, { id: account_id })
zone = fetch_zone(connection)
end
puts "Creating DNS records:".yellow
puts " - #{service.s3.s3_primary}"
puts " - #{service.s3.s3_secondary}"
puts "Generating ...".yellow
zone.dns_records.to_a.each do |record|
if record.type == 'CNAME' && (record.name == config.domain.secondary || record.name == config.domain.primary)
record.delete
end
end
www = zone.dns_records.create('CNAME', 'www', service.s3.s3_primary, proxied: true)
non_www = zone.dns_records.create('CNAME', '.', service.s3.s3_secondary, proxied: true)
zone_info = []
zone_info << [
zone.value[:name],
zone.value[:name_servers].join('; '),
zone.value[:status]
]
puts
puts "Domain settings (you need to chang nameservers for your domain)".green
puts Terminal::Table.new(headings: ["Name", "Name Servers", "Status"], rows: zone_info)
puts
puts "DNS settings".green
summary_info = []
[www, non_www].each do |e|
summary_info << [ e.type, e.name, ' => ', e.content, e.proxied ]
end
puts Terminal::Table.new(headings: ['Type', 'Name', nil, 'Destination', 'Proxied'], rows: summary_info)
puts "=> Done!".green
end
end
|