gandi_v5 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +44 -0
  3. data/CHANGELOG.md +13 -0
  4. data/README.md +1 -0
  5. data/gandi_v5.gemspec +2 -2
  6. data/lib/gandi_v5/domain.rb +5 -3
  7. data/lib/gandi_v5/live_dns/domain.rb +2 -2
  8. data/lib/gandi_v5/sharing_space.rb +27 -0
  9. data/lib/gandi_v5/simple_hosting.rb +12 -0
  10. data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
  11. data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
  12. data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
  13. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  14. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
  15. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
  16. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
  17. data/lib/gandi_v5/version.rb +1 -1
  18. data/spec/.rubocop.yml +50 -3
  19. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  20. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  21. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  22. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  23. data/spec/units/gandi_v5/domain_spec.rb +1 -1
  24. data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
  25. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  26. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
  27. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
  28. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
  29. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  30. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
  31. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
  32. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  33. metadata +28 -8
  34. data/lib/gandi_v5/domain/sharing_space.rb +0 -29
  35. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6873be5c700e1ef88075c90b71361bb9568b11661661dd0bc4f7d77cfdefd6f0
4
- data.tar.gz: 13aac04c42357193607cff0f55c0502253fb6b527475e40ad5cb5d53011268ce
3
+ metadata.gz: 5bcedab1f98eded02f20893ca2f4b8c5a47abe1d72d3e055ef5688b2969104df
4
+ data.tar.gz: 6db74218bd3914c662c2b6cac47c76a4d9497368f80b3ef4f31ad7e6537604a5
5
5
  SHA512:
6
- metadata.gz: 46afb560fe574db5bf9d47e3e5bbce0843acef12edd132e26cba685608e4b1fa2dc1579dc30e287128ef6462924d56c14856168bcc2d277dededbf9360c45d0b
7
- data.tar.gz: 9e35714cdb2ad68d57d11f4bdd689a6fc0103d155827682bb6a2f66340e8054af328761827f13e7af857c5c41263568daed84805e20b90e5b580917dea502eab
6
+ metadata.gz: 29dad44ec126323a917bcc5c4ac8dd200e1acc7ac32cfdf7c4608a919dd872e9f2071031b371d7ad8bae8a2ed09e6bd2bf660d0095b59999859e91d180b53e70
7
+ data.tar.gz: 1d2c599205a31b449c003cf4e2628b0326cf90d45ae3c75a68356879e463ee708c6d81f5fb64e1ee75ffe73fbc5402cc3e2fc290fddfe6777c0fb304ccb45a8f
@@ -4,6 +4,18 @@ AllCops:
4
4
  TargetRubyVersion: 2.6.0
5
5
  Gemspec/RequiredRubyVersion:
6
6
  Enabled: false
7
+ Layout/EmptyLinesAroundAttributeAccessor:
8
+ Enabled: true
9
+ Layout/SpaceAroundMethodCallOperator:
10
+ Enabled: true
11
+ Lint/DeprecatedOpenSSLConstant:
12
+ Enabled: true
13
+ Lint/MixedRegexpCaptureTypes:
14
+ Enabled: true
15
+ Lint/RaiseException:
16
+ Enabled: true
17
+ Lint/StructNewOverride:
18
+ Enabled: true
7
19
  Metrics/AbcSize:
8
20
  Max: 20
9
21
  Metrics/ClassLength:
@@ -16,15 +28,47 @@ Metrics/ModuleLength:
16
28
  Max: 200
17
29
  Metrics/ParameterLists:
18
30
  Max: 6
31
+ Performance/AncestorsInclude:
32
+ Enabled: true
33
+ Performance/BigDecimalWithNumericArgument:
34
+ Enabled: true
35
+ Performance/RedundantSortBlock:
36
+ Enabled: true
37
+ Performance/RedundantStringChars:
38
+ Enabled: true
39
+ Performance/ReverseFirst:
40
+ Enabled: true
41
+ Performance/SortReverse:
42
+ Enabled: true
43
+ Performance/Squeeze:
44
+ Enabled: true
45
+ Performance/StringInclude:
46
+ Enabled: true
47
+ Style/AccessorGrouping:
48
+ Enabled: true
49
+ Style/BisectedAttrAccessor:
50
+ Enabled: true
19
51
  Style/DocumentationMethod:
20
52
  Enabled: true
53
+ Style/ExponentialNotation:
54
+ Enabled: true
21
55
  Style/HashEachMethods:
22
56
  Enabled: true
23
57
  Style/HashTransformKeys:
24
58
  Enabled: true
25
59
  Style/HashTransformValues:
26
60
  Enabled: true
61
+ Style/RedundantAssignment:
62
+ Enabled: true
63
+ Style/RedundantFetchBlock:
64
+ Enabled: true
65
+ Style/RedundantRegexpCharacterClass:
66
+ Enabled: true
67
+ Style/RedundantRegexpEscape:
68
+ Enabled: true
27
69
  Style/SignalException:
28
70
  Enabled: false
