hcloud 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f32bc658bc4cb2d5151d8af866b7f09769b688bdda0fb3626932ba02268dd1c
4
- data.tar.gz: c9882c417f63c0b7100540cbfb3c86c299674904ac4676a5b85e934d888a72d8
3
+ metadata.gz: d0476422e0663e6960e40d0198cfcc4544701def1670fbefae008cfcb4208a41
4
+ data.tar.gz: 192b15230064d1f5fea319268ce5ea897785e9bcc5c7f970ee50451490339fe7
5
5
  SHA512:
6
- metadata.gz: d0f0a02ffe7bf1f53b2da59775df790d3340616a4c1a30c15cd24c6556d8412e713286b7d690e9c618ebfa9682b81f2ee1a6543e5c056b02c121f0655db3a818
7
- data.tar.gz: 3c5e42fdca1fa5e0e1ce8050052583b4055ae5a0b9206a8d020721d5f845ebdc26ffd99696d4fa9fac943cc9cf17f6b0de3306daa74bdc7f87d4fa719f963ac2
6
+ metadata.gz: 9676ed391c7b0474fdb4c3b16d9ff2556ffe0909dfb2bc16a3d9fb9eed48d178b5d6d7ea7cc42eb93ebed99d38854846bbe0791e36a3967fd8c45ba5ca2fcd60
7
+ data.tar.gz: e9c4d5118d2e16ce1421cdc42c0413326bb58b17f986f91081d2db04004cb1a1e60edbcb4f84eec904adc6d6e71d5d7db4f052f4b1a07b2d0bede23184d87410
@@ -1,5 +1,12 @@
1
+ ---
1
2
  name: hcloud-ruby ci
2
- on: [push]
3
+
4
+ on:
5
+ pull_request: {}
6
+ push:
7
+ branches:
8
+ - master
9
+
3
10
  jobs:
4
11
  lint:
