Class: RecordStore::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/record_store/provider.rb

Direct Known Subclasses

DNSimple, DynECT, GoogleCloudDNS, NS1, OracleCloudDNS

Defined Under Namespace

Classes: DNSimple, DynECT, Error, GoogleCloudDNS, NS1, OracleCloudDNS, UnparseableBodyError

Class Method Summary collapse

Class Method Details

.apply_changeset(changeset, stdout = $stdout) ⇒ Object

Applies changeset to provider



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/record_store/provider.rb', line 79

def apply_changeset(changeset, stdout = $stdout)
  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
end

.build_zone(zone_name:, config:) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/record_store/provider.rb', line 65

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

.empty_non_terminal_over_wildcard?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/record_store/provider.rb', line 61

def empty_non_terminal_over_wildcard?
  true
end

.freezable?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/record_store/provider.rb', line 114

def freezable?
  respond_to?(:freeze_zone)
end

.provider_for(object) ⇒ Object



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
# File 'lib/record_store/provider.rb', line 10

def provider_for(object)
  lookup_error = false
  ns_server =
    case object
    when Record::NS
      object.nsdname.chomp('.')
    else
      begin
        master_nameserver_for(object)
      rescue Resolv::ResolvError
        $stderr.puts "Domain doesn't exist (#{object})"
        lookup_error = true
      end
    end
  return if lookup_error

  case ns_server
  when /\.dnsimple\.com\z/
    'DNSimple'
  when /\.dynect\.net\z/
    'DynECT'
  when /\.googledomains\.com\z/
    'GoogleCloudDNS'
  when /\.nsone\.net\z/,
       /\.ns1global\.net\z/,
       /\.ns1global\.org\z/
    'NS1'
  when /\.oraclecloud\.net\z/
    'OracleCloudDNS'
  end
end

.record_typesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/record_store/provider.rb', line 42

def record_types
  Set.new([
    'A',
    'AAAA',
    'ALIAS',
    'CAA',
    'CNAME',
    'MX',
    'NS',
    'SPF',
    'SRV',
    'TXT',
  ])
end

.retrieve_current_records(zone:, stdout: $stdout) ⇒ Object

returns an array of Record objects that match the records which exist in the provider

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/record_store/provider.rb', line 74

def retrieve_current_records(zone:, stdout: $stdout)
  raise NotImplementedError
end

.secretsObject



102
103
104
105
106
107
108
# File 'lib/record_store/provider.rb', line 102

def secrets
  @secrets ||= if File.exist?(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

Returns:

  • (Boolean)


57
58
59
# File 'lib/record_store/provider.rb', line 57

def supports_alias?
  false
end

.thawable?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/record_store/provider.rb', line 110

def thawable?
  respond_to?(:thaw_zone)
end

.to_sObject



118
119
120
# File 'lib/record_store/provider.rb', line 118

def to_s
  name.demodulize
end

.zonesObject

Returns an array of the zones managed by provider as strings

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/record_store/provider.rb', line 98

def zones
  raise NotImplementedError
end