gandi_v5 0.2.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +13 -3
  4. data/.travis.yml +15 -1
  5. data/CHANGELOG.md +63 -0
  6. data/FUNDING.yml +10 -0
  7. data/LICENSE.md +2 -6
  8. data/README.md +16 -21
  9. data/gandi_v5.gemspec +3 -2
  10. data/lib/gandi_v5.rb +64 -24
  11. data/lib/gandi_v5/billing.rb +0 -2
  12. data/lib/gandi_v5/billing/info.rb +0 -2
  13. data/lib/gandi_v5/data.rb +1 -4
  14. data/lib/gandi_v5/data/converter.rb +0 -4
  15. data/lib/gandi_v5/data/converter/integer.rb +26 -0
  16. data/lib/gandi_v5/domain.rb +167 -28
  17. data/lib/gandi_v5/domain/availability.rb +0 -3
  18. data/lib/gandi_v5/domain/availability/product.rb +0 -3
  19. data/lib/gandi_v5/domain/live_dns.rb +42 -0
  20. data/lib/gandi_v5/domain/renewal_information.rb +0 -3
  21. data/lib/gandi_v5/domain/sharing_space.rb +10 -2
  22. data/lib/gandi_v5/email.rb +0 -4
  23. data/lib/gandi_v5/email/forward.rb +102 -0
  24. data/lib/gandi_v5/email/mailbox.rb +57 -13
  25. data/lib/gandi_v5/email/slot.rb +11 -3
  26. data/lib/gandi_v5/error.rb +0 -2
  27. data/lib/gandi_v5/live_dns.rb +0 -16
  28. data/lib/gandi_v5/live_dns/domain.rb +221 -80
  29. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
  30. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  31. data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
  32. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
  33. data/lib/gandi_v5/organization.rb +38 -5
  34. data/lib/gandi_v5/organization/customer.rb +90 -0
  35. data/lib/gandi_v5/version.rb +1 -1
  36. data/spec/.rubocop.yml +9 -2
  37. data/spec/fixtures/bodies/GandiV5_Billing/{info.yaml → info.yml} +0 -0
  38. data/spec/fixtures/bodies/GandiV5_Domain/{get.yaml → fetch.yml} +8 -0
  39. data/spec/fixtures/bodies/GandiV5_Domain/{fetch_contacts.yaml → fetch_contacts.yml} +0 -0
  40. data/spec/fixtures/bodies/GandiV5_Domain/fetch_glue_records.yml +7 -0
  41. data/spec/fixtures/bodies/GandiV5_Domain/fetch_livedns.yml +6 -0
  42. data/spec/fixtures/bodies/GandiV5_Domain/fetch_name_servers.yml +2 -0
  43. data/spec/fixtures/bodies/GandiV5_Domain/{renewal_info.yaml → fetch_renewal_info.yml} +0 -3
  44. data/spec/fixtures/bodies/GandiV5_Domain/{restore_info.yaml → fetch_restore_info.yml} +0 -0
  45. data/spec/fixtures/bodies/GandiV5_Domain/{list.yaml → list.yml} +1 -0
  46. data/spec/fixtures/bodies/GandiV5_Domain_Availability/{fetch.yaml → fetch.yml} +0 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TLD/{fetch.yaml → fetch.yml} +0 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_TLD/{list.yaml → list.yml} +0 -0
  49. data/spec/fixtures/bodies/GandiV5_Email_Forward/list.yml +6 -0
  50. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/{get.yaml → fetch.yml} +0 -0
  51. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/{list.yaml → list.yml} +0 -0
  52. data/spec/fixtures/bodies/GandiV5_Email_Slot/{get.yaml → fetch.yml} +0 -0
  53. data/spec/fixtures/bodies/GandiV5_Email_Slot/{list.yaml → list.yml} +0 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +3 -0
  55. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/{list.yaml → list.yml} +0 -0
  56. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  57. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  58. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  59. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  60. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot/fetch.yaml → GandiV5_LiveDNS_Domain_Snapshot/fetch.yml} +4 -3
  61. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  62. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  63. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  64. data/spec/fixtures/bodies/GandiV5_Organization/{get.yaml → fetch.yml} +0 -0
  65. data/spec/fixtures/bodies/GandiV5_Organization/list.yml +7 -0
  66. data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
  67. data/spec/spec_helper.rb +2 -2
  68. data/spec/units/gandi_v5/billing_spec.rb +2 -2
  69. data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
  70. data/spec/units/gandi_v5/domain/availability_spec.rb +1 -1
  71. data/spec/units/gandi_v5/domain/live_dns_spec.rb +45 -0
  72. data/spec/units/gandi_v5/domain/tld_spec.rb +2 -2
  73. data/spec/units/gandi_v5/domain_spec.rb +294 -65
  74. data/spec/units/gandi_v5/email/forward_spec.rb +92 -0
  75. data/spec/units/gandi_v5/email/mailbox_spec.rb +122 -40
  76. data/spec/units/gandi_v5/email/slot_spec.rb +13 -5
  77. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  78. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  79. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  80. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  81. data/spec/units/gandi_v5/live_dns/domain_spec.rb +299 -120
  82. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  83. data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
  84. data/spec/units/gandi_v5/organization_spec.rb +52 -1
  85. data/spec/units/gandi_v5_spec.rb +139 -30
  86. metadata +68 -95
  87. data/doc/GandiV5.html +0 -1183
  88. data/doc/GandiV5/Billing.html +0 -293
  89. data/doc/GandiV5/Billing/Info.html +0 -641
  90. data/doc/GandiV5/Billing/Info/Prepaid.html +0 -817
  91. data/doc/GandiV5/Data.html +0 -785
  92. data/doc/GandiV5/Data/ClassMethods.html +0 -223
  93. data/doc/GandiV5/Data/Converter.html +0 -433
  94. data/doc/GandiV5/Data/Converter/ArrayOf.html +0 -413
  95. data/doc/GandiV5/Data/Converter/Symbol.html +0 -322
  96. data/doc/GandiV5/Data/Converter/Time.html +0 -330
  97. data/doc/GandiV5/Domain.html +0 -16847
  98. data/doc/GandiV5/Domain/AutoRenew.html +0 -1237
  99. data/doc/GandiV5/Domain/Availability.html +0 -1020
  100. data/doc/GandiV5/Domain/Availability/Product.html +0 -988
  101. data/doc/GandiV5/Domain/Availability/Product/Period.html +0 -220
  102. data/doc/GandiV5/Domain/Availability/Product/Price.html +0 -1031
  103. data/doc/GandiV5/Domain/Availability/Tax.html +0 -440
  104. data/doc/GandiV5/Domain/Contact.html +0 -4459
  105. data/doc/GandiV5/Domain/Contract.html +0 -520
  106. data/doc/GandiV5/Domain/Dates.html +0 -1313
  107. data/doc/GandiV5/Domain/RenewalInformation.html +0 -1147
  108. data/doc/GandiV5/Domain/RestoreInformation.html +0 -339
  109. data/doc/GandiV5/Domain/SharingSpace.html +0 -437
  110. data/doc/GandiV5/Domain/TLD.html +0 -1565
  111. data/doc/GandiV5/Email.html +0 -144
  112. data/doc/GandiV5/Email/Mailbox.html +0 -6307
  113. data/doc/GandiV5/Email/Mailbox/Responder.html +0 -1560
  114. data/doc/GandiV5/Email/Offer.html +0 -514
  115. data/doc/GandiV5/Email/Slot.html +0 -4244
  116. data/doc/GandiV5/Error.html +0 -151
  117. data/doc/GandiV5/Error/GandiError.html +0 -270
  118. data/doc/GandiV5/LiveDNS.html +0 -300
  119. data/doc/GandiV5/LiveDNS/Domain.html +0 -2984
  120. data/doc/GandiV5/LiveDNS/RecordSet.html +0 -1593
  121. data/doc/GandiV5/LiveDNS/Zone.html +0 -8891
  122. data/doc/GandiV5/LiveDNS/Zone/Snapshot.html +0 -1556
  123. data/doc/GandiV5/Organization.html +0 -2341
  124. data/doc/_index.html +0 -474
  125. data/doc/class_list.html +0 -51
  126. data/doc/css/common.css +0 -1
  127. data/doc/css/full_list.css +0 -58
  128. data/doc/css/style.css +0 -496
  129. data/doc/file.README.html +0 -175
  130. data/doc/file_list.html +0 -56
  131. data/doc/frames.html +0 -17
  132. data/doc/index.html +0 -175
  133. data/doc/js/app.js +0 -303
  134. data/doc/js/full_list.js +0 -216
  135. data/doc/js/jquery.js +0 -4
  136. data/doc/method_list.html +0 -2427
  137. data/doc/top-level-namespace.html +0 -110
  138. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  139. data/lib/gandi_v5/live_dns/zone.rb +0 -305
  140. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  141. data/spec/features/domain_spec.rb +0 -45
  142. data/spec/features/livedns_domain_spec.rb +0 -8
  143. data/spec/features/livedns_zone_spec.rb +0 -45
  144. data/spec/features/mailbox_spec.rb +0 -18
  145. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/get.yaml +0 -4
  146. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/get.yaml +0 -11
  147. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yaml +0 -11
  148. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yaml +0 -3
  149. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -54
  150. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  151. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  152. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  153. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  154. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  155. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  156. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  157. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe GandiV5::LiveDNS::RecordSet do
