gandi_v5 0.8.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -9
- data/README.md +64 -15
- data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
- data/lib/gandi_v5/data/converter/array_of.rb +3 -2
- data/lib/gandi_v5/data/converter/integer.rb +3 -2
- data/lib/gandi_v5/data/converter/symbol.rb +3 -2
- data/lib/gandi_v5/data/converter/time.rb +3 -2
- data/lib/gandi_v5/data/converter.rb +3 -2
- data/lib/gandi_v5/data.rb +13 -14
- data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
- data/lib/gandi_v5/domain/contact.rb +5 -5
- data/lib/gandi_v5/domain/tld.rb +2 -2
- data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
- data/lib/gandi_v5/domain/transfer_in.rb +172 -0
- data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
- data/lib/gandi_v5/domain.rb +52 -13
- data/lib/gandi_v5/email/forward.rb +1 -1
- data/lib/gandi_v5/email/mailbox.rb +6 -6
- data/lib/gandi_v5/email/slot.rb +1 -1
- data/lib/gandi_v5/email.rb +3 -0
- data/lib/gandi_v5/error/gandi_error.rb +1 -0
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +16 -11
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +5 -1
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +8 -5
- data/lib/gandi_v5/live_dns/domain.rb +29 -1
- data/lib/gandi_v5/live_dns.rb +2 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +1 -1
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +2 -1
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +90 -5
- data/lib/gandi_v5/simple_hosting/instance.rb +9 -0
- data/lib/gandi_v5/simple_hosting.rb +1 -0
- data/lib/gandi_v5/template/dispatch.rb +109 -0
- data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
- data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
- data/lib/gandi_v5/template/payload.rb +64 -0
- data/lib/gandi_v5/template.rb +271 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/lib/gandi_v5.rb +115 -66
- data/spec/.rubocop.yml +3 -50
- data/spec/features/list_domain_renewals_spec.rb +16 -0
- data/spec/features/list_email_addresses_spec.rb +39 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
- data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
- data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
- data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
- data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
- data/spec/spec_helper.rb +8 -7
- data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
- data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
- data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
- data/spec/units/gandi_v5/domain_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +125 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +8 -0
- data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
- data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
- data/spec/units/gandi_v5/template_spec.rb +341 -0
- data/spec/units/gandi_v5_spec.rb +1 -1
- metadata +191 -57
- data/.gitignore +0 -26
- data/.rspec +0 -3
- data/.rubocop.yml +0 -74
- data/.travis.yml +0 -38
- data/FUNDING.yml +0 -10
- data/Gemfile +0 -6
- data/Guardfile +0 -39
- data/Rakefile +0 -3
- data/bin/console +0 -13
- data/gandi_v5.gemspec +0 -42
- data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
- data/spec/units/gandi_v5/error_spec.rb +0 -4
- data/spec/units/gandi_v5/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +0 -4
@@ -21,6 +21,7 @@ class GandiV5
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Update this domain's settings.
|
24
|
+
# @see https://api.gandi.net/docs/livedns/#patch-v5-livedns-domains-fqdn
|
24
25
|
# @param automatic_snapshots [String, #to_s]
|
25
26
|
# Enable or disable the automatic creation of new snapshots when records are changed.
|
26
27
|
# @return [String] The confirmation message from Gandi.
|
@@ -33,12 +34,14 @@ class GandiV5
|
|
33
34
|
|
34
35
|
# @overload fetch_records()
|
35
36
|
# Fetch all records for this domain.
|
37
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records
|
36
38
|
# @param page [Integer, #each<Integer>] which page(s) of results to get.
|
37
39
|
# If page is not provided keep querying until an empty list is returned.
|
38
40
|
# If page responds to .each then iterate until an empty list is returned.
|
39
41
|
# @param per_page [Integer, #to_s] (optional default 100) how many results ot get per page.
|
40
42
|
# @overload fetch_records(name)
|
41
43
|
# Fetch records for a name.
|
44
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records-rrset_name
|
42
45
|
# @param name [String] the name to fetch records for.
|
43
46
|
# @param page [Integer, #each<Integer>] which page(s) of results to get.
|
44
47
|
# If page is not provided keep querying until an empty list is returned.
|
@@ -46,6 +49,7 @@ class GandiV5
|
|
46
49
|
# @param per_page [Integer, #to_s] (optional default 100) how many results ot get per page.
|
47
50
|
# @overload fetch_records(name, type)
|
48
51
|
# Fetch records of a type for a name.
|
52
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records-rrset_name-rrset_type
|
49
53
|
# @param name [String] the name to fetch records for.
|
50
54
|
# @param type [String] the record type to fetch.
|
51
55
|
# @param page [Integer, #each<Integer>] which page(s) of results to get.
|
@@ -70,11 +74,15 @@ class GandiV5
|
|
70
74
|
|
71
75
|
# @overload fetch_zone_lines()
|
72
76
|
# Fetch all records for this domain.
|
77
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records
|
78
|
+
# @see https://rubygems.org/gems/dns-zonefile dns-zonefile gem may be helpful too
|
73
79
|
# @overload fetch_zone_lines(name)
|
74
80
|
# Fetch records for a name.
|
81
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records-rrset_name
|
75
82
|
# @param name [String] the name to fetch records for.
|
76
83
|
# @overload fetch_zone_lines(name, type)
|
77
84
|
# Fetch records of a type for a name.
|
85
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-records-rrset_name-rrset_type
|
78
86
|
# @param name [String] the name to fetch records for.
|
79
87
|
# @param type [String] the record type to fetch.
|
80
88
|
# @return [String]
|
@@ -90,6 +98,7 @@ class GandiV5
|
|
90
98
|
end
|
91
99
|
|
92
100
|
# Add record to this domain.
|
101
|
+
# @see https://api.gandi.net/docs/livedns/#post-v5-livedns-domains-fqdn-records
|
93
102
|
# @param name [String]
|
94
103
|
# @param type [String]
|
95
104
|
# @param ttl [Integer]
|
@@ -113,11 +122,14 @@ class GandiV5
|
|
113
122
|
|
114
123
|
# @overload delete_records()
|
115
124
|
# Delete all records for this domain.
|
125
|
+
# @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-records
|
116
126
|
# @overload delete_records(name)
|
117
127
|
# Delete records for a name.
|
128
|
+
# @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-records-rrset_name
|
118
129
|
# @param name [String] the name to delete records for.
|
119
130
|
# @overload delete_records(name, type)
|
120
131
|
# Delete records of a type for a name.
|
132
|
+
# @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-records-rrset_name-rrset_type
|
121
133
|
# @param name [String] the name to delete records for.
|
122
134
|
# @param type [String] the record type to delete.
|
123
135
|
# @return [nil]
|
@@ -136,6 +148,9 @@ class GandiV5
|
|
136
148
|
# @param type [String, nil] only replaces record of this type (requires name).
|
137
149
|
# @param values [Array<String>] the values to set for the record.
|
138
150
|
# @raise [ArgumentError] if ttl is present and type is absent.
|
151
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-records
|
152
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-records-rrset_name
|
153
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-records-rrset_name-rrset_type
|
139
154
|
# @return [String] The confirmation message from Gandi.
|
140
155
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
141
156
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
@@ -161,6 +176,7 @@ class GandiV5
|
|
161
176
|
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
162
177
|
|
163
178
|
# Replace all records for this domain.
|
179
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-records
|
164
180
|
# @param text [String] zone file lines to replace the records with.
|
165
181
|
# @return [String] The confirmation message from Gandi.
|
166
182
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
@@ -199,6 +215,7 @@ class GandiV5
|
|
199
215
|
end
|
200
216
|
|
201
217
|
# Requery Gandi for the domain's DNSSEC keys.
|
218
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-keys
|
202
219
|
# @return [Array<GandiV5::LiveDNS::Domain::DnssecKey>]
|
203
220
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
204
221
|
def fetch_dnssec_keys
|
@@ -215,6 +232,7 @@ class GandiV5
|
|
215
232
|
end
|
216
233
|
|
217
234
|
# Requery Gandi for the domain's TSIG keys.
|
235
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-axfr-tsig
|
218
236
|
# @return [Array<GandiV5::LiveDNS::Domain::TsigKey>]
|
219
237
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
220
238
|
def fetch_tsig_keys
|
@@ -223,6 +241,7 @@ class GandiV5
|
|
223
241
|
end
|
224
242
|
|
225
243
|
# Add a Tsig key to this domain.
|
244
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-axfr-tsig-id
|
226
245
|
# @param key [GandiV5::LiveDNS::Domain::TsigKey, #uuid, String, #to_s]
|
227
246
|
# the key to add.
|
228
247
|
# @param sharing_id [nil, String, #to_s]
|
@@ -235,6 +254,7 @@ class GandiV5
|
|
235
254
|
end
|
236
255
|
|
237
256
|
# Remove a Tsig key from this domain.
|
257
|
+
# @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-axfr-tsig-id
|
238
258
|
# @param key [GandiV5::LiveDNS::Domain::TsigKey, #uuid, String, #to_s]
|
239
259
|
# the key to remove.
|
240
260
|
# @param sharing_id [nil, String, #to_s]
|
@@ -254,6 +274,7 @@ class GandiV5
|
|
254
274
|
end
|
255
275
|
|
256
276
|
# Requery Gandi for the domain's AXFR clients.
|
277
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-axfr-slaves
|
257
278
|
# @return [Array<String>] list of IP addresses.
|
258
279
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
259
280
|
def fetch_axfr_clients
|
@@ -262,6 +283,7 @@ class GandiV5
|
|
262
283
|
end
|
263
284
|
|
264
285
|
# Add an AXFR client to this domain.
|
286
|
+
# @see https://api.gandi.net/docs/livedns/#put-v5-livedns-domains-fqdn-axfr-slaves-ip
|
265
287
|
# @param ip [String, #to_s] the IP address to add.
|
266
288
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
267
289
|
def add_axfr_client(ip)
|
@@ -269,6 +291,7 @@ class GandiV5
|
|
269
291
|
end
|
270
292
|
|
271
293
|
# Remove and AXFR client from this domain.
|
294
|
+
# @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-axfr-slaves-ip
|
272
295
|
# @param ip [String, #to_s] the IP address to remove.
|
273
296
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
274
297
|
def remove_axfr_client(ip)
|
@@ -276,6 +299,7 @@ class GandiV5
|
|
276
299
|
end
|
277
300
|
|
278
301
|
# List the domains.
|
302
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains
|
279
303
|
# @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
|
280
304
|
# If page is not provided keep querying until an empty list is returned.
|
281
305
|
# If page responds to .each then iterate until an empty list is returned.
|
@@ -300,6 +324,7 @@ class GandiV5
|
|
300
324
|
end
|
301
325
|
|
302
326
|
# Get a domain.
|
327
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn
|
303
328
|
# @param fqdn [String, #to_s] the fully qualified domain name to fetch.
|
304
329
|
# @return [GandiV5::LiveDNS::Domain]
|
305
330
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
@@ -310,6 +335,7 @@ class GandiV5
|
|
310
335
|
|
311
336
|
# Create a new domain in the LiveDNS system.
|
312
337
|
# You must have sufficent permission to manage the domain to do this.
|
338
|
+
# @see https://api.gandi.net/docs/livedns/#post-v5-livedns-domains
|
313
339
|
# @param fqdn [String, #to_s] the fully qualified domain to add to LiveDNS.
|
314
340
|
# @param records [Array<Hash, GandiV5::LiveDNS::Domain::Record, #to_h, nil>]
|
315
341
|
# @param ttl [Integer, #to_s, nil] the TTL of the SOA record.
|
@@ -335,6 +361,7 @@ class GandiV5
|
|
335
361
|
end
|
336
362
|
|
337
363
|
# Fetch the list of known record types (A, CNAME, etc.)
|
364
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-dns-rrtypes
|
338
365
|
# @return [Array<String>]
|
339
366
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
340
367
|
def self.record_types
|
@@ -342,7 +369,8 @@ class GandiV5
|
|
342
369
|
end
|
343
370
|
|
344
371
|
# Get the LiveDNS servers to use for a domain.
|
345
|
-
# Does not take into account any NS records that exist in the zone.
|
372
|
+
# @note Does not take into account any NS records that exist in the zone.
|
373
|
+
# @see https://api.gandi.net/docs/livedns/#get-v5-livedns-nameservers-fqdn
|
346
374
|
# @param fqdn [String, #to_s] the fully qualified domain to hash in
|
347
375
|
# in order to get the LiveDNS servers to use.
|
348
376
|
# @return [Array<String>]
|
data/lib/gandi_v5/live_dns.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Namespace for classes which access LiveDNS details.
|
4
|
+
# @see https://api.gandi.net/docs/livedns/
|
4
5
|
class GandiV5
|
5
6
|
# Gandi LiveDNS Management API.
|
6
7
|
class LiveDNS
|
8
|
+
# Permitted record types.
|
7
9
|
RECORD_TYPES = %w[
|
8
10
|
A AAAA CNAME MX NS TXT ALIAS
|
9
11
|
WKS SRV LOC SPF CAA DS SSHFP PTR KEY DNAME TLSA OPENPGPKEY CDS
|
@@ -4,7 +4,8 @@ class GandiV5
|
|
4
4
|
class SimpleHosting
|
5
5
|
class Instance
|
6
6
|
class VirtualHost
|
7
|
-
#
|
7
|
+
# A DNS Zone linked to a virtual host on a simple hosting instance.
|
8
|
+
# @!attribute [r] allow_alteration
|
8
9
|
# @return [Boolean]
|
9
10
|
# @!attribute [r] cname
|
10
11
|
# @return [String]
|
@@ -4,7 +4,7 @@
|
|
4
4
|
class GandiV5
|
5
5
|
class SimpleHosting
|
6
6
|
class Instance
|
7
|
-
# A simple hosting
|
7
|
+
# A virtual host on a simple hosting instance.
|
8
8
|
# @see https://api.gandi.net/docs/simplehosting/
|
9
9
|
# @!attribute [r] created_at
|
10
10
|
# @return [Time]
|
@@ -48,7 +48,7 @@ class GandiV5
|
|
48
48
|
member(
|
49
49
|
:certificates,
|
50
50
|
converter: GandiV5::Data::Converter.new(
|
51
|
-
from_gandi: ->(array) {
|
51
|
+
from_gandi: ->(array) { array.map { |h| [h['id'], h['pending']] }.to_h }
|
52
52
|
)
|
53
53
|
)
|
54
54
|
|
@@ -57,7 +57,7 @@ class GandiV5
|
|
57
57
|
converter: GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone
|
58
58
|
)
|
59
59
|
|
60
|
-
# Requery Gandi fo this hosts's information.
|
60
|
+
# Requery Gandi fo this virtual hosts's information.
|
61
61
|
# @return [GandiV5::SimpleHosting::Instance::VirtualHost]
|
62
62
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
63
63
|
def refresh
|
@@ -65,6 +65,59 @@ class GandiV5
|
|
65
65
|
from_gandi data
|
66
66
|
end
|
67
67
|
|
68
|
+
# Delete the virtual host.
|
69
|
+
# @see https://api.gandi.net/docs/simplehosting/#delete-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
|
70
|
+
# @return [String] The confirmation message from Gandi.
|
71
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
72
|
+
def delete
|
73
|
+
_response, data = GandiV5.delete url
|
74
|
+
data['message']
|
75
|
+
end
|
76
|
+
|
77
|
+
# Update the virtual host.
|
78
|
+
# @see https://api.gandi.net/docs/simplehosting/#patch-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
|
79
|
+
# @param application [GandiV5::SimpleHosting::Instance::Application, Hash]
|
80
|
+
# @param https_strategy [:http_only, :allow_http_and_https, :redirect_http_to_https]
|
81
|
+
# @param linked_dns_zone_allow_alteration [Boolean]
|
82
|
+
# authorize Gandi to modify your DNS zone so that your vhost points to their
|
83
|
+
# Simple Hosting public endpoints.
|
84
|
+
# @param linked_dns_zone_allow_alteration_override [Boolean]
|
85
|
+
# authorize Gandi to override your DNS zone if there already is a record to
|
86
|
+
# link your instance to your vhost fqdn.
|
87
|
+
# @return [GandiV5::SimpleHosting::Instance::VirtualHost] self.
|
88
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
89
|
+
# rubocop:disable Metrics/MethodLength
|
90
|
+
def update(
|
91
|
+
application: nil,
|
92
|
+
https_strategy: nil,
|
93
|
+
linked_dns_zone_allow_alteration: nil,
|
94
|
+
linked_dns_zone_allow_alteration_override: false
|
95
|
+
)
|
96
|
+
https_strategy = case https_strategy
|
97
|
+
when nil then nil
|
98
|
+
when :http_only then 'HTTP_only'
|
99
|
+
when :allow_http_and_https then 'allow_HTTP_and_HTTPS'
|
100
|
+
when :redirect_http_to_https then 'redirect_HTTP_to_HTTPS'
|
101
|
+
else
|
102
|
+
fail ArgumentError,
|
103
|
+
"https_strategy #{https_strategy.inspect} is invalid"
|
104
|
+
end
|
105
|
+
|
106
|
+
body = {}
|
107
|
+
body[:application] = application.to_h.slice(:name, :parameters) if application
|
108
|
+
body[:https_strategy] = https_strategy if https_strategy
|
109
|
+
unless linked_dns_zone_allow_alteration.nil?
|
110
|
+
body[:linked_dns_zone] = {
|
111
|
+
allow_alteration: linked_dns_zone_allow_alteration,
|
112
|
+
allow_alteration_override: linked_dns_zone_allow_alteration_override
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
_response, data = GandiV5.put url, body.to_json
|
117
|
+
from_gandi data
|
118
|
+
end
|
119
|
+
# rubocop:enable Metrics/MethodLength
|
120
|
+
|
68
121
|
# Check if the virtual host is being created
|
69
122
|
# @return [Boolean]
|
70
123
|
def being_created?
|
@@ -139,7 +192,7 @@ class GandiV5
|
|
139
192
|
|
140
193
|
# Get information on a virtual host.
|
141
194
|
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
|
142
|
-
# @param
|
195
|
+
# @param instance_uuid [String, #to_s] the UUID of the simple hosting instance.
|
143
196
|
# @param fqdn [String, #to_s] the fully qualified domain name of the virtual host.
|
144
197
|
# @return [GandiV5::SimpleHosting::Instance]
|
145
198
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
@@ -148,7 +201,39 @@ class GandiV5
|
|
148
201
|
from_gandi data.merge('instance_uuid' => instance_uuid)
|
149
202
|
end
|
150
203
|
|
151
|
-
#
|
204
|
+
# Create a new virtual host for an instance
|
205
|
+
# @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-vhosts
|
206
|
+
# @param fqdn [String, #to_s] the fully qualified domain of the virtual host to create.
|
207
|
+
# @param application [GandiV5::SimpleHosting::Instance::Application, Hash]
|
208
|
+
# @param linked_dns_zone_allow_alteration [Boolean]
|
209
|
+
# authorize Gandi to modify your DNS zone so that your vhost points to their
|
210
|
+
# Simple Hosting public endpoints.
|
211
|
+
# @param linked_dns_zone_allow_alteration_override [Boolean]
|
212
|
+
# authorize Gandi to override your DNS zone if there already is a record to
|
213
|
+
# link your instance to your vhost fqdn.
|
214
|
+
# @return [GandiV5::SimpleHosting::Instance::VirtualHost]
|
215
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
216
|
+
def self.create(
|
217
|
+
instance_uuid,
|
218
|
+
fqdn,
|
219
|
+
application: nil,
|
220
|
+
linked_dns_zone_allow_alteration: nil,
|
221
|
+
linked_dns_zone_allow_alteration_override: false
|
222
|
+
)
|
223
|
+
body = { fqdn: fqdn }
|
224
|
+
body[:application] = application.to_h.slice(:name, :parameters) if application
|
225
|
+
unless linked_dns_zone_allow_alteration.nil?
|
226
|
+
body[:linked_dns_zone] = {
|
227
|
+
allow_alteration: linked_dns_zone_allow_alteration,
|
228
|
+
allow_alteration_override: linked_dns_zone_allow_alteration_override
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
_response, _data = GandiV5.post url(instance_uuid), body.to_json
|
233
|
+
fetch instance_uuid, fqdn
|
234
|
+
end
|
235
|
+
|
236
|
+
# List virtual hosts for an instance.
|
152
237
|
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts
|
153
238
|
# @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
|
154
239
|
# If page is not provided keep querying until an empty list is returned.
|
@@ -117,6 +117,7 @@ class GandiV5
|
|
117
117
|
)
|
118
118
|
|
119
119
|
# Instruct Gandi to restart this instance.
|
120
|
+
# @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
|
120
121
|
# @return [String] confirmation message.
|
121
122
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
122
123
|
def restart
|
@@ -125,6 +126,7 @@ class GandiV5
|
|
125
126
|
end
|
126
127
|
|
127
128
|
# Instruct Gandi to console this instance.
|
129
|
+
# @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
|
128
130
|
# @return [String] confirmation message.
|
129
131
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
130
132
|
def console
|
@@ -133,6 +135,7 @@ class GandiV5
|
|
133
135
|
end
|
134
136
|
|
135
137
|
# Instruct Gandi to reset the database password for this instance.
|
138
|
+
# @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
|
136
139
|
# @return [String] confirmation message.
|
137
140
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
138
141
|
def reset_database_password
|
@@ -143,6 +146,12 @@ class GandiV5
|
|
143
146
|
data
|
144
147
|
end
|
145
148
|
|
149
|
+
# @see GandiV5::SimpleHosting::Instance::VirtualHost.create
|
150
|
+
def create_virtual_host(fqdn, **params)
|
151
|
+
GandiV5::SimpleHosting::Instance::VirtualHost.create(uuid, fqdn, **params)
|
152
|
+
refresh
|
153
|
+
end
|
154
|
+
|
146
155
|
# Requery Gandi fo this instance's information.
|
147
156
|
# @return [GandiV5::SimpleHosting::Instance]
|
148
157
|
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class Template
|
5
|
+
# The current state of a template dispatch.
|
6
|
+
# @!attribute [r] uuid
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] template_uuid
|
9
|
+
# @return [String, nil]
|
10
|
+
# @!attribute [r] template_name
|
11
|
+
# @return [String, nil]
|
12
|
+
# @!attribute [r] target_uuid
|
13
|
+
# @return [String]
|
14
|
+
# @!attribute [r] attempt
|
15
|
+
# @return [Integer]
|
16
|
+
# @!attribute [r] created_at
|
17
|
+
# @return [Time]
|
18
|
+
# @!attribute [r] created_by
|
19
|
+
# @return [String] the UUID of the user who applied the template.
|
20
|
+
# @!attribute [r] updated_at
|
21
|
+
# @return [Time, nil]
|
22
|
+
# @!attribute [r] state
|
23
|
+
# @return [:pending, :running, :done, :error]
|
24
|
+
# @!attribute [r] state_message
|
25
|
+
# @return [String, nil]
|
26
|
+
# @!attribute [r] task_statuses
|
27
|
+
# @return [Array<Hash{Symbol => Synbol}>]
|
28
|
+
# maps namespace (e.g. :dns_records) to current status (e.g. :done)
|
29
|
+
# @!attribute [r] task_history
|
30
|
+
# @return [Array<Hash{:at => Time, :what => Symbol, :status => Symbol, :message => String}>]
|
31
|
+
# @!attribute [r] payload
|
32
|
+
# @return [Array<GandiV5::Template::Payload] the settings which will be applied
|
33
|
+
# when this template is used.
|
34
|
+
class Dispatch
|
35
|
+
include GandiV5::Data
|
36
|
+
|
37
|
+
members :attempt, :template_name
|
38
|
+
member :uuid, gandi_key: 'id'
|
39
|
+
member :template_uuid, gandi_key: 'template_id'
|
40
|
+
member :created_at, converter: GandiV5::Data::Converter::Time
|
41
|
+
member :created_by, gandi_key: 'sharing_id'
|
42
|
+
member :target_uuid, gandi_key: 'target_id'
|
43
|
+
member :state_message, gandi_key: 'state_msg'
|
44
|
+
member :updated_at, gandi_key: 'task_updated_at', converter: GandiV5::Data::Converter::Time
|
45
|
+
member :payload, converter: GandiV5::Template::Payload
|
46
|
+
|
47
|
+
member(
|
48
|
+
:state,
|
49
|
+
converter: GandiV5::Data::Converter.new(
|
50
|
+
from_gandi: lambda { |value|
|
51
|
+
values = { 0 => :pending, 10 => :running, 20 => :done, 30 => :error }
|
52
|
+
values.fetch(value)
|
53
|
+
}
|
54
|
+
)
|
55
|
+
)
|
56
|
+
|
57
|
+
member(
|
58
|
+
:task_statuses,
|
59
|
+
gandi_key: 'task_status',
|
60
|
+
converter: GandiV5::Data::Converter.new(
|
61
|
+
from_gandi: lambda { |hash|
|
62
|
+
keys = {
|
63
|
+
'dns:records' => :dns_records,
|
64
|
+
'domain:mailboxes' => :mailboxes,
|
65
|
+
'domain:nameservers' => :name_servers,
|
66
|
+
'domain:webredirs' => :web_forwardings
|
67
|
+
}
|
68
|
+
values = { 0 => :pending, 10 => :running, 20 => :done, 30 => :error }
|
69
|
+
hash.transform_keys { |key| keys.fetch(key) }
|
70
|
+
.transform_values { |value| values.fetch(value.fetch('status')) }
|
71
|
+
}
|
72
|
+
)
|
73
|
+
)
|
74
|
+
|
75
|
+
member(
|
76
|
+
:task_history,
|
77
|
+
converter: GandiV5::Data::Converter.new(
|
78
|
+
from_gandi: lambda { |array|
|
79
|
+
namespace = {
|
80
|
+
'dns:records' => :dns_records,
|
81
|
+
'domain:mailboxes' => :mailboxes,
|
82
|
+
'domain:nameservers' => :name_servers,
|
83
|
+
'domain:webredirs' => :web_forwardings
|
84
|
+
}
|
85
|
+
status = { 0 => :pending, 10 => :running, 20 => :done, 30 => :error }
|
86
|
+
array.map do |item|
|
87
|
+
{
|
88
|
+
at: Time.parse(item.fetch('date')),
|
89
|
+
what: namespace.fetch(item.fetch('namespace')),
|
90
|
+
status: status.fetch(item.fetch('status')),
|
91
|
+
message: item.fetch('message')
|
92
|
+
}
|
93
|
+
end
|
94
|
+
}
|
95
|
+
)
|
96
|
+
)
|
97
|
+
|
98
|
+
# Get a template dispatch.
|
99
|
+
# @see https://api.gandi.net/docs/template/#get-v5-template-dispatch-id
|
100
|
+
# @param uuid [String, #to_s] unique identifier of the dispatch.
|
101
|
+
# @return [GandiV5::Template::Dispatch]
|
102
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
103
|
+
def self.fetch(uuid)
|
104
|
+
_response, data = GandiV5.get "#{BASE}template/dispatch/#{CGI.escape uuid}"
|
105
|
+
from_gandi data
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class Template
|
5
|
+
class Payload
|
6
|
+
# DNS Record details of a configuration template.
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] type
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] values
|
12
|
+
# @return [Array<String>]
|
13
|
+
# @!attribute [r] ttl
|
14
|
+
# @return [Integer, nil] 300-2592000.
|
15
|
+
class DNSRecord
|
16
|
+
include GandiV5::Data
|
17
|
+
|
18
|
+
members :name, :type, :ttl
|
19
|
+
member :values, array: true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class Template
|
5
|
+
class Payload
|
6
|
+
# Web forwarding details of a configuration template.
|
7
|
+
# @!attribute [r] type
|
8
|
+
# @return [:cloak, :http301, :http302]
|
9
|
+
# @!attribute [r] target
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] fqdn
|
12
|
+
# @return [String, nil]
|
13
|
+
# @!attribute [r] override
|
14
|
+
# @return [Boolean, nil]
|
15
|
+
# when you create a redirection on a domain, a DNS record is created if it does not exist.
|
16
|
+
# When the record already exists and this parameter is set to true it will
|
17
|
+
# overwrite the record. Otherwise it will trigger an error.
|
18
|
+
# @!attribute [r] protocol
|
19
|
+
# @return [:http, :https, :https_only, nil]
|
20
|
+
class WebForwarding
|
21
|
+
include GandiV5::Data
|
22
|
+
|
23
|
+
member :type, converter: GandiV5::Data::Converter::Symbol
|
24
|
+
member :target, gandi_key: 'url'
|
25
|
+
member :fqdn, gandi_key: 'host'
|
26
|
+
member :override
|
27
|
+
member(
|
28
|
+
:protocol,
|
29
|
+
converter: GandiV5::Data::Converter.new(
|
30
|
+
from_gandi: lambda { |value|
|
31
|
+
{
|
32
|
+
'http' => :http,
|
33
|
+
'https' => :https,
|
34
|
+
'httpsonly' => :https_only
|
35
|
+
}.fetch(value)
|
36
|
+
}
|
37
|
+
)
|
38
|
+
)
|
39
|
+
|
40
|
+
# Check if this is an HTTP 301 (permanent) redirection.
|
41
|
+
def http301?
|
42
|
+
type == :http301
|
43
|
+
end
|
44
|
+
|
45
|
+
# Check if this is an HTTP 302 (found) redirection.
|
46
|
+
def http302?
|
47
|
+
type == :http302
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check if this is an HTTP 301 (permanent) redirection.
|
51
|
+
def permanent?
|
52
|
+
type == :http301
|
53
|
+
end
|
54
|
+
|
55
|
+
# Check if this is an HTTP 302 (found) redirection.
|
56
|
+
def found?
|
57
|
+
type == :http302
|
58
|
+
end
|
59
|
+
|
60
|
+
# Check if this is a temporary redirection.
|
61
|
+
def temporary?
|
62
|
+
type == :http302
|
63
|
+
end
|
64
|
+
|
65
|
+
# Check if it's an http end point
|
66
|
+
def http?
|
67
|
+
protocol == :http || protocol == :https
|
68
|
+
end
|
69
|
+
|
70
|
+
# Check if it's an https end point
|
71
|
+
def https?
|
72
|
+
protocol == :https || protocol == :https_only
|
73
|
+
end
|
74
|
+
|
75
|
+
# Check if it's an https only
|
76
|
+
def https_only?
|
77
|
+
protocol == :https_only
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|