gandi_v5 0.6.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -5
  3. data/README.md +65 -14
  4. data/lib/gandi_v5.rb +139 -70
  5. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  6. data/lib/gandi_v5/data.rb +3 -2
  7. data/lib/gandi_v5/data/converter.rb +3 -2
  8. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  9. data/lib/gandi_v5/data/converter/integer.rb +3 -2
  10. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  11. data/lib/gandi_v5/data/converter/time.rb +3 -2
  12. data/lib/gandi_v5/domain.rb +55 -18
  13. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  14. data/lib/gandi_v5/domain/contact.rb +5 -5
  15. data/lib/gandi_v5/domain/tld.rb +2 -2
  16. data/lib/gandi_v5/domain/transfer_in.rb +172 -0
  17. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  18. data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
  19. data/lib/gandi_v5/email.rb +3 -0
  20. data/lib/gandi_v5/email/forward.rb +3 -9
  21. data/lib/gandi_v5/email/mailbox.rb +5 -11
  22. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  23. data/lib/gandi_v5/live_dns.rb +2 -12
  24. data/lib/gandi_v5/live_dns/domain.rb +340 -29
  25. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
  26. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  27. data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
  28. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
  29. data/lib/gandi_v5/sharing_space.rb +27 -0
  30. data/lib/gandi_v5/simple_hosting.rb +13 -0
  31. data/lib/gandi_v5/simple_hosting/instance.rb +251 -0
  32. data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
  33. data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
  34. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  35. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
  36. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +272 -0
  37. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
  38. data/lib/gandi_v5/template.rb +271 -0
  39. data/lib/gandi_v5/template/dispatch.rb +109 -0
  40. data/lib/gandi_v5/template/payload.rb +64 -0
  41. data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
  42. data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
  43. data/lib/gandi_v5/version.rb +1 -1
  44. data/spec/.rubocop.yml +9 -9
  45. data/spec/features/list_domain_renewals_spec.rb +16 -0
  46. data/spec/features/list_email_addresses_spec.rb +39 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  49. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
  50. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
  51. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  52. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  53. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  55. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  56. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  57. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  58. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  59. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  60. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  61. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  62. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  63. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  64. data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
  65. data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
  66. data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
  67. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  68. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  69. data/spec/spec_helper.rb +8 -7
  70. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  71. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  72. data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
  73. data/spec/units/gandi_v5/domain_spec.rb +56 -37
  74. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  75. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  76. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  77. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  78. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  79. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  80. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  81. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  82. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  83. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  84. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +324 -0
  85. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +190 -0
  86. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  87. data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
  88. data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
  89. data/spec/units/gandi_v5/template_spec.rb +341 -0
  90. data/spec/units/gandi_v5_spec.rb +111 -14
  91. metadata +226 -79
  92. data/.gitignore +0 -26
  93. data/.rspec +0 -3
  94. data/.rubocop.yml +0 -30
  95. data/.travis.yml +0 -38
  96. data/FUNDING.yml +0 -10
  97. data/Gemfile +0 -6
  98. data/Guardfile +0 -39
  99. data/Rakefile +0 -3
  100. data/bin/console +0 -13
  101. data/gandi_v5.gemspec +0 -42
  102. data/lib/gandi_v5/domain/sharing_space.rb +0 -29
  103. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  104. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  105. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  106. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  107. data/spec/features/domain_spec.rb +0 -45
  108. data/spec/features/livedns_domain_spec.rb +0 -8
  109. data/spec/features/livedns_zone_spec.rb +0 -44
  110. data/spec/features/mailbox_spec.rb +0 -18
  111. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  112. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  113. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  114. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  115. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  116. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  117. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  118. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  119. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  120. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  121. data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
  122. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
  123. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
  124. data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
  125. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
  126. data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
  127. data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
  128. data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
  129. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  130. data/spec/units/gandi_v5/error_spec.rb +0 -4
  131. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  132. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -13,18 +13,6 @@ describe GandiV5::LiveDNS do
13
13
  expect(described_class.domains).to be returns
14
14
  end
15
15
 