3
+ describe GandiV5::LiveDNS::Domain::Record do
4
4
  subject do
5
5
  described_class.new type: 'A', ttl: 900, name: 'www', values: %w[192.168.0.1 192.168.0.2]
6
6
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::Domain::Snapshot do
4
+ subject do
5
+ described_class.new(
6
+ created_at: Time.new(2016, 12, 16, 16, 51, 26, 0),
7
+ uuid: 'snapshot-uuid',
8
+ name: 'snapshot-name',
9
+ automatic: false,
10
+ records: [],
11
+ fqdn: 'example.com'
12
+ )
13
+ end
14
+
15
+ it '#update' do
16
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid'
17
+ body = '{"name":"NEW NAME"}'
18
+ expect(GandiV5).to receive(:patch).with(url, body)
19
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
20
+ expect(subject.update(name: 'NEW NAME')).to eq 'Confirmation message.'
21
+ expect(subject.name).to eq 'NEW NAME'
22
+ end
23
+
24
+ it '#delete' do
25
+ expect(GandiV5).to receive(:delete).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
26
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
27
+ expect(subject.delete).to eq 'Confirmation message.'
28
+ end
29
+
30
+ describe '#records' do
31
+ it 'Returns existing if present' do
32
+ expect(GandiV5).to_not receive(:get)
33
+ expect(subject.records).to eq []
34
+ end
35
+
36
+ it 'Fetches and saves if not present' do
37
+ subject = described_class.new fqdn: 'example.com', uuid: 'snapshot-uuid'
38
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
39
+ .and_return([nil, { 'zone_data' => [{ 'rrset_name' => 'HELLO' }] }])
40
+ expect(subject.records.count).to eq 1
41
+ expect(subject.records.first.name).to eq 'HELLO'
42
+ end
43
+ end
44
+
45
+ describe '.list' do
46
+ let :body_fixture do
47
+ File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_Snapshot', 'list.yml'))
48
+ end
49
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/snapshots' }
50
+
51
+ it 'With default parameters' do
52
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
53
+ .and_yield(YAML.load_file(body_fixture))
54
+ results = described_class.list('example.com')
55
+ result = results.first
56
+ expect(results.count).to eq 1
57
+ expect(result.name).to eq 'snapshot-name'
58
+ expect(result.created_at).to eq Time.new(2016, 12, 16, 16, 51, 26, 0)
59
+ expect(result.uuid).to eq 'snapshot-uuid'
60
+ expect(result.automatic).to be true
61
+ expect(result.fqdn).to eq 'example.com'
62
+ end
63
+
64
+ describe 'Passes optional query params' do
65
+ describe 'automatic' do
66
+ it 'true' do
67
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { automatic: true })
68
+ described_class.list('example.com', automatic: true)
69
+ end
70
+
71
+ it 'false' do
72
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { automatic: false })
73
+ described_class.list('example.com', automatic: false)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '.fetch' do
80
+ subject { described_class.fetch 'example.com', 'snapshot-uuid' }
81
+
82
+ before :each do
83
+ body_fixture = File.expand_path(
84
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_Snapshot', 'fetch.yml')
85
+ )
86
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/snapshots/snapshot-uuid')
87
+ .and_return([nil, YAML.load_file(body_fixture)])
88
+ end
89
+
90
+ its('created_at') { should eq Time.new(2016, 12, 16, 16, 51, 26, 0) }
91
+ its('uuid') { should eq 'snapshot-uuid' }
92
+ its('name') { should eq 'snapshot-name' }
93
+ its('automatic') { should be true }
94
+ its('fqdn') { should eq 'example.com' }
95
+ its('records.count') { should eq 1 }
96
+ its('records.first.type') { should eq 'A' }
97
+ its('records.first.ttl') { should eq 10_800 }
98
+ its('records.first.name') { should eq 'www' }
99
+ its('records.first.values') { should match_array ['10.0.1.42'] }
100
+ end
101
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::Domain::TsigKey do
4
+ subject do
5
+ described_class.new(
6
+ uuid: 'key-uuid',
7
+ name: 'key-name',
8
+ secret: 'key-secret',
9
+ config_examples: { test: 'test config sample' }
10
+ )
11
+ end
12
+
13
+ describe '.create' do
14
+ it 'Without sharing_id' do
15
+ url = 'https://api.gandi.net/v5/livedns/axfr/tsig'
16
+ created = { 'href' => '', 'id' => 'created-key-uuid', 'key_name' => 'based on id' }
17
+ returns = double described_class
18
+
19
+ expect(GandiV5).to receive(:post).with(url).and_return([nil, created])
20
+ expect(described_class).to receive(:fetch).with('created-key-uuid')
21
+ .and_return(returns)
22
+ expect(described_class.create).to be returns
23
+ end
24
+
25
+ it 'With sharing_id' do
26
+ url = 'https://api.gandi.net/v5/livedns/axfr/tsig?sharing_id=sharing-id'
27
+ created = { 'href' => '', 'id' => 'created-key-uuid', 'key_name' => 'based on id' }
28
+ returns = double described_class
29
+
30
+ expect(GandiV5).to receive(:post).with(url).and_return([nil, created])
31
+ expect(described_class).to receive(:fetch).with('created-key-uuid')
32
+ .and_return(returns)
33
+ expect(described_class.create('sharing-id')).to be returns
34
+ end
35
+ end
36
+
37
+ it '.list' do
38
+ body_fixture = File.expand_path(
39
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_TsigKey', 'list.yml')
40
+ )
41
+ url = 'https://api.gandi.net/v5/livedns/axfr/tsig'
42
+
43
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
44
+ results = described_class.list
45
+ result = results.first
46
+ expect(results.count).to eq 1
47
+ expect(result.uuid).to eq 'key-uuid'
48
+ expect(result.name).to eq 'key-name'
49
+ expect(result.secret).to eq 'key-secret'
50
+ end
51
+
52
+ describe '.fetch' do
53
+ subject { described_class.fetch 'key-uuid' }
54
+
55
+ before :each do
56
+ body_fixture = File.expand_path(
57
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain_TsigKey', 'fetch.yml')
58
+ )
59
+ url = 'https://api.gandi.net/v5/livedns/axfr/tsig/key-uuid'
60
+ expect(GandiV5).to receive(:get).with(url)
61
+ .and_return([nil, YAML.load_file(body_fixture)])
62
+ end
63
+
64
+ its('uuid') { should eq 'key-uuid' }
65
+ its('name') { should eq 'key-name' }
66
+ its('secret') { should eq 'key-secret' }
67
+ its('config_examples') do
68
+ should eq(
69
+ {
70
+ bind: 'bind-sample',
71
+ knot: 'knot-sample',
72
+ nsd: 'nsd-sample',
73
+ powerdns: 'powerdns-sample'
74
+ }
75
+ )
76
+ end
77
+ end
78
+ end
@@ -2,51 +2,53 @@
2
2
 
