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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +81 -5
- data/README.md +65 -14
- data/lib/gandi_v5.rb +139 -70
- data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
- data/lib/gandi_v5/data.rb +3 -2
- data/lib/gandi_v5/data/converter.rb +3 -2
- 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/domain.rb +55 -18
- 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.rb +172 -0
- data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
- data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
- data/lib/gandi_v5/email.rb +3 -0
- data/lib/gandi_v5/email/forward.rb +3 -9
- data/lib/gandi_v5/email/mailbox.rb +5 -11
- data/lib/gandi_v5/error/gandi_error.rb +1 -0
- data/lib/gandi_v5/live_dns.rb +2 -12
- data/lib/gandi_v5/live_dns/domain.rb +340 -29
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
- data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
- data/lib/gandi_v5/sharing_space.rb +27 -0
- data/lib/gandi_v5/simple_hosting.rb +13 -0
- data/lib/gandi_v5/simple_hosting/instance.rb +251 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +272 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
- data/lib/gandi_v5/template.rb +271 -0
- data/lib/gandi_v5/template/dispatch.rb +109 -0
- data/lib/gandi_v5/template/payload.rb +64 -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/version.rb +1 -1
- data/spec/.rubocop.yml +9 -9
- 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_LiveDNS_Domain/fetch.yml +1 -2
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
- data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
- data/spec/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 +56 -37
- data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
- data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
- data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
- data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
- data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
- data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
- data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
- data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
- data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +324 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +190 -0
- data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -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 +111 -14
- metadata +226 -79
- data/.gitignore +0 -26
- data/.rspec +0 -3
- data/.rubocop.yml +0 -30
- 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/lib/gandi_v5/domain/sharing_space.rb +0 -29
- data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
- data/lib/gandi_v5/live_dns/record_set.rb +0 -79
- data/lib/gandi_v5/live_dns/zone.rb +0 -160
- data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
- data/spec/features/domain_spec.rb +0 -45
- data/spec/features/livedns_domain_spec.rb +0 -8
- data/spec/features/livedns_zone_spec.rb +0 -44
- data/spec/features/mailbox_spec.rb +0 -18
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
- data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
- data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
- data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
- data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
- data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
- data/spec/units/gandi_v5/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/domain/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/error_spec.rb +0 -4
- data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# An application running on a simple hosting instance.
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] parameters
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] status
|
12
|
+
# @return [Symbol] :error, :running, :being_created, :cancelled
|
13
|
+
class Application
|
14
|
+
include GandiV5::Data
|
15
|
+
|
16
|
+
members :name, :parameters
|
17
|
+
member :status, converter: GandiV5::Data::Converter::Symbol
|
18
|
+
|
19
|
+
# Check if the appliaction is currently being created
|
20
|
+
# @return [Boolean]
|
21
|
+
def being_created?
|
22
|
+
status == :being_created
|
23
|
+
end
|
24
|
+
|
25
|
+
# Check if the appliaction has been cancelled
|
26
|
+
# @return [Boolean]
|
27
|
+
def cancelled?
|
28
|
+
status == :cancelled
|
29
|
+
end
|
30
|
+
|
31
|
+
# Check if the appliaction is running
|
32
|
+
# @return [Boolean]
|
33
|
+
def running?
|
34
|
+
status == :running
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check if the appliaction is in an error condition
|
38
|
+
# @return [Boolean]
|
39
|
+
def error?
|
40
|
+
status == :error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# A simple hosting instance.
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] status
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] version
|
12
|
+
# @return [String]
|
13
|
+
class Database
|
14
|
+
include GandiV5::Data
|
15
|
+
|
16
|
+
members :name, :status, :version
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# A language running on a simple hosting instance.
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] single_application
|
10
|
+
# @return [Boolean]
|
11
|
+
# @!attribute [r] status
|
12
|
+
# @return [String]
|
13
|
+
# @!attribute [r] version
|
14
|
+
# @return [String]
|
15
|
+
class Language
|
16
|
+
include GandiV5::Data
|
17
|
+
|
18
|
+
members :name, :single_application, :status, :version
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# An available upgrade on a simple hosting instance.
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] status
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] type
|
12
|
+
# @return [String] "database" or "language"
|
13
|
+
# @!attribute [r] version
|
14
|
+
# @return [String]
|
15
|
+
class Upgrade
|
16
|
+
include GandiV5::Data
|
17
|
+
|
18
|
+
members :name, :status, :type, :version
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for classes which access LiveDNS details.
|
4
|
+
class GandiV5
|
5
|
+
class SimpleHosting
|
6
|
+
class Instance
|
7
|
+
# A virtual host on a simple hosting instance.
|
8
|
+
# @see https://api.gandi.net/docs/simplehosting/
|
9
|
+
# @!attribute [r] created_at
|
10
|
+
# @return [Time]
|
11
|
+
# @!attribute [r] fqdn
|
12
|
+
# @return [String] fully qualified domain name of the virtual host.
|
13
|
+
# @!attribute [r] instance_uuid
|
14
|
+
# @return [String] UUID of the simple hosting instance which 'owns' the host.
|
15
|
+
# @!attribute [r] is_a_test_virtual_host
|
16
|
+
# @return [Boolean]
|
17
|
+
# @!attribute [r] status
|
18
|
+
# @return [Symbol] :being_created, :running, :being_deleted,
|
19
|
+
# :locked, :waiting_ownership, :ownership_validated,
|
20
|
+
# :validation_failed
|
21
|
+
# @!attribute [r] https_strategy
|
22
|
+
# @return [Symbol] :http_only, :allow_http_and_https,
|
23
|
+
# :redirect_http_to_https
|
24
|
+
# @!attribute [r] Application
|
25
|
+
# @return [GandiV5::SimpleHosting::Instance::Application]
|
26
|
+
# @!attribute [r] certificates
|
27
|
+
# @return [Hash<String => Boolean>] Hash - certificate ID to pendingness
|
28
|
+
# @!attribute [r] linked_dns_zone
|
29
|
+
# @return [GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone]
|
30
|
+
class VirtualHost
|
31
|
+
include GandiV5::Data
|
32
|
+
|
33
|
+
members :created_at, :fqdn, :instance_uuid
|
34
|
+
|
35
|
+
member :is_a_test_virtual_host, gandi_key: 'is_a_test_vhost'
|
36
|
+
member :status, converter: GandiV5::Data::Converter::Symbol
|
37
|
+
|
38
|
+
member(
|
39
|
+
:https_strategy,
|
40
|
+
converter: GandiV5::Data::Converter.new(from_gandi: ->(data) { data.downcase.to_sym })
|
41
|
+
)
|
42
|
+
|
43
|
+
member(
|
44
|
+
:application,
|
45
|
+
converter: GandiV5::SimpleHosting::Instance::Application
|
46
|
+
)
|
47
|
+
|
48
|
+
member(
|
49
|
+
:certificates,
|
50
|
+
converter: GandiV5::Data::Converter.new(
|
51
|
+
from_gandi: ->(array) { Hash[array.map { |h| [h['id'], h['pending']] }] }
|
52
|
+
)
|
53
|
+
)
|
54
|
+
|
55
|
+
member(
|
56
|
+
:linked_dns_zone,
|
57
|
+
converter: GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone
|
58
|
+
)
|
59
|
+
|
60
|
+
# Requery Gandi fo this virtual hosts's information.
|
61
|
+
# @return [GandiV5::SimpleHosting::Instance::VirtualHost]
|
62
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
63
|
+
def refresh
|
64
|
+
_response, data = GandiV5.get url
|
65
|
+
from_gandi data
|
66
|
+
end
|
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
|
+
|
121
|
+
# Check if the virtual host is being created
|
122
|
+
# @return [Boolean]
|
123
|
+
def being_created?
|
124
|
+
status == :being_created
|
125
|
+
end
|
126
|
+
|
127
|
+
# Check if the virtual host is running
|
128
|
+
# @return [Boolean]
|
129
|
+
def running?
|
130
|
+
status == :running
|
131
|
+
end
|
132
|
+
|
133
|
+
# Check if the virtual host is being deleted
|
134
|
+
# @return [Boolean]
|
135
|
+
def being_deleted?
|
136
|
+
status == :being_deleted
|
137
|
+
end
|
138
|
+
|
139
|
+
# Check if the virtual host is locked
|
140
|
+
# @return [Boolean]
|
141
|
+
def locked?
|
142
|
+
status == :locked
|
143
|
+
end
|
144
|
+
|
145
|
+
# Check if the virtual host is waiting for an ownership check
|
146
|
+
# @return [Boolean]
|
147
|
+
def waiting_ownership?
|
148
|
+
status == :waiting_ownership
|
149
|
+
end
|
150
|
+
|
151
|
+
# Check if the virtual host has it's ownership validated
|
152
|
+
# @return [Boolean]
|
153
|
+
def ownership_validated?
|
154
|
+
status == :ownership_validated
|
155
|
+
end
|
156
|
+
|
157
|
+
# Check if the virtual host failed it's ownership check
|
158
|
+
# @return [Boolean]
|
159
|
+
def validation_failed?
|
160
|
+
status == :validation_failed
|
161
|
+
end
|
162
|
+
|
163
|
+
# Check if the virtual host is serving HTTP only
|
164
|
+
# @return [Boolean]
|
165
|
+
def http_only?
|
166
|
+
https_strategy == :http_only
|
167
|
+
end
|
168
|
+
|
169
|
+
# Check if the virtual host is serving HTTP and HTTPS
|
170
|
+
# @return [Boolean]
|
171
|
+
def http_and_https?
|
172
|
+
https_strategy == :http_and_https
|
173
|
+
end
|
174
|
+
|
175
|
+
# Check if the virtual host is serving HTTPS and redirecting HTTP to HTTPS
|
176
|
+
# @return [Boolean]
|
177
|
+
def redirect_http_to_https?
|
178
|
+
https_strategy == :redirect_http_to_https
|
179
|
+
end
|
180
|
+
|
181
|
+
# Check if the virtual host is serving HTTP requests
|
182
|
+
# @return [Boolean]
|
183
|
+
def http?
|
184
|
+
https_strategy == :http_only || https_strategy == :http_and_https
|
185
|
+
end
|
186
|
+
|
187
|
+
# Check if the virtual host is serving HTTPS requests
|
188
|
+
# @return [Boolean]
|
189
|
+
def https?
|
190
|
+
https_strategy == :http_and_https
|
191
|
+
end
|
192
|
+
|
193
|
+
# Get information on a virtual host.
|
194
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
|
195
|
+
# @param instance_uuid [String, #to_s] the UUID of the simple hosting instance.
|
196
|
+
# @param fqdn [String, #to_s] the fully qualified domain name of the virtual host.
|
197
|
+
# @return [GandiV5::SimpleHosting::Instance]
|
198
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
199
|
+
def self.fetch(instance_uuid, fqdn)
|
200
|
+
_response, data = GandiV5.get url(instance_uuid, fqdn)
|
201
|
+
from_gandi data.merge('instance_uuid' => instance_uuid)
|
202
|
+
end
|
203
|
+
|
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.
|
237
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts
|
238
|
+
# @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
|
239
|
+
# If page is not provided keep querying until an empty list is returned.
|
240
|
+
# If page responds to .each then iterate until an empty list is returned.
|
241
|
+
# @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
|
242
|
+
# @param status [String, #to_s] (optional)
|
243
|
+
# filter the list by the virtual host's status.
|
244
|
+
# @param fqdn [String, #to_s] (optional)
|
245
|
+
# filter the list by the virtual host's domain name, allows * as wildcard.
|
246
|
+
# @param sort_by [String, #to_s] (optional default "created_at")
|
247
|
+
# how to sort the list, prefix with a minus to reverse sort order.
|
248
|
+
# @return [Array<GandiV5::SimpleHosting::Instance::VirtualHost>]
|
249
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
250
|
+
def self.list(instance_uuid, page: (1..), per_page: 100, **params)
|
251
|
+
instances = []
|
252
|
+
GandiV5.paginated_get(url(instance_uuid), page, per_page, params: params) do |data|
|
253
|
+
instances += data.map { |item| from_gandi item.merge('instance_uuid' => instance_uuid) }
|
254
|
+
end
|
255
|
+
instances
|
256
|
+
end
|
257
|
+
|
258
|
+
private
|
259
|
+
|
260
|
+
def url
|
261
|
+
"#{BASE}simplehosting/instances/#{instance_uuid}/vhosts/#{CGI.escape(fqdn)}"
|
262
|
+
end
|
263
|
+
|
264
|
+
def self.url(instance_uuid, fqdn = nil)
|
265
|
+
"#{BASE}simplehosting/instances/#{instance_uuid}/vhosts" +
|
266
|
+
(fqdn ? "/#{CGI.escape fqdn}" : '')
|
267
|
+
end
|
268
|
+
private_class_method :url
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
class VirtualHost
|
7
|
+
# A DNS Zone linked to a virtual host on a simple hosting instance.
|
8
|
+
# @!attribute [r] allow_alteration
|
9
|
+
# @return [Boolean]
|
10
|
+
# @!attribute [r] cname
|
11
|
+
# @return [String]
|
12
|
+
# @!attribute [r] domain
|
13
|
+
# @return [String]
|
14
|
+
# @!attribute [r] ipv4
|
15
|
+
# @return [String]
|
16
|
+
# @!attribute [r] ipv6
|
17
|
+
# @return [String]
|
18
|
+
# @!attribute [r] is_alterable
|
19
|
+
# @return [Boolean]
|
20
|
+
# @!attribute [r] is_root
|
21
|
+
# @return [Boolean]
|
22
|
+
# @!attribute [r] key
|
23
|
+
# @return [String]
|
24
|
+
# @!attribute [r] txt
|
25
|
+
# @return [String]
|
26
|
+
# @!attribute [r] last_checked_at
|
27
|
+
# @return [Time]
|
28
|
+
# @!attribute [r] status
|
29
|
+
# @return [Symbol] :altered, :livedns_conflict, :livedns_done, :livedns_error, :unknown
|
30
|
+
class LinkedDnsZone
|
31
|
+
include GandiV5::Data
|
32
|
+
|
33
|
+
members :allow_alteration, :is_alterable, :last_checked_at,
|
34
|
+
:cname, :domain, :is_root, :ipv4, :ipv6, :key, :txt
|
35
|
+
|
36
|
+
member(
|
37
|
+
:status,
|
38
|
+
gandi_key: 'last_checked_status',
|
39
|
+
converter: GandiV5::Data::Converter::Symbol
|
40
|
+
)
|
41
|
+
|
42
|
+
# Check if the linked zone is currently in an altered state
|
43
|
+
# @return [Boolean]
|
44
|
+
def altered?
|
45
|
+
status == :altered
|
46
|
+
end
|
47
|
+
|
48
|
+
# Check if the linked zone is currently in a conflicted state
|
49
|
+
# @return [Boolean]
|
50
|
+
def livedns_conflict?
|
51
|
+
status == :livedns_conflict
|
52
|
+
end
|
53
|
+
|
54
|
+
# Check if the linked zone has been updated
|
55
|
+
# @return [Boolean]
|
56
|
+
def livedns_done?
|
57
|
+
status == :livedns_done
|
58
|
+
end
|
59
|
+
|
60
|
+
# Check if the linked zone had an error updating
|
61
|
+
# @return [Boolean]
|
62
|
+
def livedns_error?
|
63
|
+
status == :livedns_error
|
64
|
+
end
|
65
|
+
|
66
|
+
# Check if the linked zone is in an unknown state
|
67
|
+
# @return [Boolean]
|
68
|
+
def unknown?
|
69
|
+
status == :unknown
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|