Class: RecordStore::Provider
- Inherits:
-
Object
- Object
- RecordStore::Provider
show all
- Defined in:
- lib/record_store/provider.rb
Defined Under Namespace
Classes: DNSimple, DynECT
Class Method Summary
collapse
Class Method Details
.add(record) ⇒ Object
54
55
56
|
# File 'lib/record_store/provider.rb', line 54
def add(record)
raise NotImplementedError
end
|
.apply_changeset(changeset, stdout = $stdout) ⇒ Object
Applies changeset to provider
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/record_store/provider.rb', line 67
def apply_changeset(changeset, stdout = $stdout)
begin
stdout.puts "Applying #{changeset.additions.size} additions, #{changeset.removals.size} removals, & #{changeset.updates.size} updates..."
changeset.changes.each do |change|
case change.type
when :removal;
stdout.puts "Removing #{change.record}..."
remove(change.record, changeset.zone)
when :addition;
stdout.puts "Creating #{change.record}..."
add(change.record, changeset.zone)
when :update;
stdout.puts "Updating record with ID #{change.id} to #{change.record}..."
update(change.id, change.record, changeset.zone)
else
raise ArgumentError, "Unknown change type #{change.type.inspect}"
end
end
puts "\nPublished #{changeset.zone} changes to #{changeset.provider.to_s}\n"
end
end
|
.build_zone(zone_name:, config:) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/record_store/provider.rb', line 41
def build_zone(zone_name:, config:)
zone = Zone.new(name: zone_name)
zone.records = retrieve_current_records(zone: zone_name)
zone.config = config
zone
end
|
.freezable? ⇒ Boolean
108
109
110
|
# File 'lib/record_store/provider.rb', line 108
def freezable?
self.respond_to?(:freeze_zone)
end
|
.provider_for(zone_name) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/record_store/provider.rb', line 4
def provider_for(zone_name)
dns = Resolv::DNS.new(nameserver: ['8.8.8.8', '8.8.4.4'])
begin
ns_server = dns.getresource(zone_name, Resolv::DNS::Resource::IN::SOA).mname.to_s
rescue Resolv::ResolvError => e
abort "Domain doesn't exist"
end
case ns_server
when /dnsimple\.com\z/
'DNSimple'
when /dynect\.net\z/
'DynECT'
else
nil
end
end
|
.record_types ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/record_store/provider.rb', line 23
def record_types
Set.new([
'A',
'AAAA',
'ALIAS',
'CNAME',
'MX',
'NS',
'SPF',
'SRV',
'TXT',
])
end
|
.remove(record) ⇒ Object
58
59
60
|
# File 'lib/record_store/provider.rb', line 58
def remove(record)
raise NotImplementedError
end
|
.retrieve_current_records(zone:, stdout: $stdout) ⇒ Object
returns an array of Record objects that match the records which exist in the provider
50
51
52
|
# File 'lib/record_store/provider.rb', line 50
def retrieve_current_records(zone:, stdout: $stdout)
raise NotImplementedError
end
|
.secrets ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/record_store/provider.rb', line 96
def secrets
@secrets ||= if File.exists?(RecordStore.secrets_path)
JSON.parse(File.read(RecordStore.secrets_path))
else
raise "You don't have a secrets.json file set up!"
end
end
|
.supports_alias? ⇒ Boolean
37
38
39
|
# File 'lib/record_store/provider.rb', line 37
def supports_alias?
false
end
|
.thawable? ⇒ Boolean
104
105
106
|
# File 'lib/record_store/provider.rb', line 104
def thawable?
self.respond_to?(:thaw_zone)
end
|
.to_s ⇒ Object
112
113
114
|
# File 'lib/record_store/provider.rb', line 112
def to_s
self.name.demodulize
end
|
.update(id, record) ⇒ Object
62
63
64
|
# File 'lib/record_store/provider.rb', line 62
def update(id, record)
raise NotImplementedError
end
|
.zones ⇒ Object
Returns an array of the zones managed by provider as strings
92
93
94
|
# File 'lib/record_store/provider.rb', line 92
def zones
raise NotImplementedError
end
|