3
3
  describe GandiV5::LiveDNS::Domain do
4
4
  subject do
5
- described_class.new fqdn: 'example.com', zone_uuid: 'zone-uuid'
5
+ described_class.new fqdn: 'example.com', automatic_snapshots: false
6
6
  end
7
7
 
8
8
  describe '#refresh' do
9
9
  before :each do
10
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
11
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
10
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'fetch.yml'))
11
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com')
12
12
  .and_return([nil, YAML.load_file(body_fixture)])
13
13
  subject.refresh
14
14
  end
15
15
 
16
16
  its('fqdn') { should eq 'example.com' }
17
- its('zone_uuid') { should eq 'zone-uuid' }
17
+ its('automatic_snapshots') { should be true }
18
+ end
19
+
20
+ it '#update' do
21
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com'
22
+ body = '{"automatic_snapshots":true}'
23
+ expect(GandiV5).to receive(:patch).with(url, body)
24
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
25
+ expect(subject.update(automatic_snapshots: true)).to eq 'Confirmation message.'
26
+ expect(subject.automatic_snapshots).to be true
18
27
  end
19
28
 
20
29
  describe '#fetch_records' do
30
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/records' }
21
31
  it 'All of them' do
22
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records')
23
- .and_return([nil, []])
24
-
32
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100)
33
+ .and_yield([])
25
34
  expect(subject.fetch_records).to eq []