5
12
  runs-on: ubuntu-latest
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.3.0](https://github.com/tonobo/hcloud-ruby/tree/v1.3.0) (2024-02-20)
4
+
5
+ [Full Changelog](https://github.com/tonobo/hcloud-ruby/compare/v1.2.0...v1.3.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - \[Enhancement\] Add missing fields / endpoints to Images + Servers [\#30](https://github.com/tonobo/hcloud-ruby/issues/30)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - fix activemodel in Gemfile.lock [\#87](https://github.com/tonobo/hcloud-ruby/pull/87) ([skoch-hc](https://github.com/skoch-hc))
14
+ - Fix typo for pagination method [\#85](https://github.com/tonobo/hcloud-ruby/pull/85) ([coorasse](https://github.com/coorasse))
15
+ - \(\#82\) fix undefined method `.blank?` [\#84](https://github.com/tonobo/hcloud-ruby/pull/84) ([bastelfreak](https://github.com/bastelfreak))
16
+ - CI: Run on PRs and pushes to master [\#83](https://github.com/tonobo/hcloud-ruby/pull/83) ([bastelfreak](https://github.com/bastelfreak))
17
+ - Dont list activemodel as dev- and runtime dep [\#80](https://github.com/tonobo/hcloud-ruby/pull/80) ([bastelfreak](https://github.com/bastelfreak))
18
+ - version: bump to v1.2.0 [\#79](https://github.com/tonobo/hcloud-ruby/pull/79) ([aufziehvogel](https://github.com/aufziehvogel))
19
+ - build\(deps\): bump rack from 3.0.1 to 3.0.6.1 [\#75](https://github.com/tonobo/hcloud-ruby/pull/75) ([dependabot[bot]](https://github.com/apps/dependabot))
20
+ - add missing features to existing resources [\#60](https://github.com/tonobo/hcloud-ruby/pull/60) ([aufziehvogel](https://github.com/aufziehvogel))
21
+
22
+ ## [v1.2.0](https://github.com/tonobo/hcloud-ruby/tree/v1.2.0) (2023-10-11)
23
+
24
+ [Full Changelog](https://github.com/tonobo/hcloud-ruby/compare/v1.1.0...v1.2.0)
25
+
26
+ **Closed issues:**
27
+
28
+ - question: could you point out the differences to other hcloud gem? [\#71](https://github.com/tonobo/hcloud-ruby/issues/71)
29
+ - \[Feature\] Add Primary IPs [\#57](https://github.com/tonobo/hcloud-ruby/issues/57)
30
+ - \[Feature\] Add Primary IPs [\#56](https://github.com/tonobo/hcloud-ruby/issues/56)
31
+ - \[Bug\] Firewalls do not expose actions [\#54](https://github.com/tonobo/hcloud-ruby/issues/54)
32
+ - \[Bug\] IPv6 global address is not parsed correctly [\#49](https://github.com/tonobo/hcloud-ruby/issues/49)
33
+ - \[Feature\] Add LoadBalancers and -Types [\#29](https://github.com/tonobo/hcloud-ruby/issues/29)
34
+ - \[Feature\] Add PlacementGroups [\#27](https://github.com/tonobo/hcloud-ruby/issues/27)
35
+ - \[Feature\] Add Certificates [\#26](https://github.com/tonobo/hcloud-ruby/issues/26)
36
+ - \[Feature\] Add Firewalls [\#25](https://github.com/tonobo/hcloud-ruby/issues/25)
37
+
38
+ **Merged pull requests:**
39
+
40
+ - version: bump to v1.2.0 [\#78](https://github.com/tonobo/hcloud-ruby/pull/78) ([aufziehvogel](https://github.com/aufziehvogel))
41
+ - lib: import active\_support before cherry-picking imports [\#77](https://github.com/tonobo/hcloud-ruby/pull/77) ([aufziehvogel](https://github.com/aufziehvogel))
42
+ - Dependencies: Drop rake, as it's unnecessary [\#74](https://github.com/tonobo/hcloud-ruby/pull/74) ([Kjarrigan](https://github.com/Kjarrigan))
43
+ - server: return `next_actions` data on create [\#72](https://github.com/tonobo/hcloud-ruby/pull/72) ([aufziehvogel](https://github.com/aufziehvogel))
44
+ - lib: implement primary IPs [\#65](https://github.com/tonobo/hcloud-ruby/pull/65) ([aufziehvogel](https://github.com/aufziehvogel))
45
+ - lib: implement certificates [\#64](https://github.com/tonobo/hcloud-ruby/pull/64) ([aufziehvogel](https://github.com/aufziehvogel))
46
+ - spec: include context doubles for doubles tests [\#63](https://github.com/tonobo/hcloud-ruby/pull/63) ([aufziehvogel](https://github.com/aufziehvogel))
47
+ - fix: return actions info on firewall create [\#59](https://github.com/tonobo/hcloud-ruby/pull/59) ([aufziehvogel](https://github.com/aufziehvogel))
48
+ - fix: do not interpret leading : in JSON as symbol [\#58](https://github.com/tonobo/hcloud-ruby/pull/58) ([aufziehvogel](https://github.com/aufziehvogel))
49
+ - lib: implement load balancer [\#55](https://github.com/tonobo/hcloud-ruby/pull/55) ([aufziehvogel](https://github.com/aufziehvogel))
50
+ - implement double tests for existing resources [\#53](https://github.com/tonobo/hcloud-ruby/pull/53) ([aufziehvogel](https://github.com/aufziehvogel))
51
+ - Add PlacementGroup [\#52](https://github.com/tonobo/hcloud-ruby/pull/52) ([aufziehvogel](https://github.com/aufziehvogel))
52
+ - firewall: please linter [\#51](https://github.com/tonobo/hcloud-ruby/pull/51) ([RaphaelPour](https://github.com/RaphaelPour))
53
+
3
54
  ## [v1.1.0](https://github.com/tonobo/hcloud-ruby/tree/v1.1.0) (2022-11-29)
4
55
 
5
56
  [Full Changelog](https://github.com/tonobo/hcloud-ruby/compare/v1.0.3...v1.1.0)
@@ -12,6 +63,7 @@
12
63
 
13
64
  **Merged pull requests:**
14
65
 
66
+ - version: bump to v1.1.0 [\#50](https://github.com/tonobo/hcloud-ruby/pull/50) ([aufziehvogel](https://github.com/aufziehvogel))
15
67
  - handle action array responses for firewall actions [\#48](https://github.com/tonobo/hcloud-ruby/pull/48) ([aufziehvogel](https://github.com/aufziehvogel))
16
68
  - fix auto pagination test to always use three pages [\#47](https://github.com/tonobo/hcloud-ruby/pull/47) ([aufziehvogel](https://github.com/aufziehvogel))
17
69
  - label support \(create, update, search\) [\#45](https://github.com/tonobo/hcloud-ruby/pull/45) ([aufziehvogel](https://github.com/aufziehvogel))
data/Gemfile.lock CHANGED
@@ -1,110 +1,120 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hcloud (1.0.3)
4
+ hcloud (1.3.0)
5
5
  activemodel
6
+ activesupport
6
7
  oj
7
8
  typhoeus
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- activemodel (7.0.3)
13
- activesupport (= 7.0.3)
14
- activesupport (7.0.3)
13
+ activemodel (7.1.1)
14
+ activesupport (= 7.1.1)
15
+ activesupport (7.1.1)
16
+ base64
17
+ bigdecimal
15
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ connection_pool (>= 2.2.5)
20
+ drb
16
21
  i18n (>= 1.6, < 2)
17
22
  minitest (>= 5.1)
23
+ mutex_m
18
24
  tzinfo (~> 2.0)
19
- addressable (2.8.0)
20
- public_suffix (>= 2.0.2, < 5.0)
25
+ addressable (2.8.1)
26
+ public_suffix (>= 2.0.2, < 6.0)
21
27
  ast (2.4.2)
28
+ base64 (0.1.1)
29
+ bigdecimal (3.1.4)
22
30
  builder (3.2.4)
23
31
  codecov (0.6.0)
24
32
  simplecov (>= 0.15, < 0.22)
25
33
  coderay (1.1.3)
26
34
  concurrent-ruby (1.1.10)
35
+ connection_pool (2.4.1)
27
36
  crack (0.4.5)
28
37
  rexml
29
38
  diff-lcs (1.5.0)
30
39
  docile (1.4.0)
31
- dry-configurable (0.15.0)
32
- concurrent-ruby (~> 1.0)
33
- dry-core (~> 0.6)
34
- dry-container (0.9.0)
40
+ drb (2.1.1)
41
+ ruby2_keywords
42
+ dry-core (1.0.0)
35
43
  concurrent-ruby (~> 1.0)
36
- dry-configurable (~> 0.13, >= 0.13.0)
37
- dry-core (0.7.1)
44
+ zeitwerk (~> 2.6)
45
+ dry-inflector (1.0.0)
46
+ dry-logic (1.5.0)
38
47
  concurrent-ruby (~> 1.0)
39
- dry-inflector (0.2.1)
40
- dry-logic (1.2.0)
48
+ dry-core (~> 1.0, < 2)
49
+ zeitwerk (~> 2.6)
50
+ dry-types (1.7.0)
41
51
  concurrent-ruby (~> 1.0)
42
- dry-core (~> 0.5, >= 0.5)
43
- dry-types (1.5.1)
44
- concurrent-ruby (~> 1.0)
45
- dry-container (~> 0.3)
46
- dry-core (~> 0.5, >= 0.5)
47
- dry-inflector (~> 0.1, >= 0.1.2)
48
- dry-logic (~> 1.0, >= 1.0.2)
49
- ethon (0.15.0)
52
+ dry-core (~> 1.0, < 2)
53
+ dry-inflector (~> 1.0, < 2)
54
+ dry-logic (>= 1.4, < 2)
55
+ zeitwerk (~> 2.6)
56
+ ethon (0.16.0)
50
57
  ffi (>= 1.15.0)
51
- faker (2.20.0)
58
+ faker (3.0.0)
52
59
  i18n (>= 1.8.11, < 2)
53
- ffi (1.15.5)
54
- grape (1.6.2)
55
- activesupport
60
+ ffi (1.16.3)
61
+ grape (1.8.0)
62
+ activesupport (>= 5)
56
63
  builder
57
64
  dry-types (>= 1.1)
58
65
  mustermann-grape (~> 1.0.0)
59
66
  rack (>= 1.3.0)
60
67
  rack-accept
61
68
  hashdiff (1.0.1)
62
- i18n (1.10.0)
69
+ i18n (1.12.0)
63
70
  concurrent-ruby (~> 1.0)
71
+ json (2.6.2)
64
72
  method_source (1.0.0)
65
- minitest (5.15.0)
66
- mustermann (1.1.1)
73
+ minitest (5.16.3)
74
+ mustermann (3.0.0)
67
75
  ruby2_keywords (~> 0.0.1)
68
76
  mustermann-grape (1.0.2)
69
77
  mustermann (>= 1.0.0)
70
- oj (3.13.11)
78
+ mutex_m (0.1.2)
79
+ oj (3.16.3)
80
+ bigdecimal (>= 3.0)
71
81
  parallel (1.22.1)
72
- parser (3.1.2.0)
82
+ parser (3.1.3.0)
73
83
  ast (~> 2.4.1)
74
84
  pry (0.14.1)
75
85
  coderay (~> 1.1)
76
86
  method_source (~> 1.0)
77
- public_suffix (4.0.7)
78
- rack (2.2.3.1)
87
+ public_suffix (5.0.0)
88
+ rack (3.0.6.1)
79
89
  rack-accept (0.4.5)
80
90
  rack (>= 0.4)
81
91
  rainbow (3.1.1)
82
- rake (13.0.6)
83
- regexp_parser (2.4.0)
92
+ regexp_parser (2.6.1)
84
93
  rexml (3.2.5)
85
- rspec (3.11.0)
86
- rspec-core (~> 3.11.0)
87
- rspec-expectations (~> 3.11.0)
88
- rspec-mocks (~> 3.11.0)
89
- rspec-core (3.11.0)
90
- rspec-support (~> 3.11.0)
91
- rspec-expectations (3.11.0)
94
+ rspec (3.12.0)
95
+ rspec-core (~> 3.12.0)
96
+ rspec-expectations (~> 3.12.0)
97
+ rspec-mocks (~> 3.12.0)
98
+ rspec-core (3.12.0)
99
+ rspec-support (~> 3.12.0)
100
+ rspec-expectations (3.12.0)
92
101
  diff-lcs (>= 1.2.0, < 2.0)
93
- rspec-support (~> 3.11.0)
94
- rspec-mocks (3.11.1)
102
+ rspec-support (~> 3.12.0)
103
+ rspec-mocks (3.12.0)
95
104
  diff-lcs (>= 1.2.0, < 2.0)
96
- rspec-support (~> 3.11.0)
97
- rspec-support (3.11.0)
98
- rubocop (1.29.0)
105
+ rspec-support (~> 3.12.0)
106
+ rspec-support (3.12.0)
107
+ rubocop (1.39.0)
108
+ json (~> 2.3)
99
109
  parallel (~> 1.10)
100
- parser (>= 3.1.0.0)
110
+ parser (>= 3.1.2.1)
101
111
  rainbow (>= 2.2.2, < 4.0)
102
112
  regexp_parser (>= 1.8, < 3.0)
103
113
  rexml (>= 3.2.5, < 4.0)
104
- rubocop-ast (>= 1.17.0, < 2.0)
114
+ rubocop-ast (>= 1.23.0, < 2.0)
105
115
  ruby-progressbar (~> 1.7)
106
116
  unicode-display_width (>= 1.4.0, < 3.0)
107
- rubocop-ast (1.17.0)
117
+ rubocop-ast (1.23.0)
108
118
  parser (>= 3.1.1.0)
109
119
  ruby-progressbar (1.11.0)
110
120
  ruby2_keywords (0.0.5)
@@ -114,32 +124,31 @@ GEM
114
124
  simplecov_json_formatter (~> 0.1)
115
125
  simplecov-html (0.12.3)
116
126
  simplecov_json_formatter (0.1.4)
117
- typhoeus (1.4.0)
127
+ typhoeus (1.4.1)
118
128
  ethon (>= 0.9.0)
119
- tzinfo (2.0.4)
129
+ tzinfo (2.0.5)
120
130
  concurrent-ruby (~> 1.0)
121
- unicode-display_width (2.1.0)
122
- webmock (3.14.0)
131
+ unicode-display_width (2.3.0)
132
+ webmock (3.18.1)
123
133
  addressable (>= 2.8.0)
124
134
  crack (>= 0.3.2)
125
135
  hashdiff (>= 0.4.0, < 2.0.0)
136
+ zeitwerk (2.6.6)
126
137
 
127
138
  PLATFORMS
128
139
  ruby
129
140
  x86_64-linux
130
141
 
131
142
  DEPENDENCIES
132
- activemodel
133
143
  bundler
134
144
  codecov
135
145
  faker
136
146
  grape
137
147
  hcloud!
138
148
  pry
139
- rake
140
149
  rspec
141
150
  rubocop
142
151
  webmock
143
152
 
144
153
  BUNDLED WITH
145
- 2.3.9
154
+ 2.3.25
data/hcloud.gemspec CHANGED
@@ -23,13 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency 'activemodel'
27
26
  spec.add_development_dependency 'bundler'
28
27
  spec.add_development_dependency 'grape'
29
- spec.add_development_dependency 'rake'
30
28
  spec.add_development_dependency 'rspec'
31
29
  spec.add_development_dependency 'webmock'
32
30
  spec.add_runtime_dependency 'activemodel'
31
+ spec.add_runtime_dependency 'activesupport'
33
32
  spec.add_runtime_dependency 'oj'
34
33
  spec.add_runtime_dependency 'typhoeus'
35
34
  end
@@ -12,7 +12,7 @@ module Hcloud
12
12
  def bind_to(klass)
13
13
  resource = self
14
14
  %w[find find_by where all [] page limit per_page order
15
- to_a count pagnation each].each do |method|
15
+ to_a count pagnation pagination each].each do |method|
16
16
  klass.define_singleton_method(method) do |*args, &block|
17
17
  resource.new(client: Client.connection).public_send(method, *args, &block)
18
18
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hcloud
4
+ class Certificate
5
+ require 'hcloud/certificate_resource'
6
+
7
+ include EntryLoader
8
+
9
+ schema(
10
+ created: :time
11
+ )
12
+
13
+ updatable :name
14
+ destructible
15
+
16
+ has_actions
17
+
18
+ def retry
19
+ prepare_request('actions/retry', j: COLLECT_ARGS.call(__method__, binding))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hcloud
4
+ class CertificateResource < AbstractResource
5
+ filter_attributes :name, :label_selector, :type
6
+
7
+ def [](arg)
8
+ case arg
9
+ when Integer then find_by(id: arg)
10
+ when String then find_by(name: arg)
11
+ end
12
+ end
13
+
14
+ def create(
15
+ name:,
16
+ type: :uploaded,
17
+ certificate: nil,
18
+ private_key: nil,
19
+ domain_names: nil,
20
+ labels: {}
21
+ )
22
+ raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
23
+
24
+ case type
25
+ when :uploaded
26
+ raise Hcloud::Error::InvalidInput, 'no certificate given' if certificate.blank?
27
+ raise Hcloud::Error::InvalidInput, 'no private_key given' if private_key.blank?
28
+ when :managed
29
+ raise Hcloud::Error::InvalidInput, 'no domain_names given' if domain_names.to_a.empty?
30
+ end
31
+
32
+ prepare_request(
33
+ 'certificates', j: COLLECT_ARGS.call(__method__, binding),
34
+ expected_code: 201
35
+ ) do |response|
36
+ [
37
+ Action.new(client, response.parsed_json[:action]),
38
+ Certificate.new(client, response.parsed_json[:certificate])
39
+ ]
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/hcloud/client.rb CHANGED
@@ -86,10 +86,18 @@ module Hcloud
86
86
  SSHKeyResource.new(client: self)
87
87
  end
88
88
 
89
+ def certificates
90
+ CertificateResource.new(client: self)
91
+ end
92
+
89
93
  def floating_ips
90
94
  FloatingIPResource.new(client: self)
91
95
  end
92
96
 
97
+ def primary_ips
98
+ PrimaryIPResource.new(client: self)
99
+ end
100
+
93
101
  def networks
94
102
  NetworkResource.new(client: self)
95
103
  end
@@ -102,6 +110,18 @@ module Hcloud
102
110
  VolumeResource.new(client: self)
103
111
  end
104
112
 
113
+ def placement_groups
114
+ PlacementGroupResource.new(client: self)
115
+ end
116
+
117
+ def load_balancer_types
118
+ LoadBalancerTypeResource.new(client: self)
119
+ end
120
+
121
+ def load_balancers
122
+ LoadBalancerResource.new(client: self)
123
+ end
124
+
105
125
  class ResourceFuture < Delegator
106
126
  def initialize(request) # rubocop:disable Lint/MissingSuper
107
127
  @request = request
@@ -68,6 +68,27 @@ module Hcloud
68
68
  end
69
69
  end
70
70
 
71
+ def has_metrics # rubocop:disable Naming/PredicateName
72
+ define_method(:metrics) do |**kwargs|
73
+ raise Hcloud::Error::InvalidInput, 'no type given' if kwargs[:type].blank?
74
+ raise Hcloud::Error::InvalidInput, 'no start given' if kwargs[:start].blank?
75
+ raise Hcloud::Error::InvalidInput, 'no end given' if kwargs[:end].blank?
76
+ if kwargs[:start] > kwargs[:end]
77
+ raise Hcloud::Error::InvalidInput, 'start time must be before end time'
78
+ end
79
+
80
+ params = {
81
+ type: kwargs[:type],
82
+ start: kwargs[:start].iso8601,
83
+ end: kwargs[:end].iso8601,
84
+ step: kwargs[:step].to_i
85
+ }
86
+ prepare_request('metrics', method: :get, params: params) do |response|
87
+ response.parsed_json[:metrics].with_indifferent_access
88
+ end
89
+ end
90
+ end
91
+
71
92
  def resource_class
72
93
  ancestors.reverse.find { |const| const.include?(Hcloud::EntryLoader) }
73
94
  end
@@ -202,49 +223,17 @@ module Hcloud
202
223
  instance_variable_set("@#{key}", value)
203
224
  end
204
225
 
205
- # rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
206
226
  def _load(resource)
207
227
  return if resource.nil?
208
228
 
209
229
  @_attributes = {}.with_indifferent_access
210
230
 
211
- resource.each do |key, value|
212
- definition = self.class.schema[key]
213
-
214
- if definition == :time
215
- _update_attribute(key, value ? Time.parse(value) : nil)
216
- next
217
- end
218
-
219
- if definition.is_a?(Class) && definition.include?(EntryLoader)
220
- _update_attribute(key, value ? definition.new(client, value) : nil)
221
- next
222
- end
223
-
224
- # if schema definition is [Class]
225
- if definition.is_a?(Array) && definition.first.include?(EntryLoader)
226
-
227
- # just set attribute to an empty array if value is no array or empty
228
- if !value.is_a?(Array) || value.empty?
229
- _update_attribute(key, [])
230
- next
231
- end
232
-
233
- if value.first.is_a?(Integer)
234
- # If value is an integer, this is the id of an object which's class can be
235
- # retreived from definition. Load a future object that can on access retreive the
236
- # data from the api and convert it to a proper object.
237
- _update_attribute(key, value.map { |id| Future.new(client, definition.first, id) })
238
- else
239
- # Otherwise the value *is* the content of the object
240
- _update_attribute(key, value.map { |item| definition.first.new(client, item) })
241
- end
242
- next
243
- end
231
+ loader = Hcloud::ResourceLoader.new(self.class.schema, client: client)
232
+ loaded_data = loader.load(resource)
244
233
 
234
+ loaded_data.each do |key, value|
245
235
  _update_attribute(key, value.is_a?(Hash) ? value.with_indifferent_access : value)
246
236
  end
247
237
  end
248
- # rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
249
238
  end
250
239
  end
@@ -6,20 +6,31 @@ module Hcloud
6
6
 
7
7
  include EntryLoader
8
8
 
9
+ schema(
10
+ created: :time
11
+ )
12
+
9
13
  updatable :name
10
14
  destructible
11
15
 
12
16
  has_actions
13
17
 
14
- def set_rules(rules:) # rubocop:disable Naming/AccessorMethodName
18
+ def set_rules(rules:)
19
+ # Set rules to empty when nil is passed
20
+ rules = rules.to_a
21
+
15
22
  prepare_request('actions/set_rules', j: COLLECT_ARGS.call(__method__, binding))
16
23
  end
17
24
 
18
25
  def apply_to_resources(apply_to:)
26
+ raise Hcloud::Error::InvalidInput, 'no apply_to resources given' if apply_to.nil?
27
+
19
28
  prepare_request('actions/apply_to_resources', j: COLLECT_ARGS.call(__method__, binding))
20
29
  end
21
30
 
22
31
  def remove_from_resources(remove_from:)
32
+ raise Hcloud::Error::InvalidInput, 'no remove_from resources given' if remove_from.nil?
33
+
23
34
  prepare_request('actions/remove_from_resources', j: COLLECT_ARGS.call(__method__, binding))
24
35
  end
25
36
  end
@@ -12,11 +12,18 @@ module Hcloud
12
12
  end
13
13
 
14
14
  def create(name:, rules: [], apply_to: [], labels: {})
15
+ raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?
16
+
15
17
  prepare_request(
16
18
  'firewalls', j: COLLECT_ARGS.call(__method__, binding),
17
19
  expected_code: 201
18
20
  ) do |response|
19
- Firewall.new(client, response.parsed_json[:firewall])
21
+ [
22
+ response.parsed_json[:actions].map do |action|
23
+ Action.new(client, action)
24
+ end,
25
+ Firewall.new(client, response.parsed_json[:firewall])
26
+ ]
20
27
  end
21
28
  end
22
29
  end
@@ -12,12 +12,14 @@ module Hcloud
12
12
  )
13
13
 
14
14
  protectable :delete
15
- updatable :description
15
+ updatable :name, :description
16
16
  destructible
17
17
 
18
18
  has_actions
19
19
 
20
20
  def assign(server:)
21
+ raise Hcloud::Error::InvalidInput, 'no server given' if server.nil?
22
+
21
23
  prepare_request('actions/assign', j: COLLECT_ARGS.call(__method__, binding))
22
24
  end
23
25
 
@@ -26,6 +28,8 @@ module Hcloud
26
28
  end
27
29
 
28
30
  def change_dns_ptr(ip:, dns_ptr:)
31
+ raise Hcloud::Error::InvalidInput, 'no IP given' if ip.blank?
32
+
29
33
  prepare_request('actions/change_dns_ptr', j: COLLECT_ARGS.call(__method__, binding))
30
34
  end
31
35
  end
@@ -13,7 +13,12 @@ module Hcloud
13
13
  end
14
14
  end
15
15
 
16
- def create(type:, server: nil, home_location: nil, description: nil, labels: {})
16
+ def create(type:, name: nil, server: nil, home_location: nil, description: nil, labels: {})
17
+ raise Hcloud::Error::InvalidInput, 'no type given' if type.blank?
18
+ if server.nil? && home_location.nil?
19
+ raise Hcloud::Error::InvalidInput, 'either server or home_location must be given'
20
+ end
21
+
17
22
  prepare_request(
18
23
  'floating_ips', j: COLLECT_ARGS.call(__method__, binding),
19
24
  expected_code: 201
data/lib/hcloud/future.rb CHANGED
@@ -4,10 +4,13 @@ require 'active_support/core_ext/string/inflections'
4
4
 
5
5
  module Hcloud
6
6
  class Future < Delegator
7
+ attr_reader :raw_data
8
+
7
9
  # rubocop: disable Lint/MissingSuper
8
- def initialize(client, target_class, id)
10
+ def initialize(client, target_class, id, raw_data: nil)
9
11
  @target_class = target_class
10
12
  @id = id
13
+ @raw_data = raw_data
11
14
  @__client = client
12
15
  end
13
16
  # rubocop: enable Lint/MissingSuper
data/lib/hcloud/image.rb CHANGED
@@ -15,6 +15,8 @@ module Hcloud
15
15
  updatable :description, :type
16
16
  destructible
17
17
 
18
+ has_actions
19
+
18
20
  def to_snapshot
19
21
  update(type: 'snapshot')
20
22
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Hcloud
4
4
  class ImageResource < AbstractResource
5
- filter_attributes :type, :bound_to, :name, :label_selector
5
+ filter_attributes :type, :bound_to, :name, :label_selector, :status, :include_deprecated
6
6
 
7
7
  bind_to Image
8
8