Class: Rubber::Dns::Nettica
- Inherits:
-
Base
- Object
- Base
- Rubber::Dns::Nettica
show all
- Defined in:
- lib/rubber/dns/nettica.rb
Instance Attribute Summary
Attributes inherited from Base
#env, #provider_env, #provider_name
Instance Method Summary
collapse
Methods inherited from Base
#destroy, #host_records_equal?, #setup_opts, #up_to_date, #update
Constructor Details
#initialize(env) ⇒ Nettica
Returns a new instance of Nettica.
7
8
9
10
|
# File 'lib/rubber/dns/nettica.rb', line 7
def initialize(env)
super(env, "nettica")
@client = ::Nettica::Client.new(provider_env.user, provider_env.password)
end
|
Instance Method Details
#check_status(response) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/rubber/dns/nettica.rb', line 12
def check_status(response)
code = case
when response.respond_to?(:status)
response.status
when response.respond_to?(:result)
response.result.status
else
500
end
if code < 200 || code > 299
msg = "Failed to access nettica api (http_status=#{code})"
msg += ", check dns_providers.nettica.user/password in rubber.yml" if code == 401
raise msg
end
return response
end
|
#create_host_record(opts = {}) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/rubber/dns/nettica.rb', line 56
def create_host_record(opts = {})
opts = setup_opts(opts, [:host, :data, :domain, :type, :ttl])
find_or_create_zone(opts[:domain])
record = opts_to_record(opts)
check_status @client.add_record(record)
end
|
#destroy_host_record(opts = {}) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/rubber/dns/nettica.rb', line 63
def destroy_host_record(opts = {})
find_host_records(opts).each do |h|
record = opts_to_record(h)
check_status @client.delete_record(record)
end
end
|
#find_host_records(opts = {}) ⇒ Object
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
|
# File 'lib/rubber/dns/nettica.rb', line 29
def find_host_records(opts = {})
opts = setup_opts(opts, [:host, :domain])
result = []
hn = opts[:host]
ht = opts[:type]
hd = opts[:data]
domain_info = find_or_create_zone(opts[:domain])
domain_info.record.each do |h|
keep = true
if hn && h.hostName != hn && hn != '*'
keep = false
end
if ht && h.recordType != ht && ht != '*'
keep = false
end
if hd && h.data != hd
keep = false
end
result << record_to_opts(h) if keep
end
return result
end
|
#update_host_record(old_opts = {}, new_opts = {}) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/rubber/dns/nettica.rb', line 70
def update_host_record(old_opts = {}, new_opts = {})
old_opts = setup_opts(old_opts, [:host, :domain])
new_opts = setup_opts(new_opts.merge(:no_defaults =>true), [])
find_host_records(old_opts).each do |h|
old_record = opts_to_record(h)
new_record = opts_to_record(h.merge(new_opts))
check_status @client.update_record(old_record, new_record)
end
end
|