26
35
  end
27
36
 
28
37
  it 'All for a name' do
29
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name')
30
- .and_return([nil, []])
31
-
38
+ expect(GandiV5).to receive(:paginated_get).with("#{url}/name", (1..), 100)
39
+ .and_yield([])
32
40
  expect(subject.fetch_records('name')).to eq []
33
41
  end
34
42
 
35
43
  it 'A type for a name' do
36
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT')
37
- .and_return(
38
- [
39
- nil,
40
- [
41
- {
42
- 'rrset_type' => 'TXT',
43
- 'rrset_name' => 'name',
44
- 'rrset_ttl' => 600,
45
- 'rrset_values' => %w[a b]
46
- }
47
- ]
48
- ]
49
- )
44
+ record = {
45
+ 'rrset_type' => 'TXT',
46
+ 'rrset_name' => 'name',
47
+ 'rrset_ttl' => 600,
48
+ 'rrset_values' => %w[a b]
49
+ }
50
+ expect(GandiV5).to receive(:paginated_get).with("#{url}/name/TXT", (1..), 100)
51
+ .and_yield([record])
50
52
 
51
53
  records = subject.fetch_records('name', 'TXT')
52
54
  expect(records.count).to eq 1
@@ -63,19 +65,19 @@ describe GandiV5::LiveDNS::Domain do
63
65
 
64
66
  describe '#fetch_zone_lines' do
65
67
  it 'All of them' do