71
+ Style/SlicingWithRange:
72
+ Enabled: true
29
73
  Layout/LineLength:
30
74
  Max: 100
@@ -1,5 +1,18 @@
1
1
  # Gandi V5 API Gem Changelog
2
2
 
3
+ ## Version 0.8.0
4
+
5
+ * Domain:
6
+ * .list - add resellee_id filter
7
+ * Added simple hosting: (I don't use simple hosting myself so it's possible I've misread the docs and a bug is waiting to be found, please add an issue if I have)
8
+ * SimpleHosting::Instance
9
+ * SimpleHosting::Instance::VirtualHost
10
+ * SimpleHosting::Instance::Application
11
+ * SimpleHosting::Instance::Database
12
+ * SimpleHosting::Instance::Language
13
+ * SimpleHosting::Instance::Upgrade
14
+ * GandiV5::Domain::SharingSpace moved to GandiV5::SharingSpace
15
+
3
16
  ## Version 0.7.0
4
17
 
5
18
  * LiveDNS:
data/README.md CHANGED
@@ -77,6 +77,7 @@ We follow the [Semantic Versioning](http://semver.org/) concept.
77
77
 
78
78
  | Gem Version | Gandi API Release Date |
79
79
  | --------------- | ------------------------ |
80
+ | 0.8.0 | 2020-07-10 |
80
81
  | 0.7.0 | 2020-05-07 |
81
82
  | 0.6.0 | 2020-05-07 (not LiveDNS) |
82
83
  | 0.5.0 | 2019-10-01 |
@@ -33,8 +33,8 @@ Gem::Specification.new do |gem|
33
33
  gem.add_development_dependency 'rb-inotify', '~> 0.9'
34
34
  gem.add_development_dependency 'rspec', '>= 3.7', '< 4'
35
35
  gem.add_development_dependency 'rspec-its', '~> 1.3'
36
- gem.add_development_dependency 'rubocop', '~> 0.73'
37
- gem.add_development_dependency 'rubocop-performance', '~> 1.1'
36
+ gem.add_development_dependency 'rubocop', '~> 0.87'
37
+ gem.add_development_dependency 'rubocop-performance', '~> 1.7'
38
38
  gem.add_development_dependency 'simplecov', '~> 0.7'
39
39
  gem.add_development_dependency 'timecop', '~> 0.5'
40
40
  gem.add_development_dependency 'vcr', '~> 4.0'
@@ -15,7 +15,7 @@ class GandiV5
15
15
  # gandidns, redirection, gandimail, packmail, dnssec, blog, hosting,
16
16
  # paas, site, certificate, gandilivedns, mailboxv2
17
17
  # @!attribute [r] sharing_space
18
- # @return [GandiV5::Domain::SharingSpace]
18
+ # @return [GandiV5::SharingSpace]
19
19
  # @!attribute [r] status
20
20
  # @return [String] one of: "clientHold", "clientUpdateProhibited", "clientTransferProhibited",
21
21
  # "clientDeleteProhibited", "clientRenewProhibited", "serverHold", "pendingTransfer",
@@ -107,7 +107,7 @@ class GandiV5
107
107
  member(
108
108
  :sharing_space,
109
109
  gandi_key: 'sharing_space',
110
- converter: GandiV5::Domain::SharingSpace
110
+ converter: GandiV5::SharingSpace
111
111
  )
112
112
 
113
113
  member(
@@ -496,8 +496,10 @@ class GandiV5
496
496
  # @param fqdn [String, #to_s] (optional)
497
497
  # filters the list by domain name, with optional patterns.
498
498
  # e.g. "example.net", "example.*", "*ample.com"
499
- # @param sort_by [String, #to_s] (optional default "fqdn") how to sort the list.
499
+ # @param resellee_id [String, #to_s] (optional)
500
+ # filters the list by resellee_id (from the Organization API).
500
501
  # @param tld [String, #to_s] (optional) used to filter by just the top level domain.
502
+ # @param sort_by [String, #to_s] (optional default "fqdn") how to sort the list.
501
503
  # @return [Array<GandiV5::Domain>]
502
504
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
503
505
  def self.list(page: (1..), per_page: 100, **params)
@@ -138,7 +138,7 @@ class GandiV5
138
138
  # @raise [ArgumentError] if ttl is present and type is absent.
139
139
  # @return [String] The confirmation message from Gandi.
140
140
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
141
- # rubocop:disable Metrics/PerceivedComplexity
141
+ # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
142
142
  def replace_records(records, name: nil, type: nil)
143
143
  if type
144
144
  GandiV5::LiveDNS.require_valid_record_type(type) if type
@@ -158,7 +158,7 @@ class GandiV5
158
158
  _response, data = GandiV5.put url_, body.to_json
159
159
  data['message']
160
160
  end
161
- # rubocop:enable Metrics/PerceivedComplexity
161
+ # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
162
162
 
163
163
  # Replace all records for this domain.
164
164
  # @param text [String] zone file lines to replace the records with.
@@ -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