16
- it '.zone' do
17
- returns = double GandiV5::LiveDNS::Zone
18
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid').and_return(returns)
19
- expect(described_class.zone('zone-uuid')).to be returns
20
- end
21
-
22
- it '.zones' do
23
- returns = double Array
24
- expect(GandiV5::LiveDNS::Zone).to receive(:list).and_return(returns)
25
- expect(described_class.zones).to be returns
26
- end
27
-
28
16
  describe '.require_valid_record_type' do
29
17
  it 'Does nothing for valid type' do
30
18
  expect { described_class.require_valid_record_type 'A' }.to_not raise_error
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::Application do
4
+ describe 'Helper methods' do
5
+ context 'being_created' do
6
+ subject { described_class.new status: :being_created }
7
+ its('being_created?') { should be true }
8
+ its('cancelled?') { should be false }
9
+ its('running?') { should be false }
10
+ its('error?') { should be false }
11
+ end
12
+
13
+ context 'cancelled' do
14
+ subject { described_class.new status: :cancelled }
15
+ its('being_created?') { should be false }
16
+ its('cancelled?') { should be true }
17
+ its('running?') { should be false }
18
+ its('error?') { should be false }
19
+ end
20
+
21
+ context 'running' do
22
+ subject { described_class.new status: :running }
23
+ its('being_created?') { should be false }
24
+ its('cancelled?') { should be false }
25
+ its('running?') { should be true }
26
+ its('error?') { should be false }
27
+ end
28
+
29
+ context 'error' do
30
+ subject { described_class.new status: :error }
31
+ its('being_created?') { should be false }
32
+ its('cancelled?') { should be false }
33
+ its('running?') { should be false }
34
+ its('error?') { should be true }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone do
4
+ describe 'Helper methods' do
5
+ context 'altered' do
6
+ subject { described_class.new status: :altered }
7
+ its('altered?') { should be true }
8
+ its('livedns_conflict?') { should be false }
9
+ its('livedns_done?') { should be false }
10
+ its('livedns_error?') { should be false }
11
+ its('unknown?') { should be false }
12
+ end
13
+
14
+ context 'altered' do
15
+ subject { described_class.new status: :livedns_conflict }
16
+ its('altered?') { should be false }
17
+ its('livedns_conflict?') { should be true }
18
+ its('livedns_done?') { should be false }
19
+ its('livedns_error?') { should be false }
20
+ its('unknown?') { should be false }
21
+ end
22
+
23
+ context 'livedns_done' do
24
+ subject { described_class.new status: :livedns_done }
25
+ its('altered?') { should be false }
26
+ its('livedns_conflict?') { should be false }
27
+ its('livedns_done?') { should be true }
28
+ its('livedns_error?') { should be false }
29
+ its('unknown?') { should be false }
30
+ end
31
+
32
+ context 'livedns_error' do
33
+ subject { described_class.new status: :livedns_error }
34
+ its('altered?') { should be false }
35
+ its('livedns_conflict?') { should be false }
36
+ its('livedns_done?') { should be false }
37
+ its('livedns_error?') { should be true }
38
+ its('unknown?') { should be false }
39
+ end
40
+
41
+ context 'unknown' do
42
+ subject { described_class.new status: :unknown }
43
+ its('altered?') { should be false }
44
+ its('livedns_conflict?') { should be false }
45
+ its('livedns_done?') { should be false }
46
+ its('livedns_error?') { should be false }
47
+ its('unknown?') { should be true }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,324 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance::VirtualHost do
4
+ let :body_list do
5
+ YAML.load_file(
6
+ File.expand_path(
7
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance_VirtualHost', 'list.yml')
8
+ )
9
+ )
10
+ end
11
+ let :body_fetch do
12
+ YAML.load_file(
13
+ File.expand_path(
14
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance_VirtualHost', 'fetch.yml')
15
+ )
16
+ )
17
+ end
18
+
19
+ subject do
20
+ described_class.new instance_uuid: 'instance-uuid', fqdn: 'vh.example.com'
21
+ end
22
+
23
+ it '#refresh' do
24
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
25
+ expect(GandiV5).to receive(:get).with(url)
26
+ .and_return([nil, body_fetch])
27
+ subject.refresh
28
+ expect(subject.linked_dns_zone.cname).to_not be nil
29
+ end
30
+
31
+ describe '#update' do
32
+ describe 'application' do
33
+ it 'Given a GandiV5::SimpleHosting::Instance::Application' do
34
+ application = GandiV5::SimpleHosting::Instance::Application.new(
35
+ name: 'app-name',
36
+ parameters: {}
37
+ )
38
+
39
+ expect(GandiV5).to receive(:put).with(
40
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
41
+ '{"application":{"name":"app-name","parameters":{}}}'
42
+ ).and_return([nil, body_fetch])
43
+ subject.update(application: application)
44
+
45
+ expect(subject.application.name).to eq 'app-name'
46
+ expect(subject.application.parameters).to eq({})
47
+ end
48
+
49
+ it 'Given a Hash' do
50
+ expect(GandiV5).to receive(:put).with(
51
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
52
+ '{"application":{"name":"app-name"}}'
53
+ ).and_return([nil, body_fetch])
54
+ subject.update(application: { name: 'app-name' })
55
+ end
56
+ end
57
+
58
+ describe 'https_strategy' do
59
+ it ':redirect_http_to_https' do
60
+ expect(GandiV5).to receive(:put).with(
61
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
62
+ '{"https_strategy":"redirect_HTTP_to_HTTPS"}'
63
+ ).and_return([nil, body_fetch])
64
+ subject.update(https_strategy: :redirect_http_to_https)
65
+ expect(subject.https_strategy).to be :redirect_http_to_https
66
+ end
67
+
68
+ it ':allow_http_and_https' do
69
+ expect(GandiV5).to receive(:put).with(
70
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
71
+ '{"https_strategy":"allow_HTTP_and_HTTPS"}'
72
+ ).and_return([nil, body_fetch])
73
+ subject.update(https_strategy: :allow_http_and_https)
74
+ expect(subject.https_strategy).to be :redirect_http_to_https
75
+ end
76
+
77
+ it ':http_only' do
78
+ expect(GandiV5).to receive(:put).with(
79
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
80
+ '{"https_strategy":"HTTP_only"}'
81
+ ).and_return([nil, body_fetch])
82
+ subject.update(https_strategy: :http_only)
83
+ expect(subject.https_strategy).to be :redirect_http_to_https
84
+ end
85
+
86
+ it 'invalid' do
87
+ expect(GandiV5).not_to receive(:put)
88
+ expect { subject.update(https_strategy: :invalid) }.to \
89
+ raise_error ArgumentError, 'https_strategy :invalid is invalid'
90
+ end
91
+ end
92
+
93
+ it 'linked_dns_zone' do
94
+ expect(GandiV5).to receive(:put).with(
95
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com',
96
+ '{"linked_dns_zone":{"allow_alteration":false,"allow_alteration_override":true}}'
97
+ ).and_return([nil, body_fetch])
98
+ subject.update(linked_dns_zone_allow_alteration: false, linked_dns_zone_allow_alteration_override: true)
99
+ expect(subject.linked_dns_zone.allow_alteration).to be true
100
+ end
101
+ end
102
+
103
+ it '#delete' do
104
+ expect(GandiV5).to receive(:delete).with(
105
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
106
+ ).and_return([nil, { 'message' => 'Confirmation message.' }])
107
+ expect(subject.delete).to eq 'Confirmation message.'
108
+ end
109
+
110
+ describe 'Helper methods' do
111
+ describe 'Status' do
112
+ context 'being_created' do
113
+ subject { described_class.new status: :being_created }
114
+ its('being_created?') { should be true }
115
+ its('running?') { should be false }
116
+ its('being_deleted?') { should be false }
117
+ its('locked?') { should be false }
118
+ its('waiting_ownership?') { should be false }
119
+ its('ownership_validated?') { should be false }
120
+ its('validation_failed?') { should be false }
121
+ end
122
+ context 'running' do
123
+ subject { described_class.new status: :running }
124
+ its('being_created?') { should be false }
125
+ its('running?') { should be true }
126
+ its('being_deleted?') { should be false }
127
+ its('locked?') { should be false }
128
+ its('waiting_ownership?') { should be false }
129
+ its('ownership_validated?') { should be false }
130
+ its('validation_failed?') { should be false }
131
+ end
132
+ context 'being_deleted' do
133
+ subject { described_class.new status: :being_deleted }
134
+ its('being_created?') { should be false }
135
+ its('running?') { should be false }
136
+ its('being_deleted?') { should be true }
137
+ its('locked?') { should be false }
138
+ its('waiting_ownership?') { should be false }
139
+ its('ownership_validated?') { should be false }
140
+ its('validation_failed?') { should be false }
141
+ end
142
+ context 'locked' do
143
+ subject { described_class.new status: :locked }
144
+ its('being_created?') { should be false }
145
+ its('running?') { should be false }
146
+ its('being_deleted?') { should be false }
147
+ its('locked?') { should be true }
148
+ its('waiting_ownership?') { should be false }
149
+ its('ownership_validated?') { should be false }
150
+ its('validation_failed?') { should be false }
151
+ end
152
+ context 'waiting_ownership' do
153
+ subject { described_class.new status: :waiting_ownership }
154
+ its('being_created?') { should be false }
155
+ its('running?') { should be false }
156
+ its('being_deleted?') { should be false }
157
+ its('locked?') { should be false }
158
+ its('waiting_ownership?') { should be true }
159
+ its('ownership_validated?') { should be false }
160
+ its('validation_failed?') { should be false }
161
+ end
162
+ context 'ownership_validated' do
163
+ subject { described_class.new status: :ownership_validated }
164
+ its('being_created?') { should be false }
165
+ its('running?') { should be false }
166
+ its('being_deleted?') { should be false }
167
+ its('locked?') { should be false }
168
+ its('waiting_ownership?') { should be false }
169
+ its('ownership_validated?') { should be true }
170
+ its('validation_failed?') { should be false }
171
+ end
172
+ context 'validation_failed' do
173
+ subject { described_class.new status: :validation_failed }
174
+ its('being_created?') { should be false }
175
+ its('running?') { should be false }
176
+ its('being_deleted?') { should be false }
177
+ its('locked?') { should be false }
178
+ its('waiting_ownership?') { should be false }
179
+ its('ownership_validated?') { should be false }
180
+ its('validation_failed?') { should be true }
181
+ end
182
+ end
183
+
184
+ describe 'HTTP(S)' do
185
+ context 'HTTP_only' do
186
+ subject { described_class.new https_strategy: :http_only }
187
+ its('http_only?') { should be true }
188
+ its('http_and_https?') { should be false }
189
+ its('redirect_http_to_https?') { should be false }
190
+ its('http?') { should be true }
191
+ its('https?') { should be false }
192
+ end
193
+ context 'HTTP_and_HTTPS' do
194
+ subject { described_class.new https_strategy: :http_and_https }
195
+ its('http_only?') { should be false }
196
+ its('http_and_https?') { should be true }
197
+ its('redirect_http_to_https?') { should be false }
198
+ its('http?') { should be true }
199
+ its('https?') { should be true }
200
+ end
201
+ context 'redirect_HTTP_to_HTTPS' do
202
+ subject { described_class.new https_strategy: :redirect_http_to_https }
203
+ its('http_only?') { should be false }
204
+ its('http_and_https?') { should be false }
205
+ its('redirect_http_to_https?') { should be true }
206
+ its('http?') { should be false }
207
+ its('https?') { should be false }
208
+ end
209
+ end
210
+ end
211
+
212
+ describe '.create' do
213
+ it 'With just fqdn' do
214
+ expect(GandiV5).to receive(:post).with(
215
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
216
+ '{"fqdn":"vh.example.com"}'
217
+ ).and_return([nil, nil])
218
+
219
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
220
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
221
+
222
+ subject = described_class.create('instance-uuid', 'vh.example.com')
223
+ expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
224
+ end
225
+
226
+ it 'Also with application' do
227
+ expect(GandiV5).to receive(:post).with(
228
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
229
+ '{"fqdn":"vh.example.com","application":{"name":"app-name"}}'
230
+ ).and_return([nil, nil])
231
+
232
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
233
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
234
+
235
+ subject = described_class.create('instance-uuid', 'vh.example.com', application: { name: 'app-name' })
236
+ expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
237
+ end
238
+
239
+ it 'Also with linked_dns_zone' do
240
+ expect(GandiV5).to receive(:post).with(
241
+ 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts',
242
+ '{"fqdn":"vh.example.com","linked_dns_zone":{"allow_alteration":false,"allow_alteration_override":true}}'
243
+ ).and_return([nil, nil])
244
+
245
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
246
+ expect(GandiV5).to receive(:get).with(url).and_return([nil, body_fetch])
247
+
248
+ subject = described_class.create(
249
+ 'instance-uuid',
250
+ 'vh.example.com',
251
+ linked_dns_zone_allow_alteration: false,
252
+ linked_dns_zone_allow_alteration_override: true
253
+ )
254
+ expect(subject.created_at).to eq Time.new(2020, 1, 2, 12, 34, 56, 0)
255
+ end
256
+ end
257
+
258
+ describe '.list' do
259
+ subject { described_class.list('instance-uuid') }
260
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts' }
261
+
262
+ describe 'With default parameters' do
263
+ before :each do
264
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
265
+ .and_yield(body_list)
266
+ end
267
+
268
+ its('count') { should eq 1 }
269
+ its('first.created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
270
+ its('first.fqdn') { should eq 'vh.example.com' }
271
+ its('first.is_a_test_virtual_host') { should be false }
272
+ its('first.linked_dns_zone.allow_alteration') { should be true }
273
+ its('first.linked_dns_zone.status') { should eq :unknown }
274
+ its('first.linked_dns_zone.last_checked_at') { should eq Time.new(2020, 2, 3, 23, 45, 56, 0) }
275
+ its('first.status') { should eq :running }
276
+ its('first.application.name') { should eq 'app-name' }
277
+ its('first.application.status') { should eq :being_created }
278
+ its('first.application.parameters') { should eq({}) }
279
+ its('first.certificates') { should eq({ 'cert-id' => true }) }
280
+ its('first.https_strategy') { should eq :redirect_http_to_https }
281
+ end
282
+
283
+ describe 'Passes optional query params' do
284
+ %i[fqdn status sort_by].each do |param|
285
+ it param do
286
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 'value' })
287
+ .and_return([nil, []])
288
+ described_class.list('instance-uuid', param => 'value')
289
+ end
290
+ end
291
+ end
292
+ end
293
+
294
+ describe '.fetch' do
295
+ subject { described_class.fetch 'instance-uuid', 'vh.example.com' }
296
+
297
+ before :each do
298
+ url = 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/vhosts/vh.example.com'
299
+ expect(GandiV5).to receive(:get).with(url)
300
+ .and_return([nil, body_fetch])
301
+ end
302
+
303
+ its('created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
304
+ its('fqdn') { should eq 'vh.example.com' }
305
+ its('is_a_test_virtual_host') { should be false }
306
+ its('linked_dns_zone.allow_alteration') { should be true }
307
+ its('linked_dns_zone.cname') { should eq 'cn' }
308
+ its('linked_dns_zone.domain') { should eq 'example.com' }
309
+ its('linked_dns_zone.ipv4') { should eq '1.2.3.4' }
310
+ its('linked_dns_zone.ipv6') { should eq '1:2::3:4' }
311
+ its('linked_dns_zone.is_alterable') { should be true }
312
+ its('linked_dns_zone.is_root') { should be true }
313
+ its('linked_dns_zone.key') { should eq 'www' }
314
+ its('linked_dns_zone.txt') { should eq 'abcd1234' }
315
+ its('linked_dns_zone.status') { should eq :unknown }
316
+ its('linked_dns_zone.last_checked_at') { should eq Time.new(2020, 2, 3, 23, 45, 56, 0) }
317
+ its('status') { should eq :running }
318
+ its('application.name') { should eq 'app-name' }
319
+ its('application.status') { should eq :being_created }
320
+ its('application.parameters') { should eq({}) }
321
+ its('certificates') { should eq({ 'cert-id' => true }) }
322
+ its('https_strategy') { should eq :redirect_http_to_https }
323
+ end
324
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::SimpleHosting::Instance do
4
+ let :body_list do
5
+ YAML.load_file(
6
+ File.expand_path(
7
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance', 'list.yml')
8
+ )
9
+ )
10
+ end
11
+ let :body_fetch do
12
+ YAML.load_file(
13
+ File.expand_path(
14
+ File.join('spec', 'fixtures', 'bodies', 'GandiV5_SimpleHosting_Instance', 'fetch.yml')
15
+ )
16
+ )
17
+ end
18
+
19
+ subject do
20
+ described_class.new uuid: 'instance-uuid'
21
+ end
22
+
23
+ describe 'Actions' do
24
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances/instance-uuid/action' }
25
+
26
+ %i[restart console reset_database_password].each do |action|
27
+ it ".#{action}" do
28
+ expect(GandiV5).to receive(:post).with(url, "{\"action\":\"#{action}\"}")
29
+ .and_return([nil, 'Confirmation message'])
30
+ expect(subject.send(action)).to eq 'Confirmation message'
31
+ end
32
+ end
33
+ end
34
+
35
+ it '#refresh' do
36
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/simplehosting/instances/instance-uuid')
37
+ .and_return([nil, body_fetch])
38
+ subject.refresh
39
+ expect(subject.access_information).to_not be nil
40
+ end
41
+
42
+ describe 'Helper methods' do
43
+ describe 'Status' do
44
+ context 'waiting_bill' do
45
+ subject { described_class.new status: :waiting_bill }
46
+ its('waiting_bill?') { should be true }
47
+ its('being_created?') { should be false }
48
+ its('active?') { should be false }
49
+ its('paused?') { should be false }
50
+ its('locked?') { should be false }
51
+ its('being_deleted?') { should be false }
52
+ end
53
+ context 'being_created' do
54
+ subject { described_class.new status: :being_created }
55
+ its('waiting_bill?') { should be false }
56
+ its('being_created?') { should be true }
57
+ its('active?') { should be false }
58
+ its('paused?') { should be false }
59
+ its('locked?') { should be false }
60
+ its('being_deleted?') { should be false }
61
+ end
62
+ context 'active' do
63
+ subject { described_class.new status: :active }
64
+ its('waiting_bill?') { should be false }
65
+ its('being_created?') { should be false }
66
+ its('active?') { should be true }
67
+ its('paused?') { should be false }
68
+ its('locked?') { should be false }
69
+ its('being_deleted?') { should be false }
70
+ end
71
+ context 'paused' do
72
+ subject { described_class.new status: :paused }
73
+ its('waiting_bill?') { should be false }
74
+ its('being_created?') { should be false }
75
+ its('active?') { should be false }
76
+ its('paused?') { should be true }
77
+ its('locked?') { should be false }
78
+ its('being_deleted?') { should be false }
79
+ end
80
+ context 'locked' do
81
+ subject { described_class.new status: :locked }
82
+ its('waiting_bill?') { should be false }
83
+ its('being_created?') { should be false }
84
+ its('active?') { should be false }
85
+ its('paused?') { should be false }
86
+ its('locked?') { should be true }
87
+ its('being_deleted?') { should be false }
88
+ end
89
+ context 'being_deleted' do
90
+ subject { described_class.new status: :being_deleted }
91
+ its('waiting_bill?') { should be false }
92
+ its('being_created?') { should be false }
93
+ its('active?') { should be false }
94
+ its('paused?') { should be false }
95
+ its('locked?') { should be false }
96
+ its('being_deleted?') { should be true }
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '.list' do
102
+ subject { described_class.list }
103
+ let(:url) { 'https://api.gandi.net/v5/simplehosting/instances' }
104
+
105
+ describe 'With default parameters' do
106
+ before :each do
107
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: {})
108
+ .and_yield(body_list)
109
+ end
110
+
111
+ its('count') { should eq 1 }
112
+ its('first.created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56) }
113
+ its('first.database.name') { should eq 'database name' }
114
+ its('first.database.status') { should eq 'database status' }
115
+ its('first.database.version') { should eq 'database version' }
116
+ its('first.data_center') { should eq 'FR-SD5' }
117
+ its('first.expire_at') { should eq Time.new(2021, 1, 2, 12, 34, 56) }
118
+ its('first.uuid') { should eq 'instance-uuid' }
119
+ its('first.language.name') { should eq 'ruby' }
120
+ its('first.language.single_application') { should be true }
121
+ its('first.language.status') { should eq 'great' }
122
+ its('first.language.version') { should eq '2.7' }
123
+ its('first.name') { should eq 'instance name' }
124
+ its('first.sharing_space.uuid') { should eq 'sharing-space-uuid' }
125
+ its('first.sharing_space.name') { should eq 'sharing space name' }
126
+ its('first.size') { should eq 's+' }
127
+ its('first.snapshot_enabled') { should be true }
128
+ its('first.status') { should eq 'active' }
129
+ its('first.storage') { should eq({ base: '20 GB', additional: '10 GB', total: '30 GB' }) }
130
+ its('first.auto_renew') { should eq '1 m' }
131
+ end
132
+
133
+ describe 'Passes optional query params' do
134
+ %i[sharing_id name fqdn size status sort_by].each do |param|
135
+ it param do
136
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100, params: { param => 'value' })
137
+ .and_return([nil, []])
138
+ described_class.list(param => 'value')
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ describe '.fetch' do
145
+ subject { described_class.fetch 'instance-uuid' }
146
+
147
+ before :each do
148
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/simplehosting/instances/instance-uuid')
149
+ .and_return([nil, body_fetch])
150
+ end
151
+
152
+ its('access_information') { should be_a Hash }
153
+ its('created_at') { should eq Time.new(2020, 1, 2, 12, 34, 56, 0) }
154
+ its('database.name') { should eq 'database name' }
155
+ its('database.status') { should eq 'database status' }
156
+ its('database.version') { should eq 'database version' }
157
+ its('data_center') { should eq 'FR-SD5' }
158
+ its('expire_at') { should eq Time.new(2021, 1, 2, 12, 34, 56, 0) }
159
+ its('uuid') { should eq 'instance-uuid' }
160
+ its('is_trial') { should be false }
161
+ its('language.name') { should eq 'ruby' }
162
+ its('language.single_application') { should be true }
163
+ its('language.status') { should eq 'great' }
164
+ its('language.version') { should eq '2.7' }
165
+ its('name') { should eq 'instance name' }
166
+ its('sharing_space.uuid') { should eq 'sharing-space-uuid' }
167
+ its('sharing_space.name') { should eq 'sharing space name' }
168
+ its('size') { should eq 's+' }
169
+ its('snapshot_enabled') { should be true }
170
+ its('status') { should eq 'active' }
171
+ its('storage') { should eq({ base: '20 GB', additional: '10 GB', total: '30 GB' }) }
172
+ its('virtual_hosts.first.fqdn') { should eq 'vhost1.example.com' }
173
+ its('auto_renew') { should eq '1 m' }
174
+ its('compatible_applications.first.name') { should eq 'compatable name' }
175
+ its('compatible_applications.first.parameters') { should be_a Hash }
176
+ its('password_updated_at') { should eq Time.new(2020, 6, 2, 12, 34, 56, 0) }
177
+ its('upgrade_to.first.name') { should eq 'upgrade to name' }
178
+ its('upgrade_to.first.status') { should eq 'upgrade to status' }
179
+ its('upgrade_to.first.type') { should eq 'database' }
180
+ its('upgrade_to.first.version') { should eq 'upgrade to version' }
181
+ end
182
+
183
+ it '.create_virtual_host' do
184
+ returns = double Object
185
+ expect(GandiV5::SimpleHosting::Instance::VirtualHost).to receive(:create).with('instance-uuid', 'fqdn', key: :value)
186
+ .and_return(returns)
187
+ expect(subject).to receive(:refresh)
188
+ subject.create_virtual_host 'fqdn', key: :value
189
+ end
190
+ end