66
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
68
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
67
69
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
68
70
  expect(subject.fetch_zone_lines).to eq 'returned'
69
71
  end
70
72
 
71
73
  it 'All for a name' do
72
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
74
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
73
75
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
74
76
  expect(subject.fetch_zone_lines('name')).to eq 'returned'
75
77
  end
76
78
 
77
79
  it 'A type for a name' do
78
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
80
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
79
81
  expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return([nil, 'returned'])
80
82
  expect(subject.fetch_zone_lines('name', 'TXT')).to eq 'returned'
81
83
  end
@@ -87,7 +89,7 @@ describe GandiV5::LiveDNS::Domain do
87
89
 
88
90
  describe '#add_record' do
89
91
  it 'Success' do
90
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
92
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
91
93
  body = '{"rrset_name":"name","rrset_type":"TXT","rrset_ttl":900,"rrset_values":["a","b"]}'
92
94
  expect(GandiV5).to receive(:post).with(url, body).and_return([nil, { 'message' => 'Confirmation message.' }])
93
95
  expect(subject.add_record('name', 'TXT', 900, 'a', 'b')).to eq 'Confirmation message.'
@@ -114,19 +116,19 @@ describe GandiV5::LiveDNS::Domain do
114
116
 
115
117
  describe '#delete_records' do
116
118
  it 'All of them' do
117
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
119
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
118
120
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
119
121
  subject.delete_records
120
122
  end
121
123
 
122
124
  it 'All for a name' do
123
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
125
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
124
126
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
125
127
  subject.delete_records 'name'
126
128
  end
127
129
 
128
130
  it 'A type for a name' do
129
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
131
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
130
132
  expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
131
133
  subject.delete_records 'name', 'TXT'
132
134
  end
@@ -137,141 +139,318 @@ describe GandiV5::LiveDNS::Domain do
137
139
  end
138
140
 
139
141
  describe '#replace_records' do
140
- it 'Given array of GandiV5::LiveDNS::RecordSet' do
141
- records = [
142
- { name: 'name', ttl: 600, type: 'TXT', values: ['a'] }
143
- ]
144
-
145
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
146
- body = '{"items":[{"rrset_name":"name","rrset_ttl":600,"rrset_type":"TXT","rrset_values":["a"]}]}'
142
+ it 'All of them' do
143
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
144
+ body = '{"items":[{"rrset_name":"name","rrset_type":"TXT","rrset_values":["a"]}]}'
147
145
  expect(GandiV5).to receive(:put).with(url, body)
148
146
  .and_return([nil, { 'message' => 'Confirmation message.' }])
149
- expect(subject.replace_records(records: records)).to eq 'Confirmation message.'
147
+ records = [{ name: 'name', type: 'TXT', values: ['a'] }]
148
+ expect(subject.replace_records(records)).to eq 'Confirmation message.'
150
149
  end
151
150
 
152
- it 'Given string' do
153
- records = [
154
- '@ 86400 IN A 192.168.0.1',
155
- '* 86400 IN A 192.168.0.1'
156
- ].join("\n")
151
+ it 'All for a name' do
152
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name'
153
+ body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
154
+ expect(GandiV5).to receive(:put).with(url, body)
155
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
156
+ records = [{ type: 'TXT', values: ['a'] }]
157
+ expect(subject.replace_records(records, name: 'name')).to eq 'Confirmation message.'
158
+ end
157
159
 
158
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
159
- expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
160
+ it 'All of a type for a name' do
161
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records/name/TXT'
162
+ body = '{"rrset_values":["a"]}'
163
+ expect(GandiV5).to receive(:put).with(url, body)
160
164
  .and_return([nil, { 'message' => 'Confirmation message.' }])
161
- expect(subject.replace_records(text: records)).to eq 'Confirmation message.'
165
+ expect(subject.replace_records(['a'], name: 'name', type: 'TXT')).to eq 'Confirmation message.'
162
166
  end
163
167
 
164
- it 'Given both' do
165
- expect { subject.replace_records text: '', records: [] }.to raise_error(
166
- ArgumentError,
167
- 'you must pass ONE of records: or text:'
168
- )
168
+ it 'Given type but no name' do
169
+ expect(GandiV5).to_not receive(:put)
170
+ expect { subject.replace_records(['a'], type: 'TXT') }.to raise_error ArgumentError, 'missing keyword: name'
171
+ end
172
+ end
173
+
174
+ it '#replace_zone_lines' do
175
+ records = [
176
+ '@ 86400 IN A 192.168.0.1',
177
+ '* 86400 IN A 192.168.0.1'
178
+ ].join("\n")
179
+
180
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/records'
181
+ expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
182
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
183
+ expect(subject.replace_zone_lines(records)).to eq 'Confirmation message.'
184
+ end
185
+
186
+ describe '#name_servers' do
187
+ let(:nameservers) { double Array }
188
+
189
+ it 'Already fetched' do
190
+ subject.instance_exec(nameservers) { |ns| @name_servers = ns }
191
+ expect(subject).to_not receive(:fetch_name_servers)
192
+ expect(subject.name_servers).to be nameservers
169
193
  end
