gandi_v5 0.3.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +56 -2
- data/.travis.yml +6 -1
- data/CHANGELOG.md +61 -0
- data/LICENSE.md +2 -6
- data/README.md +15 -9
- data/gandi_v5.gemspec +2 -2
- data/lib/gandi_v5.rb +40 -14
- data/lib/gandi_v5/data.rb +1 -2
- data/lib/gandi_v5/data/converter/integer.rb +26 -0
- data/lib/gandi_v5/domain.rb +13 -14
- data/lib/gandi_v5/email/forward.rb +2 -8
- data/lib/gandi_v5/email/mailbox.rb +57 -11
- data/lib/gandi_v5/email/slot.rb +11 -3
- data/lib/gandi_v5/live_dns.rb +0 -12
- data/lib/gandi_v5/live_dns/domain.rb +313 -29
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
- data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
- data/lib/gandi_v5/organization.rb +10 -0
- data/lib/gandi_v5/organization/customer.rb +90 -0
- data/lib/gandi_v5/sharing_space.rb +27 -0
- data/lib/gandi_v5/simple_hosting.rb +12 -0
- data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/spec/.rubocop.yml +56 -2
- data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
- data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
- data/spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml +8 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
- data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
- data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
- data/spec/units/gandi_v5/domain_spec.rb +53 -43
- data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
- data/spec/units/gandi_v5/email/mailbox_spec.rb +119 -37
- data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
- data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
- data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
- data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
- data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
- data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
- data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
- data/spec/units/gandi_v5/organization/customer_spec.rb +81 -0
- data/spec/units/gandi_v5/organization_spec.rb +14 -0
- data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
- data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
- data/spec/units/gandi_v5_spec.rb +139 -30
- metadata +50 -31
- data/lib/gandi_v5/domain/sharing_space.rb +0 -21
- data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
- data/lib/gandi_v5/live_dns/record_set.rb +0 -79
- data/lib/gandi_v5/live_dns/zone.rb +0 -160
- data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
- data/spec/features/domain_spec.rb +0 -45
- data/spec/features/livedns_domain_spec.rb +0 -8
- data/spec/features/livedns_zone_spec.rb +0 -45
- data/spec/features/mailbox_spec.rb +0 -18
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
- data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
- data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
- data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
- data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
- data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
- data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
- data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
- data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
- data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
# Sharing space which contains other billable items.
|
5
|
+
# @!attribute [r] uuid
|
6
|
+
# @return [String]
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [r] type
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] reseller
|
12
|
+
# @return [nil, Boolean]
|
13
|
+
# @!attribute [r] reseller_details
|
14
|
+
# @return [nil, GandiV5::Domain::SharingSpace]
|
15
|
+
class SharingSpace
|
16
|
+
include GandiV5::Data
|
17
|
+
|
18
|
+
members :name, :type, :reseller
|
19
|
+
member :uuid, gandi_key: 'id'
|
20
|
+
member(
|
21
|
+
:reseller_details,
|
22
|
+
gandi_key: 'sharing_space',
|
23
|
+
converter: GandiV5::SharingSpace
|
24
|
+
)
|
25
|
+
alias sharing_space_uuid uuid
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for classes which access LiveDNS details.
|
4
|
+
class GandiV5
|
5
|
+
# Gandi Simple Hosting management API.
|
6
|
+
class SimpleHosting
|
7
|
+
# @see GandiV5::Simplehosting::Instance.list
|
8
|
+
def self.instances
|
9
|
+
GandiV5::SimpleHosting::Instance.list
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Namespace for classes which access LiveDNS details.
|
4
|
+
class GandiV5
|
5
|
+
class SimpleHosting
|
6
|
+
# A simple hosting instance.
|
7
|
+
# @see https://api.gandi.net/docs/simplehosting/
|
8
|
+
# @!attribute [r] uuid
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [r] name
|
11
|
+
# @return [String]
|
12
|
+
# @!attribute [r] size
|
13
|
+
# @return [String] one of: s, s+, m, l, xl, xxl
|
14
|
+
# @!attribute [r] password_updated_at
|
15
|
+
# @return [Time]
|
16
|
+
# @!attribute [r] created_at
|
17
|
+
# @return [Time]
|
18
|
+
# @!attribute [r] expire_at
|
19
|
+
# @return [Time]
|
20
|
+
# @!attribute [r] status
|
21
|
+
# @return [Symbol] :waiting_bill, :being_created, :active
|
22
|
+
# :paused, :locked, :being_deleted
|
23
|
+
# @!attribute [r] snapshot_enabled
|
24
|
+
# @return [Boolean]
|
25
|
+
# @!attribute [r] available_upgrade
|
26
|
+
# @return [Boolean]
|
27
|
+
# @!attribute [r] is_trial
|
28
|
+
# @return [Boolean]
|
29
|
+
# @!attribute [r] access_information
|
30
|
+
# @return [Hash] as returned by Gandi.
|
31
|
+
# @!attribute [r] sharing_space
|
32
|
+
# @return [GandiV5::SharingSpace] who pays for this instance.
|
33
|
+
# @!attribute [r] data_center
|
34
|
+
# @return [String] code of the data center hosting this instance.
|
35
|
+
# @!attribute [r] storage
|
36
|
+
# @return [Hash<Symbol => "#{number} #{unit}">]
|
37
|
+
# storage split by :base, :additional and :total
|
38
|
+
# @!attribute [r] auto_renew
|
39
|
+
# @return [string] "#{number} #{unit}".
|
40
|
+
# @!attribute [r] virtual_hosts
|
41
|
+
# @return [Array<GandiV5::SimpleHosting::Instance::VirtualHost>]
|
42
|
+
# @!attribute [r] database
|
43
|
+
# @return [GandiV5::SimpleHosting::Instance::Database]
|
44
|
+
# @!attribute [r] language
|
45
|
+
# @return [GandiV5::SimpleHosting::Instance::Language]
|
46
|
+
# @!attribute [r] compatible_applications
|
47
|
+
# @return [Array<GandiV5::SimpleHosting::Instance::Application>]
|
48
|
+
# @!attribute [r] upgrade_to
|
49
|
+
# @return [Array<GandiV5::SimpleHosting::Instance::Upgrade>]
|
50
|
+
class Instance
|
51
|
+
include GandiV5::Data
|
52
|
+
|
53
|
+
members :name, :size, :password_updated_at, :created_at, :expire_at, :status,
|
54
|
+
:snapshot_enabled, :available_upgrade, :is_trial, :access_information
|
55
|
+
|
56
|
+
member :uuid, gandi_key: 'id'
|
57
|
+
|
58
|
+
member(
|
59
|
+
:sharing_space,
|
60
|
+
gandi_key: 'sharing_space',
|
61
|
+
converter: GandiV5::SharingSpace
|
62
|
+
)
|
63
|
+
|
64
|
+
member(
|
65
|
+
:data_center,
|
66
|
+
gandi_key: 'datacenter',
|
67
|
+
converter: GandiV5::Data::Converter.new(
|
68
|
+
from_gandi: ->(hash) { hash['code'] }
|
69
|
+
)
|
70
|
+
)
|
71
|
+
|
72
|
+
member(
|
73
|
+
:storage,
|
74
|
+
converter: GandiV5::Data::Converter.new(
|
75
|
+
from_gandi: lambda do |hash|
|
76
|
+
hash.transform_values { |value| "#{value['value']} #{value['unit']}" }
|
77
|
+
.transform_keys(&:to_sym)
|
78
|
+
end
|
79
|
+
)
|
80
|
+
)
|
81
|
+
|
82
|
+
member(
|
83
|
+
:auto_renew,
|
84
|
+
gandi_key: 'autorenew',
|
85
|
+
converter: GandiV5::Data::Converter.new(
|
86
|
+
from_gandi: ->(hash) { "#{hash['duration']} #{hash['duration_type']}" }
|
87
|
+
)
|
88
|
+
)
|
89
|
+
|
90
|
+
member(
|
91
|
+
:virtual_hosts,
|
92
|
+
gandi_key: 'vhosts',
|
93
|
+
array: true,
|
94
|
+
converter: GandiV5::SimpleHosting::Instance::VirtualHost
|
95
|
+
)
|
96
|
+
|
97
|
+
member(
|
98
|
+
:database,
|
99
|
+
converter: GandiV5::SimpleHosting::Instance::Database
|
100
|
+
)
|
101
|
+
|
102
|
+
member(
|
103
|
+
:language,
|
104
|
+
converter: GandiV5::SimpleHosting::Instance::Language
|
105
|
+
)
|
106
|
+
|
107
|
+
member(
|
108
|
+
:compatible_applications,
|
109
|
+
array: true,
|
110
|
+
converter: GandiV5::SimpleHosting::Instance::Application
|
111
|
+
)
|
112
|
+
|
113
|
+
member(
|
114
|
+
:upgrade_to,
|
115
|
+
array: true,
|
116
|
+
converter: GandiV5::SimpleHosting::Instance::Upgrade
|
117
|
+
)
|
118
|
+
|
119
|
+
# Instruct Gandi to restart this instance.
|
120
|
+
# @return [String] confirmation message.
|
121
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
122
|
+
def restart
|
123
|
+
_response, data = GandiV5.post "#{url}/action", { 'action' => 'restart' }.to_json
|
124
|
+
data
|
125
|
+
end
|
126
|
+
|
127
|
+
# Instruct Gandi to console this instance.
|
128
|
+
# @return [String] confirmation message.
|
129
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
130
|
+
def console
|
131
|
+
_response, data = GandiV5.post "#{url}/action", { 'action' => 'console' }.to_json
|
132
|
+
data
|
133
|
+
end
|
134
|
+
|
135
|
+
# Instruct Gandi to reset the database password for this instance.
|
136
|
+
# @return [String] confirmation message.
|
137
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
138
|
+
def reset_database_password
|
139
|
+
_response, data = GandiV5.post(
|
140
|
+
"#{url}/action",
|
141
|
+
{ 'action' => 'reset_database_password' }.to_json
|
142
|
+
)
|
143
|
+
data
|
144
|
+
end
|
145
|
+
|
146
|
+
# Requery Gandi fo this instance's information.
|
147
|
+
# @return [GandiV5::SimpleHosting::Instance]
|
148
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
149
|
+
def refresh
|
150
|
+
_response, data = GandiV5.get url
|
151
|
+
from_gandi data
|
152
|
+
end
|
153
|
+
|
154
|
+
# Check if this instance is waiting for a bill
|
155
|
+
# @return [Boolean]
|
156
|
+
def waiting_bill?
|
157
|
+
status == :waiting_bill
|
158
|
+
end
|
159
|
+
|
160
|
+
# Check if this instance is being created
|
161
|
+
# @return [Boolean]
|
162
|
+
def being_created?
|
163
|
+
status == :being_created
|
164
|
+
end
|
165
|
+
|
166
|
+
# Check if this instance is active
|
167
|
+
# @return [Boolean]
|
168
|
+
def active?
|
169
|
+
status == :active
|
170
|
+
end
|
171
|
+
|
172
|
+
# Check if this instance is paused
|
173
|
+
# @return [Boolean]
|
174
|
+
def paused?
|
175
|
+
status == :paused
|
176
|
+
end
|
177
|
+
|
178
|
+
# Check if this instance is locked
|
179
|
+
# @return [Boolean]
|
180
|
+
def locked?
|
181
|
+
status == :locked
|
182
|
+
end
|
183
|
+
|
184
|
+
# Check if this instance is being deleted
|
185
|
+
# @return [Boolean]
|
186
|
+
def being_deleted?
|
187
|
+
status == :being_deleted
|
188
|
+
end
|
189
|
+
|
190
|
+
# Get information on an instance.
|
191
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id
|
192
|
+
# @param uuid [String, #to_s] the UUID of the instance.
|
193
|
+
# @return [GandiV5::SimpleHosting::Instance]
|
194
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
195
|
+
def self.fetch(uuid)
|
196
|
+
_response, data = GandiV5.get url(uuid)
|
197
|
+
from_gandi data
|
198
|
+
end
|
199
|
+
|
200
|
+
# List instances.
|
201
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances
|
202
|
+
# @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
|
203
|
+
# If page is not provided keep querying until an empty list is returned.
|
204
|
+
# If page responds to .each then iterate until an empty list is returned.
|
205
|
+
# @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
|
206
|
+
# @param sharing_id [String, #to_s] (optional)
|
207
|
+
# filter the list by who pays the bill.
|
208
|
+
# @param size [String, #to_s] (optional)
|
209
|
+
# filter the list by instance size (s, s+, m, i, xl, xxl).
|
210
|
+
# @param name [String, #to_s] (optional)
|
211
|
+
# filter the list by instance name, allows * as wildcard.
|
212
|
+
# @param status [String, #to_s] (optional)
|
213
|
+
# filter the list by the instance's status.
|
214
|
+
# @param fqdn [String, #to_s] (optional)
|
215
|
+
# filter the list by the virtual host's domain name, allows * as wildcard.
|
216
|
+
# @param sort_by [String, #to_s] (optional default "created_at")
|
217
|
+
# how to sort the list, prefix with a minus to reverse sort order.
|
218
|
+
# @return [Array<GandiV5::SimpleHosting::Instance>]
|
219
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
220
|
+
def self.list(page: (1..), per_page: 100, **params)
|
221
|
+
instances = []
|
222
|
+
GandiV5.paginated_get(url, page, per_page, params: params) do |data|
|
223
|
+
instances += data.map { |item| from_gandi item }
|
224
|
+
end
|
225
|
+
instances
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def url
|
231
|
+
"#{BASE}simplehosting/instances/" +
|
232
|
+
CGI.escape(uuid)
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.url(uuid = nil)
|
236
|
+
"#{BASE}simplehosting/instances" +
|
237
|
+
(uuid ? "/#{CGI.escape uuid}" : '')
|
238
|
+
end
|
239
|
+
private_class_method :url
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# @!attribute [r] name
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] parameters
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [r] status
|
11
|
+
# @return [Symbol] :error, :running, :being_created, :cancelled
|
12
|
+
class Application
|
13
|
+
include GandiV5::Data
|
14
|
+
|
15
|
+
members :name, :parameters
|
16
|
+
member :status, converter: GandiV5::Data::Converter::Symbol
|
17
|
+
|
18
|
+
# Check if the appliaction is currently being created
|
19
|
+
# @return [Boolean]
|
20
|
+
def being_created?
|
21
|
+
status == :being_created
|
22
|
+
end
|
23
|
+
|
24
|
+
# Check if the appliaction has been cancelled
|
25
|
+
# @return [Boolean]
|
26
|
+
def cancelled?
|
27
|
+
status == :cancelled
|
28
|
+
end
|
29
|
+
|
30
|
+
# Check if the appliaction is running
|
31
|
+
# @return [Boolean]
|
32
|
+
def running?
|
33
|
+
status == :running
|
34
|
+
end
|
35
|
+
|
36
|
+
# Check if the appliaction is in an error condition
|
37
|
+
# @return [Boolean]
|
38
|
+
def error?
|
39
|
+
status == :error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# @!attribute [r] name
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] status
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [r] version
|
11
|
+
# @return [String]
|
12
|
+
class Database
|
13
|
+
include GandiV5::Data
|
14
|
+
|
15
|
+
members :name, :status, :version
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# Sharing space which contains other billable items.
|
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,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class SimpleHosting
|
5
|
+
class Instance
|
6
|
+
# @!attribute [r] name
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] status
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [r] type
|
11
|
+
# @return [String] "database" or "language"
|
12
|
+
# @!attribute [r] version
|
13
|
+
# @return [String]
|
14
|
+
class Upgrade
|
15
|
+
include GandiV5::Data
|
16
|
+
|
17
|
+
members :name, :status, :type, :version
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,187 @@
|
|
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 simple hosting virtual host.
|
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 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
|
+
# Check if the virtual host is being created
|
69
|
+
# @return [Boolean]
|
70
|
+
def being_created?
|
71
|
+
status == :being_created
|
72
|
+
end
|
73
|
+
|
74
|
+
# Check if the virtual host is running
|
75
|
+
# @return [Boolean]
|
76
|
+
def running?
|
77
|
+
status == :running
|
78
|
+
end
|
79
|
+
|
80
|
+
# Check if the virtual host is being deleted
|
81
|
+
# @return [Boolean]
|
82
|
+
def being_deleted?
|
83
|
+
status == :being_deleted
|
84
|
+
end
|
85
|
+
|
86
|
+
# Check if the virtual host is locked
|
87
|
+
# @return [Boolean]
|
88
|
+
def locked?
|
89
|
+
status == :locked
|
90
|
+
end
|
91
|
+
|
92
|
+
# Check if the virtual host is waiting for an ownership check
|
93
|
+
# @return [Boolean]
|
94
|
+
def waiting_ownership?
|
95
|
+
status == :waiting_ownership
|
96
|
+
end
|
97
|
+
|
98
|
+
# Check if the virtual host has it's ownership validated
|
99
|
+
# @return [Boolean]
|
100
|
+
def ownership_validated?
|
101
|
+
status == :ownership_validated
|
102
|
+
end
|
103
|
+
|
104
|
+
# Check if the virtual host failed it's ownership check
|
105
|
+
# @return [Boolean]
|
106
|
+
def validation_failed?
|
107
|
+
status == :validation_failed
|
108
|
+
end
|
109
|
+
|
110
|
+
# Check if the virtual host is serving HTTP only
|
111
|
+
# @return [Boolean]
|
112
|
+
def http_only?
|
113
|
+
https_strategy == :http_only
|
114
|
+
end
|
115
|
+
|
116
|
+
# Check if the virtual host is serving HTTP and HTTPS
|
117
|
+
# @return [Boolean]
|
118
|
+
def http_and_https?
|
119
|
+
https_strategy == :http_and_https
|
120
|
+
end
|
121
|
+
|
122
|
+
# Check if the virtual host is serving HTTPS and redirecting HTTP to HTTPS
|
123
|
+
# @return [Boolean]
|
124
|
+
def redirect_http_to_https?
|
125
|
+
https_strategy == :redirect_http_to_https
|
126
|
+
end
|
127
|
+
|
128
|
+
# Check if the virtual host is serving HTTP requests
|
129
|
+
# @return [Boolean]
|
130
|
+
def http?
|
131
|
+
https_strategy == :http_only || https_strategy == :http_and_https
|
132
|
+
end
|
133
|
+
|
134
|
+
# Check if the virtual host is serving HTTPS requests
|
135
|
+
# @return [Boolean]
|
136
|
+
def https?
|
137
|
+
https_strategy == :http_and_https
|
138
|
+
end
|
139
|
+
|
140
|
+
# Get information on a virtual host.
|
141
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
|
142
|
+
# @param uuid [String, #to_s] the UUID of the simple hosting instance.
|
143
|
+
# @param fqdn [String, #to_s] the fully qualified domain name of the virtual host.
|
144
|
+
# @return [GandiV5::SimpleHosting::Instance]
|
145
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
146
|
+
def self.fetch(instance_uuid, fqdn)
|
147
|
+
_response, data = GandiV5.get url(instance_uuid, fqdn)
|
148
|
+
from_gandi data.merge('instance_uuid' => instance_uuid)
|
149
|
+
end
|
150
|
+
|
151
|
+
# List instances.
|
152
|
+
# @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts
|
153
|
+
# @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
|
154
|
+
# If page is not provided keep querying until an empty list is returned.
|
155
|
+
# If page responds to .each then iterate until an empty list is returned.
|
156
|
+
# @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
|
157
|
+
# @param status [String, #to_s] (optional)
|
158
|
+
# filter the list by the virtual host's status.
|
159
|
+
# @param fqdn [String, #to_s] (optional)
|
160
|
+
# filter the list by the virtual host's domain name, allows * as wildcard.
|
161
|
+
# @param sort_by [String, #to_s] (optional default "created_at")
|
162
|
+
# how to sort the list, prefix with a minus to reverse sort order.
|
163
|
+
# @return [Array<GandiV5::SimpleHosting::Instance::VirtualHost>]
|
164
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
165
|
+
def self.list(instance_uuid, page: (1..), per_page: 100, **params)
|
166
|
+
instances = []
|
167
|
+
GandiV5.paginated_get(url(instance_uuid), page, per_page, params: params) do |data|
|
168
|
+
instances += data.map { |item| from_gandi item.merge('instance_uuid' => instance_uuid) }
|
169
|
+
end
|
170
|
+
instances
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def url
|
176
|
+
"#{BASE}simplehosting/instances/#{instance_uuid}/vhosts/#{CGI.escape(fqdn)}"
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.url(instance_uuid, fqdn = nil)
|
180
|
+
"#{BASE}simplehosting/instances/#{instance_uuid}/vhosts" +
|
181
|
+
(fqdn ? "/#{CGI.escape fqdn}" : '')
|
182
|
+
end
|
183
|
+
private_class_method :url
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|