gandi_v5 0.3.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +56 -2
- data/.travis.yml +6 -1
- data/CHANGELOG.md +61 -0
- data/LICENSE.md +2 -6
- data/README.md +15 -9
- data/gandi_v5.gemspec +2 -2
- data/lib/gandi_v5.rb +40 -14
- data/lib/gandi_v5/data.rb +1 -2
- data/lib/gandi_v5/data/converter/integer.rb +26 -0
- data/lib/gandi_v5/domain.rb +13 -14
- data/lib/gandi_v5/email/forward.rb +2 -8
- data/lib/gandi_v5/email/mailbox.rb +57 -11
- data/lib/gandi_v5/email/slot.rb +11 -3
- data/lib/gandi_v5/live_dns.rb +0 -12
- data/lib/gandi_v5/live_dns/domain.rb +313 -29
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
- data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
- data/lib/gandi_v5/organization.rb +10 -0
- data/lib/gandi_v5/organization/customer.rb +90 -0
- data/lib/gandi_v5/sharing_space.rb +27 -0
- data/lib/gandi_v5/simple_hosting.rb +12 -0
- data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/spec/.rubocop.yml +56 -2
- data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
- data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
- data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
- data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
- data/spec/units/gandi_v5/domain_spec.rb +53 -43
- data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
- data/spec/units/gandi_v5/email/mailbox_spec.rb +119 -37
- data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
- data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
- data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
- data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
- data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
- data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
- data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
- data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
- data/spec/units/gandi_v5/organization_spec.rb +14 -0
- data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
- data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
- data/spec/units/gandi_v5_spec.rb +139 -30
- metadata +50 -31
- data/lib/gandi_v5/domain/sharing_space.rb +0 -21
- data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
- data/lib/gandi_v5/live_dns/record_set.rb +0 -79
- data/lib/gandi_v5/live_dns/zone.rb +0 -160
- data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
- data/spec/features/domain_spec.rb +0 -45
- data/spec/features/livedns_domain_spec.rb +0 -8
- data/spec/features/livedns_zone_spec.rb +0 -45
- data/spec/features/mailbox_spec.rb +0 -18
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
- data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
- data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
- data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
- data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
- data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
- data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class GandiV5
|
4
|
-
class LiveDNS
|
5
|
-
# Methods for handling record related requests in both
|
6
|
-
# GandiV5::LiveDNS::Domain and GandiV5::LiveDNS::Zone.
|
7
|
-
module HasZoneRecords
|
8
|
-
# @overload fetch_records()
|
9
|
-
# Fetch all records for this domain.
|
10
|
-
# @overload fetch_records(name)
|
11
|
-
# Fetch records for a name.
|
12
|
-
# @param name [String] the name to fetch records for.
|
13
|
-
# @overload fetch_records(name, type)
|
14
|
-
# Fetch records of a type for a name.
|
15
|
-
# @param name [String] the name to fetch records for.
|
16
|
-
# @param type [String] the record type to fetch.
|
17
|
-
# @return [Array<GandiV5::LiveDNS::RecordSet>]
|
18
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
19
|
-
def fetch_records(name = nil, type = nil)
|
20
|
-
GandiV5::LiveDNS.require_valid_record_type type if type
|
21
|
-
|
22
|
-
url_ = "#{url}/records"
|
23
|
-
url_ += "/#{CGI.escape name}" if name
|
24
|
-
url_ += "/#{CGI.escape type}" if type
|
25
|
-
|
26
|
-
_response, data = GandiV5.get url_
|
27
|
-
data = [data] unless data.is_a?(Array)
|
28
|
-
data.map { |item| GandiV5::LiveDNS::RecordSet.from_gandi item }
|
29
|
-
end
|
30
|
-
|
31
|
-
# @overload fetch_zone_lines()
|
32
|
-
# Fetch all records for this domain.
|
33
|
-
# @overload fetch_zone_lines(name)
|
34
|
-
# Fetch records for a name.
|
35
|
-
# @param name [String] the name to fetch records for.
|
36
|
-
# @overload fetch_zone_lines(name, type)
|
37
|
-
# Fetch records of a type for a name.
|
38
|
-
# @param name [String] the name to fetch records for.
|
39
|
-
# @param type [String] the record type to fetch.
|
40
|
-
# @return [String]
|
41
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
42
|
-
def fetch_zone_lines(name = nil, type = nil)
|
43
|
-
GandiV5::LiveDNS.require_valid_record_type type if type
|
44
|
-
|
45
|
-
url_ = "#{url}/records"
|
46
|
-
url_ += "/#{CGI.escape name}" if name
|
47
|
-
url_ += "/#{CGI.escape type}" if type
|
48
|
-
|
49
|
-
GandiV5.get(url_, accept: 'text/plain').last
|
50
|
-
end
|
51
|
-
|
52
|
-
# Add record to this domain.
|
53
|
-
# @param name [String]
|
54
|
-
# @param type [String]
|
55
|
-
# @param ttl [Integer]
|
56
|
-
# @param values [Array<String>]
|
57
|
-
# @return [String] The confirmation message from Gandi.
|
58
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
59
|
-
def add_record(name, type, ttl, *values)
|
60
|
-
GandiV5::LiveDNS.require_valid_record_type type
|
61
|
-
fail ArgumentError, 'ttl must be positive and non-zero' unless ttl.positive?
|
62
|
-
fail ArgumentError, 'there must be at least one value' if values.none?
|
63
|
-
|
64
|
-
body = {
|
65
|
-
rrset_name: name,
|
66
|
-
rrset_type: type,
|
67
|
-
rrset_ttl: ttl,
|
68
|
-
rrset_values: values
|
69
|
-
}.to_json
|
70
|
-
_response, data = GandiV5.post "#{url}/records", body
|
71
|
-
data['message']
|
72
|
-
end
|
73
|
-
|
74
|
-
# @overload delete_records()
|
75
|
-
# Delete all records for this domain.
|
76
|
-
# @overload delete_records(name)
|
77
|
-
# Delete records for a name.
|
78
|
-
# @param name [String] the name to delete records for.
|
79
|
-
# @overload delete_records(name, type)
|
80
|
-
# Delete records of a type for a name.
|
81
|
-
# @param name [String] the name to delete records for.
|
82
|
-
# @param type [String] the record type to delete.
|
83
|
-
# @return [nil]
|
84
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
85
|
-
def delete_records(name = nil, type = nil)
|
86
|
-
GandiV5::LiveDNS.require_valid_record_type(type) if type
|
87
|
-
|
88
|
-
url_ = "#{url}/records"
|
89
|
-
url_ += "/#{CGI.escape name}" if name
|
90
|
-
url_ += "/#{CGI.escape type}" if type
|
91
|
-
GandiV5.delete(url_).last
|
92
|
-
end
|
93
|
-
|
94
|
-
# Replace all records for this domain.
|
95
|
-
# @param records
|
96
|
-
# [Array<Hash<:name, :type => String, :ttl => Integer, :values => Array<String>>>]
|
97
|
-
# the records to add.
|
98
|
-
# @param text [String] zone file lines to replace the records with.
|
99
|
-
# @return [String] The confirmation message from Gandi.
|
100
|
-
# @raise [ArgumentError] if neither/both of records & test are passed.
|
101
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
102
|
-
def replace_records(records: nil, text: nil)
|
103
|
-
unless [records, text].count(&:nil?).eql?(1)
|
104
|
-
fail ArgumentError, 'you must pass ONE of records: or text:'
|
105
|
-
end
|
106
|
-
|
107
|
-
if records
|
108
|
-
body = {
|
109
|
-
items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
|
110
|
-
}.to_json
|
111
|
-
_response, data = GandiV5.put "#{url}/records", body
|
112
|
-
elsif text
|
113
|
-
_response, data = GandiV5.put "#{url}/records", text, 'content-type': 'text/plain'
|
114
|
-
end
|
115
|
-
data['message']
|
116
|
-
end
|
117
|
-
|
118
|
-
# @override replace_records_for(name, records)
|
119
|
-
# Replace records for a name in this domain.
|
120
|
-
# @param name [String]
|
121
|
-
# @param records
|
122
|
-
# [Array<Hash<type: String, ttl: Integer, values: Array<String>>>]
|
123
|
-
# the records to add.
|
124
|
-
# @override replace_records_for(name, values, type: nil, ttl: nil)
|
125
|
-
# Replace records for a name in this domain.
|
126
|
-
# @param name [String]
|
127
|
-
# @param type [String] the record type.
|
128
|
-
# @param ttl [Integer] the TTL to set for the record.
|
129
|
-
# @param values [Array<String>] the values to set for the record.
|
130
|
-
# @raise [ArgumentError] if ttl is present and type is absent.
|
131
|
-
# @return [String] The confirmation message from Gandi.
|
132
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
133
|
-
def replace_records_for(name, records, type: nil, ttl: nil)
|
134
|
-
fail ArgumentError, 'missing keyword: type' if ttl && type.nil?
|
135
|
-
|
136
|
-
if type
|
137
|
-
GandiV5::LiveDNS.require_valid_record_type type
|
138
|
-
body = { rrset_values: records, rrset_ttl: ttl }
|
139
|
-
# body[:rrset_ttl] = ttl if ttl
|
140
|
-
_response, data = GandiV5.put "#{url}/records/#{name}/#{type}", body.to_json
|
141
|
-
|
142
|
-
else
|
143
|
-
body = {
|
144
|
-
items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
|
145
|
-
}
|
146
|
-
_response, data = GandiV5.put "#{url}/records/#{name}", body.to_json
|
147
|
-
end
|
148
|
-
|
149
|
-
data['message']
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class GandiV5
|
4
|
-
class LiveDNS
|
5
|
-
# A record set which comes from either a domain or zone.
|
6
|
-
# @!attribute [r] type
|
7
|
-
# @return [String]
|
8
|
-
# @!attribute [r] ttl
|
9
|
-
# @return [Integer]
|
10
|
-
# @!attribute [r] name
|
11
|
-
# @return [String]
|
12
|
-
# @!attribute [r] values
|
13
|
-
# @return [Array<String>]
|
14
|
-
class RecordSet
|
15
|
-
include GandiV5::Data
|
16
|
-
|
17
|
-
member :type, gandi_key: 'rrset_type'
|
18
|
-
member :ttl, gandi_key: 'rrset_ttl'
|
19
|
-
member :name, gandi_key: 'rrset_name'
|
20
|
-
member :values, gandi_key: 'rrset_values'
|
21
|
-
|
22
|
-
# Generate zone file lines for the record.
|
23
|
-
# @return [String]
|
24
|
-
def to_s
|
25
|
-
values.map do |value|
|
26
|
-
"#{name}\t#{ttl}\tIN\t#{type}\t#{value}"
|
27
|
-
end.join("\n")
|
28
|
-
end
|
29
|
-
|
30
|
-
GandiV5::LiveDNS::RECORD_TYPES.each do |t|
|
31
|
-
# Check the record type.
|
32
|
-
# @return [Boolean]
|
33
|
-
define_method "#{t.downcase}?" do
|
34
|
-
type.eql?(t)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Check the TTL's value in seconds.
|
39
|
-
# @param number [Integer] the number of second(s) to check against.
|
40
|
-
# @return [Boolean]
|
41
|
-
def second?(number = 1)
|
42
|
-
ttl == number
|
43
|
-
end
|
44
|
-
alias seconds? second?
|
45
|
-
|
46
|
-
# Check the TTL's value in minutes.
|
47
|
-
# @param number [Integer] the number of minute(s) to check against.
|
48
|
-
# @return [Boolean]
|
49
|
-
def minute?(number = 1)
|
50
|
-
ttl == number * 60
|
51
|
-
end
|
52
|
-
alias minutes? minute?
|
53
|
-
|
54
|
-
# Check the TTL's value in hours.
|
55
|
-
# @param number [Integer] the number of hour(s) to check against.
|
56
|
-
# @return [Boolean]
|
57
|
-
def hour?(number = 1)
|
58
|
-
ttl == number * 3_600
|
59
|
-
end
|
60
|
-
alias hours? hour?
|
61
|
-
|
62
|
-
# Check the TTL's value in days.
|
63
|
-
# @param number [Integer] the number of day(s) to check against.
|
64
|
-
# @return [Boolean]
|
65
|
-
def day?(number = 1)
|
66
|
-
ttl == number * 86_400
|
67
|
-
end
|
68
|
-
alias days? day?
|
69
|
-
|
70
|
-
# Check the TTL's value in weeks.
|
71
|
-
# @param number [Integer] the number of week(s) to check against.
|
72
|
-
# @return [Boolean]
|
73
|
-
def week?(number = 1)
|
74
|
-
ttl == number * 604_800
|
75
|
-
end
|
76
|
-
alias weeks? day?
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,160 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class GandiV5
|
4
|
-
class LiveDNS
|
5
|
-
# A zone within the LiveDNS system.
|
6
|
-
# Zones can be used by any number of domains.
|
7
|
-
# @!attribute [r] uuid
|
8
|
-
# @return [String]
|
9
|
-
# @!attribute [r] name
|
10
|
-
# @return [String]
|
11
|
-
# @!attribute [r] sharing_uuid
|
12
|
-
# @return [String]
|
13
|
-
# @!attribute [r] soa_retry
|
14
|
-
# @return [Integer] retry period, as reported in SOA record.
|
15
|
-
# @!attribute [r] soa_minimum
|
16
|
-
# @return [Integer] minimum and negative TTL, as reported in SOA record.
|
17
|
-
# @!attribute [r] soa_refresh
|
18
|
-
# @return [Integer] refresh period, as reported in SOA record.
|
19
|
-
# @!attribute [r] soa_expire
|
20
|
-
# @return [Integer] expire period, as reported in SOA record.
|
21
|
-
# @!attribute [r] soa_serial
|
22
|
-
# @return [Integer] serial number, as reported in SOA record.
|
23
|
-
# @!attribute [r] soa_email
|
24
|
-
# @return [String] admin email address, as reported in SOA record.
|
25
|
-
# @!attribute [r] soa_primary_ns
|
26
|
-
# @return [String] primary name server, as reported in SOA record.
|
27
|
-
class Zone
|
28
|
-
include GandiV5::Data
|
29
|
-
include GandiV5::LiveDNS::HasZoneRecords
|
30
|
-
|
31
|
-
members :uuid, :name
|
32
|
-
member :sharing_uuid, gandi_key: 'sharing_id'
|
33
|
-
member :soa_retry, gandi_key: 'retry'
|
34
|
-
member :soa_minimum, gandi_key: 'minimum'
|
35
|
-
member :soa_refresh, gandi_key: 'refresh'
|
36
|
-
member :soa_expire, gandi_key: 'expire'
|
37
|
-
member :soa_serial, gandi_key: 'serial'
|
38
|
-
member :soa_email, gandi_key: 'email'
|
39
|
-
member :soa_primary_ns, gandi_key: 'primary_ns'
|
40
|
-
|
41
|
-
alias zone_uuid uuid
|
42
|
-
|
43
|
-
# Generate SOA record for the zone
|
44
|
-
# @return [String]
|
45
|
-
def to_s
|
46
|
-
"@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
|
47
|
-
"\t#{soa_serial}\t;Serial\n" \
|
48
|
-
"\t#{soa_refresh}\t\t;Refresh\n" \
|
49
|
-
"\t#{soa_retry}\t\t;Retry\n" \
|
50
|
-
"\t#{soa_expire}\t\t;Expire\n" \
|
51
|
-
"\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
|
52
|
-
')'
|
53
|
-
end
|
54
|
-
|
55
|
-
# List the domains that use this zone.
|
56
|
-
# @return [Array<String>] The FQDNs.
|
57
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
58
|
-
def list_domains
|
59
|
-
_response, data = GandiV5.get "#{url}/domains"
|
60
|
-
data.map { |item| item['fqdn'] }
|
61
|
-
end
|
62
|
-
|
63
|
-
# Attach domain to this zone.
|
64
|
-
# @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
|
65
|
-
# that should start using this zone.
|
66
|
-
# @return [String] The confirmation message from Gandi.
|
67
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
68
|
-
def attach_domain(fqdn)
|
69
|
-
fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
|
70
|
-
_resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
|
71
|
-
data['message']
|
72
|
-
end
|
73
|
-
|
74
|
-
# Get snapshot UUIDs for this zone from Gandi.
|
75
|
-
# @return [Hash{String => Time}] Mapping snapshot UUID to time made.
|
76
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
77
|
-
def snapshots
|
78
|
-
GandiV5::LiveDNS::Zone::Snapshot.list uuid
|
79
|
-
end
|
80
|
-
|
81
|
-
# Get snapshot from Gandi.
|
82
|
-
# @param uuid [String] the UUID of the snapshot to fetch.
|
83
|
-
# @return [GandiV5::LiveDNS::Zone::Snapshot]
|
84
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
85
|
-
def snapshot(uuid)
|
86
|
-
GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
|
87
|
-
end
|
88
|
-
|
89
|
-
# Take a snapshot of this zone.
|
90
|
-
# @return [GandiV5::LiveDNS::Zone::Snapshot]
|
91
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
92
|
-
def take_snapshot
|
93
|
-
_response, data = GandiV5.post "#{url}/snapshots"
|
94
|
-
snapshot data['uuid']
|
95
|
-
end
|
96
|
-
|
97
|
-
# Update this zone.
|
98
|
-
# @param name [String, #to_s] new name for the zone.
|
99
|
-
# @return [String] The confirmation message from Gandi.
|
100
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
101
|
-
def update(name:)
|
102
|
-
_response, data = GandiV5.patch url, { name: name }.to_json
|
103
|
-
self.name = name
|
104
|
-
data['message']
|
105
|
-
end
|
106
|
-
|
107
|
-
# Delete this zone from Gandi.
|
108
|
-
# @return [nil]
|
109
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
110
|
-
def delete
|
111
|
-
GandiV5.delete url
|
112
|
-
end
|
113
|
-
|
114
|
-
# Create a new zone.
|
115
|
-
# @param name [String] the name for the created zone.
|
116
|
-
# @param sharing_id [String] the UUID of the account to ceate the zone under.
|
117
|
-
# @return [GandiV5::LiveDNS::Zone] The created zone.
|
118
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
119
|
-
def self.create(name, sharing_id: nil)
|
120
|
-
params = sharing_id ? { sharing_id: sharing_id } : {}
|
121
|
-
|
122
|
-
response, _data = GandiV5.post(
|
123
|
-
url,
|
124
|
-
{ name: name }.to_json,
|
125
|
-
params: params
|
126
|
-
)
|
127
|
-
|
128
|
-
fetch response.headers[:location].split('/').last
|
129
|
-
end
|
130
|
-
|
131
|
-
# List the zones.
|
132
|
-
# @return [Array<GandiV5::LiveDNS::Zone>]
|
133
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
134
|
-
def self.list
|
135
|
-
_response, data = GandiV5.get url
|
136
|
-
data.map { |item| from_gandi item }
|
137
|
-
end
|
138
|
-
|
139
|
-
# Get a zone from Gandi.
|
140
|
-
# @param uuid [String, #to_s] the UUID of the zone to fetch.
|
141
|
-
# @return [GandiV5::LiveDNS::Zone]
|
142
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
143
|
-
def self.fetch(uuid)
|
144
|
-
_response, data = GandiV5.get url(uuid)
|
145
|
-
from_gandi data
|
146
|
-
end
|
147
|
-
|
148
|
-
private
|
149
|
-
|
150
|
-
def url
|
151
|
-
"#{BASE}zones/#{CGI.escape uuid}"
|
152
|
-
end
|
153
|
-
|
154
|
-
def self.url(uuid = nil)
|
155
|
-
BASE + (uuid ? "zones/#{CGI.escape(uuid)}" : 'zones')
|
156
|
-
end
|
157
|
-
private_class_method :url
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class GandiV5
|
4
|
-
class LiveDNS
|
5
|
-
class Zone
|
6
|
-
# A snapshot (backup) of a zone.
|
7
|
-
# @!attribute [r] uuid
|
8
|
-
# @return [String]
|
9
|
-
# @!attribute [r] zone_uuid
|
10
|
-
# @return [String]
|
11
|
-
# @!attribute [r] created_at
|
12
|
-
# @return [Time]
|
13
|
-
# @!attribute [r] records
|
14
|
-
# @return [Array<GandiV5::LiveDNS::RecordSet>]
|
15
|
-
class Snapshot
|
16
|
-
include GandiV5::Data
|
17
|
-
|
18
|
-
members :uuid, :zone_uuid
|
19
|
-
member :created_at, gandi_key: 'date_created', converter: GandiV5::Data::Converter::Time
|
20
|
-
member(
|
21
|
-
:records,
|
22
|
-
gandi_key: 'zone_data',
|
23
|
-
converter: GandiV5::LiveDNS::RecordSet,
|
24
|
-
array: true
|
25
|
-
)
|
26
|
-
|
27
|
-
alias snapshot_uuid uuid
|
28
|
-
|
29
|
-
# Delete this snapshot.
|
30
|
-
# @return [String] The confirmation message from Gandi.
|
31
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
32
|
-
def delete
|
33
|
-
_response, data = GandiV5.delete url
|
34
|
-
data['message']
|
35
|
-
end
|
36
|
-
|
37
|
-
# @see GandiV5::LiveDNS::Zone.fetch
|
38
|
-
def fetch_zone
|
39
|
-
GandiV5::LiveDNS::Zone.fetch zone_uuid
|
40
|
-
end
|
41
|
-
|
42
|
-
# The snapshot's zone (fetching from Gandi if required).
|
43
|
-
# @return [GandiV5::LiveDNS::Zone]
|
44
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
45
|
-
def zone
|
46
|
-
@zone ||= fetch_zone
|
47
|
-
end
|
48
|
-
|
49
|
-
# Get snapshot UUIDs for this zone from Gandi.
|
50
|
-
# @return [Hash{String => Time}] Mapping UUID to time made.
|
51
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
52
|
-
def self.list(zone_uuid)
|
53
|
-
_response, data = GandiV5.get url(zone_uuid)
|
54
|
-
Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Get snapshot from Gandi.
|
58
|
-
# @param zone_uuid [String, #to_s] the UUID of the zone the snapshot was made of.
|
59
|
-
# @param snapshot_uuid [String, #to_s] the UUID of the snapshot to fetch.
|
60
|
-
# @return [GandiV5::LiveDNS::Zone::Snapshot]
|
61
|
-
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
62
|
-
def self.fetch(zone_uuid, snapshot_uuid)
|
63
|
-
_response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
|
64
|
-
from_gandi data
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def url
|
70
|
-
"#{BASE}zones/#{CGI.escape zone_uuid}/snapshots/#{CGI.escape uuid}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.url(zone_uuid, snapshot_uuid = nil)
|
74
|
-
"#{BASE}zones/#{CGI.escape zone_uuid}/snapshots" +
|
75
|
-
(snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
|
76
|
-
end
|
77
|
-
private_class_method :url
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|