170
194
 
171
- it 'Given nothing' do
172
- expect { subject.replace_records }.to raise_error ArgumentError, 'you must pass ONE of records: or text:'
195
+ it 'Not already fetched' do
196
+ expect(subject).to receive(:fetch_name_servers).and_return(nameservers)
197
+ expect(subject.name_servers).to be nameservers
173
198
  end
174
199
  end
175
200
 
176
- describe '#replace_records_for' do
177
- it 'Given no type or ttl' do
178
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
179
- body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
180
- expect(GandiV5).to receive(:put).with(url, body)
181
- .and_return([nil, { 'message' => 'Confirmation message.' }])
182
- records = [{ type: 'TXT', values: ['a'] }]
183
- expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
201
+ it '#fetch_name_servers' do
202
+ body_fixture = File.expand_path(
203
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'nameservers.yml')
204
+ )
205
+
206
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com/nameservers')
207
+ .and_return([nil, YAML.load_file(body_fixture)])
208
+
209
+ expect(subject.fetch_name_servers).to match_array ['a.example.com', 'b.example.com']
210
+ end
211
+
212
+ describe '#dnssec_keys' do
213
+ let(:dnsseckeys) { double Array }
214
+
215
+ it 'Already fetched' do
216
+ subject.instance_exec(dnsseckeys) { |k| @dnssec_keys = k }
217
+ expect(subject).to_not receive(:fetch_dnssec_keys)
218
+ expect(subject.dnssec_keys).to be dnsseckeys
184
219
  end
185
220
 
186
- it 'Given type and ttl' do
187
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
188
- body = '{"rrset_values":["a"],"rrset_ttl":600}'
189
- expect(GandiV5).to receive(:put).with(url, body)
190
- .and_return([nil, { 'message' => 'Confirmation message.' }])
191
- expect(subject.replace_records_for('name', ['a'], type: 'TXT', ttl: 600)).to eq 'Confirmation message.'
221
+ it 'Not already fetched' do
222
+ expect(subject).to receive(:fetch_dnssec_keys).and_return(dnsseckeys)
223
+ expect(subject.dnssec_keys).to be dnsseckeys
192
224
  end
225
+ end
193
226
 
194
- it 'Given type but no ttl' do
195
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
196
- body = '{"rrset_values":["a"],"rrset_ttl":null}'
197
- expect(GandiV5).to receive(:put).with(url, body)
198
- .and_return([nil, { 'message' => 'Confirmation message.' }])
199
- expect(subject.replace_records_for('name', ['a'], type: 'TXT')).to eq 'Confirmation message.'
227
+ it '#fetch_dnssec_keys' do
228
+ keys = double Array
229
+ expect(GandiV5::LiveDNS::Domain::DnssecKey).to receive(:list).with('example.com')
230
+ .and_return(keys)
231
+
232
+ expect(subject.fetch_dnssec_keys).to be keys
233
+ expect(subject.instance_exec { @dnssec_keys }).to be keys
234
+ end
235
+
236
+ describe '#tsig_keys' do
237
+ let(:tsigkeys) { double Array }
238
+
239
+ it 'Already fetched' do
240
+ subject.instance_exec(tsigkeys) { |k| @tsig_keys = k }
241
+ expect(subject).to_not receive(:fetch_tsig_keys)
242
+ expect(subject.tsig_keys).to be tsigkeys
200
243
  end
201
244
 
202
- it 'Given ttl but no type' do
203
- expect(GandiV5).to_not receive(:put)
204
- expect { subject.replace_records_for 'name', 'a', ttl: 600 }.to raise_error ArgumentError, 'missing keyword: type'
245
+ it 'Not already fetched' do
246
+ expect(subject).to receive(:fetch_tsig_keys).and_return(tsigkeys)
247
+ expect(subject.tsig_keys).to be tsigkeys
205
248
  end
206
249
  end
207
250
 
208
- describe '#change_zone' do
209
- it 'Given a uuid' do
210
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
211
- body = '{"zone_uuid":"zone-uuid"}'
212
- expect(GandiV5).to receive(:patch).with(url, body)
213
- .and_return([nil, { 'message' => 'Confirmation message.' }])
214
- expect(subject.change_zone('zone-uuid')).to eq 'Confirmation message.'
215
- expect(subject.zone_uuid).to eq 'zone-uuid'
216
- end
217
-
218
- it 'Given something with a uuid method' do
219
- url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
220
- body = '{"zone_uuid":"zone-uuid"}'
221
- expect(GandiV5).to receive(:patch).with(url, body)
222
- .and_return([nil, { 'message' => 'Confirmation message.' }])
223
- zone = double GandiV5::LiveDNS::Zone, uuid: 'zone-uuid'
224
- expect(subject.change_zone(zone)).to eq 'Confirmation message.'
225
- expect(subject.zone_uuid).to eq 'zone-uuid'
251
+ it '#fetch_tsig_keys' do
252
+ body_fixture = File.expand_path(
253
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list_tsig.yml')
254
+ )
255
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig'
256
+
257
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, YAML.load_file(body_fixture)])
258
+ results = subject.fetch_tsig_keys
259
+ result = results.first
260
+ expect(results.count).to eq 1
261
+ expect(result.uuid).to eq 'key-uuid'
262
+ expect(result.name).to eq 'key-name'
263
+ end
264
+
265
+ describe '#add_tsig_key' do
266
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig/key-uuid' }
267
+
268
+ it 'Passed a key' do
269
+ key = GandiV5::LiveDNS::Domain::TsigKey.new uuid: 'key-uuid'
270
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
271
+ subject.add_tsig_key key
272
+ end
273
+
274
+ it 'Passed a string' do
275
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
276
+ subject.add_tsig_key 'key-uuid'
277
+ end
278
+
279
+ it 'With sharing_id' do
280
+ expect(GandiV5).to receive(:put).with("#{url}?sharing_id=sharing-id").and_return([nil, nil])
281
+ subject.add_tsig_key 'key-uuid', sharing_id: 'sharing-id'
226
282
  end
227
283
  end
228
284
 
229
- it '#fetch_zone' do
230
- returns = double GandiV5::LiveDNS::Zone
231
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid')
232
- .and_return(returns)
233
- expect(subject.fetch_zone).to be returns
285
+ describe '#remove_tsig_key' do
286
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/tsig/key-uuid' }
287
+
288
+ it 'Passed a key' do
289
+ key = GandiV5::LiveDNS::Domain::TsigKey.new uuid: 'key-uuid'
290
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
291
+ subject.remove_tsig_key key
292
+ end
293
+
294
+ it 'Passed a string' do
295
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
296
+ subject.remove_tsig_key 'key-uuid'
297
+ end
298
+
299
+ it 'With sharing_id' do
300
+ expect(GandiV5).to receive(:delete).with("#{url}?sharing_id=sharing-id").and_return([nil, nil])
301
+ subject.remove_tsig_key 'key-uuid', sharing_id: 'sharing-id'
302
+ end
234
303
  end
235
304
 
236
- describe '#zone' do
237
- it 'Not previously fetched' do
238
- returns = double GandiV5::LiveDNS::Zone
239
- expect(subject).to receive(:fetch_zone).and_return(returns)
240
- expect(subject.zone).to be returns
305
+ describe '#axfr_clients' do
306
+ let(:clients) { double Array }
307
+
308
+ it 'Already fetched' do
309
+ subject.instance_exec(clients) { |k| @axfr_clients = k }
310
+ expect(subject).to_not receive(:fetch_axfr_clients)
311
+ expect(subject.axfr_clients).to be clients
241
312
  end
242
313
 
243
- it 'Previously fetched' do
244
- returns = double GandiV5::LiveDNS::Zone
245
- subject.instance_exec { @zone = returns }
246
- expect(subject).to_not receive(:fetch_zone)
247
- expect(subject.zone).to be returns
314
+ it 'Not already fetched' do
315
+ expect(subject).to receive(:fetch_axfr_clients).and_return(clients)
316
+ expect(subject.axfr_clients).to be clients
248
317
  end
249
318
  end
250
319
 
320
+ it '#fetch_axfr_clients' do
321
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves'
322
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, ['1.2.3.4']])
323
+ expect(subject.fetch_axfr_clients).to match_array ['1.2.3.4']
324
+ end
325
+
326
+ it '#add_axfr_client' do
327
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves/1.2.3.4'
328
+ expect(GandiV5).to receive(:put).with(url).and_return([nil, nil])
329
+ subject.add_axfr_client '1.2.3.4'
330
+ end
331
+
332
+ it '#remove_axfr_client' do
333
+ url = 'https://api.gandi.net/v5/livedns/domains/example.com/axfr/slaves/1.2.3.4'
334
+ expect(GandiV5).to receive(:delete).with(url).and_return([nil, nil])
335
+ subject.remove_axfr_client '1.2.3.4'
336
+ end
337
+
251
338
  describe '.list' do
252
- subject { described_class.list }
339
+ let(:body_fixture) do
340
+ File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yml'))
341
+ end
342
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains' }
253
343
 
254
- before :each do
255
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yaml'))
256
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains')
344
+ it 'With default parameters' do
345
+ headers = { params: { page: 1, per_page: 100 } }
346
+ expect(GandiV5).to receive(:get).with(url, headers)
257
347
  .and_return([nil, YAML.load_file(body_fixture)])
348
+
349
+ subject = described_class.list
350
+ expect(subject.count).to eq 1
351
+ expect(subject.first).to eq 'example.com'
258
352
  end
259
353
 
260
- its('count') { should eq 1 }
261
- its('first.fqdn') { should eq 'example.com' }
262
- its('first.zone_uuid') { should be nil }
354
+ it 'Keeps fetching until no more to get' do
355
+ headers1 = { params: { page: 1, per_page: 1 } }
356
+ headers2 = { params: { page: 2, per_page: 1 } }
357
+ expect(GandiV5).to receive(:get).with(url, headers1)
358
+ .ordered
359
+ .and_return([nil, YAML.load_file(body_fixture)])
360
+ expect(GandiV5).to receive(:get).with(url, headers2)
361
+ .ordered
362
+ .and_return([nil, []])
363
+
364
+ expect(described_class.list(per_page: 1).count).to eq 1
365
+ end
366
+
367
+ it 'Given a range as page number' do
368
+ headers = { params: { page: 1, per_page: 1 } }
369
+ expect(GandiV5).to receive(:get).with(url, headers)
370
+ .and_return([nil, YAML.load_file(body_fixture)])
371
+
372
+ described_class.list(page: (1..1), per_page: 1)
373
+ end
374
+
375
+ describe 'Passes optional query params' do
376
+ it 'per_page' do
377
+ headers = { params: { page: 1, per_page: 10 } }
378
+ expect(GandiV5).to receive(:get).with(url, headers)
379
+ .and_return([nil, []])
380
+ described_class.list(per_page: 10)
381
+ end
382
+
383
+ it 'sharing_id' do
384
+ headers = { params: { sharing_id: 'SHARING-UUID', page: 1, per_page: 100 } }
385
+ expect(GandiV5).to receive(:get).with(url, headers)
386
+ .and_return([nil, []])
387
+ described_class.list(sharing_id: 'SHARING-UUID')
388
+ end
389
+ end
263
390
  end
264
391
 
265
392
  describe '.fetch' do
266
393
  subject { described_class.fetch 'example.com' }
267
394
 
268
395
  before :each do
269
- body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
270
- expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
396
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'fetch.yml'))
397
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/domains/example.com')
271
398
  .and_return([nil, YAML.load_file(body_fixture)])
272
399
  end
273
400
 
274
401
  its('fqdn') { should eq 'example.com' }
275
- its('zone_uuid') { should eq 'zone-uuid' }
402
+ its('automatic_snapshots') { should be true }
403
+ end
404
+
405
+ describe '.create' do
406
+ let(:url) { 'https://api.gandi.net/v5/livedns/domains' }
407
+ let(:response) do
408
+ double RestClient::Response, headers: { location: 'https://api.gandi.net/v5/livedns/domains/example.com' }
409
+ end
410
+
411
+ it 'When passed only fqdn' do
412
+ returns = double described_class
413
+ body = '{"fqdn":"example.com","zone":{}}'
414
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
415
+ expect(described_class).to receive(:fetch).with('example.com').and_return(returns)
416
+ expect(described_class.create('example.com')).to be returns
417
+ end
418
+
419
+ it 'When passed soa_ttl' do
420
+ body = '{"fqdn":"example.com","zone":{"ttl":123}}'
421
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
422
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
423
+ described_class.create('example.com', soa_ttl: 123)
424
+ end
425
+
426
+ it 'When passed records' do
427
+ body = '{"fqdn":"example.com","zone":{"items":' \
428
+ '[{"rrset_type":"TXT","rrset_ttl":234,"rrset_name":"test","rrset_values":["value"]}]}}'
429
+ record = GandiV5::LiveDNS::Domain::Record.new name: 'test', type: 'TXT', ttl: 234, values: ['value']
430
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, nil])
431
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
432
+ described_class.create('example.com', [record])
433
+ end
434
+
435
+ it 'When passed sharing_id' do
436
+ body = '{"fqdn":"example.com","zone":{}}'
437
+ expect(GandiV5).to receive(:post).with("#{url}?sharing_id=organization_id", body).and_return([response, nil])
438
+ expect(described_class).to receive(:fetch).with('example.com').and_return(nil)
439
+ described_class.create('example.com', sharing_id: 'organization_id')
440
+ end
441
+ end
442
+
443
+ it '.record_types' do
444
+ list = double Array
445
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/dns/rrtypes')
446
+ .and_return([nil, list])
447
+ expect(described_class.record_types).to be list
448
+ end
449
+
450
+ it '.generic_name_servers' do
451
+ list = double Array
452
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/livedns/nameservers/example.com')
453
+ .and_return([nil, list])
454
+ expect(described_class.generic_name_servers('example.com')).to be list
276
455
  end
277
456
  end