ionoscloud 5.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (300) hide show
  1. checksums.yaml +7 -0
  2. data/DOCS.md +14618 -0
  3. data/Gemfile +9 -0
  4. data/README.md +55 -0
  5. data/Rakefile +10 -0
  6. data/git_push.sh +58 -0
  7. data/ionoscloud.gemspec +38 -0
  8. data/lib/ionoscloud.rb +181 -0
  9. data/lib/ionoscloud/api/_api.rb +96 -0
  10. data/lib/ionoscloud/api/backup_unit_api.rb +583 -0
  11. data/lib/ionoscloud/api/contract_api.rb +96 -0
  12. data/lib/ionoscloud/api/data_center_api.rb +532 -0
  13. data/lib/ionoscloud/api/image_api.rb +432 -0
  14. data/lib/ionoscloud/api/ip_blocks_api.rb +514 -0
  15. data/lib/ionoscloud/api/kubernetes_api.rb +1479 -0
  16. data/lib/ionoscloud/api/label_api.rb +2460 -0
  17. data/lib/ionoscloud/api/lan_api.rb +858 -0
  18. data/lib/ionoscloud/api/load_balancer_api.rb +950 -0
  19. data/lib/ionoscloud/api/location_api.rb +262 -0
  20. data/lib/ionoscloud/api/nic_api.rb +1222 -0
  21. data/lib/ionoscloud/api/private_cross_connect_api.rb +426 -0
  22. data/lib/ionoscloud/api/request_api.rb +283 -0
  23. data/lib/ionoscloud/api/server_api.rb +1679 -0
  24. data/lib/ionoscloud/api/snapshot_api.rb +432 -0
  25. data/lib/ionoscloud/api/user_management_api.rb +2495 -0
  26. data/lib/ionoscloud/api/volume_api.rb +763 -0
  27. data/lib/ionoscloud/api_client.rb +521 -0
  28. data/lib/ionoscloud/api_error.rb +57 -0
  29. data/lib/ionoscloud/configuration.rb +291 -0
  30. data/lib/ionoscloud/models/attached_volumes.rb +278 -0
  31. data/lib/ionoscloud/models/backup_unit.rb +294 -0
  32. data/lib/ionoscloud/models/backup_unit_properties.rb +242 -0
  33. data/lib/ionoscloud/models/backup_unit_sso.rb +217 -0
  34. data/lib/ionoscloud/models/backup_units.rb +283 -0
  35. data/lib/ionoscloud/models/balanced_nics.rb +278 -0
  36. data/lib/ionoscloud/models/cdroms.rb +278 -0
  37. data/lib/ionoscloud/models/connectable_datacenter.rb +234 -0
  38. data/lib/ionoscloud/models/contract.rb +231 -0
  39. data/lib/ionoscloud/models/contract_properties.rb +256 -0
  40. data/lib/ionoscloud/models/data_center_entities.rb +243 -0
  41. data/lib/ionoscloud/models/datacenter.rb +269 -0
  42. data/lib/ionoscloud/models/datacenter_element_metadata.rb +321 -0
  43. data/lib/ionoscloud/models/datacenter_properties.rb +296 -0
  44. data/lib/ionoscloud/models/datacenters.rb +278 -0
  45. data/lib/ionoscloud/models/error.rb +228 -0
  46. data/lib/ionoscloud/models/error_message.rb +227 -0
  47. data/lib/ionoscloud/models/firewall_rule.rb +260 -0
  48. data/lib/ionoscloud/models/firewall_rules.rb +278 -0
  49. data/lib/ionoscloud/models/firewallrule_properties.rb +468 -0
  50. data/lib/ionoscloud/models/group.rb +260 -0
  51. data/lib/ionoscloud/models/group_entities.rb +225 -0
  52. data/lib/ionoscloud/models/group_members.rb +249 -0
  53. data/lib/ionoscloud/models/group_properties.rb +307 -0
  54. data/lib/ionoscloud/models/group_share.rb +251 -0
  55. data/lib/ionoscloud/models/group_share_properties.rb +227 -0
  56. data/lib/ionoscloud/models/group_shares.rb +249 -0
  57. data/lib/ionoscloud/models/group_users.rb +250 -0
  58. data/lib/ionoscloud/models/groups.rb +249 -0
  59. data/lib/ionoscloud/models/image.rb +260 -0
  60. data/lib/ionoscloud/models/image_properties.rb +428 -0
  61. data/lib/ionoscloud/models/images.rb +249 -0
  62. data/lib/ionoscloud/models/info.rb +237 -0
  63. data/lib/ionoscloud/models/ip_block.rb +260 -0
  64. data/lib/ionoscloud/models/ip_block_properties.rb +271 -0
  65. data/lib/ionoscloud/models/ip_blocks.rb +249 -0
  66. data/lib/ionoscloud/models/ip_consumer.rb +270 -0
  67. data/lib/ionoscloud/models/ip_failover.rb +225 -0
  68. data/lib/ionoscloud/models/kubernetes_auto_scaling.rb +227 -0
  69. data/lib/ionoscloud/models/kubernetes_cluster.rb +303 -0
  70. data/lib/ionoscloud/models/kubernetes_cluster_entities.rb +216 -0
  71. data/lib/ionoscloud/models/kubernetes_cluster_properties.rb +265 -0
  72. data/lib/ionoscloud/models/kubernetes_cluster_properties_for_post_and_put.rb +241 -0
  73. data/lib/ionoscloud/models/kubernetes_clusters.rb +283 -0
  74. data/lib/ionoscloud/models/kubernetes_config.rb +285 -0
  75. data/lib/ionoscloud/models/kubernetes_config_properties.rb +217 -0
  76. data/lib/ionoscloud/models/kubernetes_maintenance_window.rb +261 -0
  77. data/lib/ionoscloud/models/kubernetes_node.rb +294 -0
  78. data/lib/ionoscloud/models/kubernetes_node_metadata.rb +291 -0
  79. data/lib/ionoscloud/models/kubernetes_node_pool.rb +294 -0
  80. data/lib/ionoscloud/models/kubernetes_node_pool_for_put.rb +294 -0
  81. data/lib/ionoscloud/models/kubernetes_node_pool_lan.rb +217 -0
  82. data/lib/ionoscloud/models/kubernetes_node_pool_properties.rb +476 -0
  83. data/lib/ionoscloud/models/kubernetes_node_pool_properties_for_post.rb +464 -0
  84. data/lib/ionoscloud/models/kubernetes_node_pool_properties_for_put.rb +464 -0
  85. data/lib/ionoscloud/models/kubernetes_node_pools.rb +283 -0
  86. data/lib/ionoscloud/models/kubernetes_node_properties.rb +252 -0
  87. data/lib/ionoscloud/models/kubernetes_nodes.rb +283 -0
  88. data/lib/ionoscloud/models/label.rb +294 -0
  89. data/lib/ionoscloud/models/label_properties.rb +257 -0
  90. data/lib/ionoscloud/models/label_resource.rb +294 -0
  91. data/lib/ionoscloud/models/label_resource_properties.rb +227 -0
  92. data/lib/ionoscloud/models/label_resources.rb +312 -0
  93. data/lib/ionoscloud/models/labels.rb +283 -0
  94. data/lib/ionoscloud/models/lan.rb +269 -0
  95. data/lib/ionoscloud/models/lan_entities.rb +216 -0
  96. data/lib/ionoscloud/models/lan_nics.rb +278 -0
  97. data/lib/ionoscloud/models/lan_post.rb +269 -0
  98. data/lib/ionoscloud/models/lan_properties.rb +249 -0
  99. data/lib/ionoscloud/models/lan_properties_post.rb +249 -0
  100. data/lib/ionoscloud/models/lans.rb +278 -0
  101. data/lib/ionoscloud/models/loadbalancer.rb +269 -0
  102. data/lib/ionoscloud/models/loadbalancer_entities.rb +216 -0
  103. data/lib/ionoscloud/models/loadbalancer_properties.rb +271 -0
  104. data/lib/ionoscloud/models/loadbalancers.rb +278 -0
  105. data/lib/ionoscloud/models/location.rb +260 -0
  106. data/lib/ionoscloud/models/location_properties.rb +263 -0
  107. data/lib/ionoscloud/models/locations.rb +249 -0
  108. data/lib/ionoscloud/models/nic.rb +269 -0
  109. data/lib/ionoscloud/models/nic_entities.rb +216 -0
  110. data/lib/ionoscloud/models/nic_properties.rb +284 -0
  111. data/lib/ionoscloud/models/nics.rb +278 -0
  112. data/lib/ionoscloud/models/no_state_meta_data.rb +277 -0
  113. data/lib/ionoscloud/models/pagination_links.rb +237 -0
  114. data/lib/ionoscloud/models/peer.rb +252 -0
  115. data/lib/ionoscloud/models/private_cross_connect.rb +260 -0
  116. data/lib/ionoscloud/models/private_cross_connect_properties.rb +251 -0
  117. data/lib/ionoscloud/models/private_cross_connects.rb +249 -0
  118. data/lib/ionoscloud/models/request.rb +260 -0
  119. data/lib/ionoscloud/models/request_metadata.rb +246 -0
  120. data/lib/ionoscloud/models/request_properties.rb +245 -0
  121. data/lib/ionoscloud/models/request_status.rb +246 -0
  122. data/lib/ionoscloud/models/request_status_metadata.rb +280 -0
  123. data/lib/ionoscloud/models/request_target.rb +259 -0
  124. data/lib/ionoscloud/models/requests.rb +293 -0
  125. data/lib/ionoscloud/models/resource.rb +265 -0
  126. data/lib/ionoscloud/models/resource_entities.rb +216 -0
  127. data/lib/ionoscloud/models/resource_groups.rb +250 -0
  128. data/lib/ionoscloud/models/resource_limits.rb +462 -0
  129. data/lib/ionoscloud/models/resource_properties.rb +227 -0
  130. data/lib/ionoscloud/models/resource_reference.rb +242 -0
  131. data/lib/ionoscloud/models/resources.rb +250 -0
  132. data/lib/ionoscloud/models/resources_users.rb +250 -0
  133. data/lib/ionoscloud/models/s3_key.rb +260 -0
  134. data/lib/ionoscloud/models/s3_key_metadata.rb +227 -0
  135. data/lib/ionoscloud/models/s3_key_properties.rb +227 -0
  136. data/lib/ionoscloud/models/s3_keys.rb +249 -0
  137. data/lib/ionoscloud/models/s3_object_storage_sso.rb +217 -0
  138. data/lib/ionoscloud/models/server.rb +269 -0
  139. data/lib/ionoscloud/models/server_entities.rb +234 -0
  140. data/lib/ionoscloud/models/server_properties.rb +341 -0
  141. data/lib/ionoscloud/models/servers.rb +278 -0
  142. data/lib/ionoscloud/models/snapshot.rb +260 -0
  143. data/lib/ionoscloud/models/snapshot_properties.rb +401 -0
  144. data/lib/ionoscloud/models/snapshots.rb +249 -0
  145. data/lib/ionoscloud/models/type.rb +59 -0
  146. data/lib/ionoscloud/models/user.rb +269 -0
  147. data/lib/ionoscloud/models/user_metadata.rb +237 -0
  148. data/lib/ionoscloud/models/user_properties.rb +297 -0
  149. data/lib/ionoscloud/models/users.rb +249 -0
  150. data/lib/ionoscloud/models/users_entities.rb +225 -0
  151. data/lib/ionoscloud/models/volume.rb +260 -0
  152. data/lib/ionoscloud/models/volume_properties.rb +463 -0
  153. data/lib/ionoscloud/models/volumes.rb +278 -0
  154. data/lib/ionoscloud/version.rb +15 -0
  155. data/spec/api/_api_spec.rb +49 -0
  156. data/spec/api/backup_unit_api_spec.rb +140 -0
  157. data/spec/api/contract_api_spec.rb +49 -0
  158. data/spec/api/data_center_api_spec.rb +128 -0
  159. data/spec/api/image_api_spec.rb +111 -0
  160. data/spec/api/ip_blocks_api_spec.rb +126 -0
  161. data/spec/api/kubernetes_api_spec.rb +306 -0
  162. data/spec/api/label_api_spec.rb +480 -0
  163. data/spec/api/lan_api_spec.rb +186 -0
  164. data/spec/api/load_balancer_api_spec.rb +203 -0
  165. data/spec/api/location_api_spec.rb +80 -0
  166. data/spec/api/nic_api_spec.rb +251 -0
  167. data/spec/api/private_cross_connect_api_spec.rb +110 -0
  168. data/spec/api/request_api_spec.rb +84 -0
  169. data/spec/api/server_api_spec.rb +337 -0
  170. data/spec/api/snapshot_api_spec.rb +111 -0
  171. data/spec/api/user_management_api_spec.rb +495 -0
  172. data/spec/api/volume_api_spec.rb +171 -0
  173. data/spec/api_client_spec.rb +226 -0
  174. data/spec/configuration_spec.rb +42 -0
  175. data/spec/models/attached_volumes_spec.rb +70 -0
  176. data/spec/models/backup_unit_properties_spec.rb +46 -0
  177. data/spec/models/backup_unit_spec.rb +62 -0
  178. data/spec/models/backup_unit_sso_spec.rb +34 -0
  179. data/spec/models/backup_units_spec.rb +56 -0
  180. data/spec/models/balanced_nics_spec.rb +70 -0
  181. data/spec/models/cdroms_spec.rb +70 -0
  182. data/spec/models/connectable_datacenter_spec.rb +46 -0
  183. data/spec/models/contract_properties_spec.rb +58 -0
  184. data/spec/models/contract_spec.rb +40 -0
  185. data/spec/models/data_center_entities_spec.rb +52 -0
  186. data/spec/models/datacenter_element_metadata_spec.rb +80 -0
  187. data/spec/models/datacenter_properties_spec.rb +68 -0
  188. data/spec/models/datacenter_spec.rb +64 -0
  189. data/spec/models/datacenters_spec.rb +70 -0
  190. data/spec/models/error_message_spec.rb +40 -0
  191. data/spec/models/error_spec.rb +40 -0
  192. data/spec/models/firewall_rule_spec.rb +58 -0
  193. data/spec/models/firewall_rules_spec.rb +70 -0
  194. data/spec/models/firewallrule_properties_spec.rb +98 -0
  195. data/spec/models/group_entities_spec.rb +40 -0
  196. data/spec/models/group_members_spec.rb +52 -0
  197. data/spec/models/group_properties_spec.rb +88 -0
  198. data/spec/models/group_share_properties_spec.rb +40 -0
  199. data/spec/models/group_share_spec.rb +52 -0
  200. data/spec/models/group_shares_spec.rb +52 -0
  201. data/spec/models/group_spec.rb +58 -0
  202. data/spec/models/group_users_spec.rb +52 -0
  203. data/spec/models/groups_spec.rb +52 -0
  204. data/spec/models/image_properties_spec.rb +138 -0
  205. data/spec/models/image_spec.rb +58 -0
  206. data/spec/models/images_spec.rb +52 -0
  207. data/spec/models/info_spec.rb +46 -0
  208. data/spec/models/ip_block_properties_spec.rb +58 -0
  209. data/spec/models/ip_block_spec.rb +58 -0
  210. data/spec/models/ip_blocks_spec.rb +52 -0
  211. data/spec/models/ip_consumer_spec.rb +70 -0
  212. data/spec/models/ip_failover_spec.rb +40 -0
  213. data/spec/models/kubernetes_auto_scaling_spec.rb +40 -0
  214. data/spec/models/kubernetes_cluster_entities_spec.rb +34 -0
  215. data/spec/models/kubernetes_cluster_properties_for_post_and_put_spec.rb +46 -0
  216. data/spec/models/kubernetes_cluster_properties_spec.rb +58 -0
  217. data/spec/models/kubernetes_cluster_spec.rb +68 -0
  218. data/spec/models/kubernetes_clusters_spec.rb +56 -0
  219. data/spec/models/kubernetes_config_properties_spec.rb +34 -0
  220. data/spec/models/kubernetes_config_spec.rb +56 -0
  221. data/spec/models/kubernetes_maintenance_window_spec.rb +44 -0
  222. data/spec/models/kubernetes_node_metadata_spec.rb +62 -0
  223. data/spec/models/kubernetes_node_pool_for_put_spec.rb +62 -0
  224. data/spec/models/kubernetes_node_pool_lan_spec.rb +34 -0
  225. data/spec/models/kubernetes_node_pool_properties_for_post_spec.rb +132 -0
  226. data/spec/models/kubernetes_node_pool_properties_for_put_spec.rb +132 -0
  227. data/spec/models/kubernetes_node_pool_properties_spec.rb +138 -0
  228. data/spec/models/kubernetes_node_pool_spec.rb +62 -0
  229. data/spec/models/kubernetes_node_pools_spec.rb +56 -0
  230. data/spec/models/kubernetes_node_properties_spec.rb +46 -0
  231. data/spec/models/kubernetes_node_spec.rb +62 -0
  232. data/spec/models/kubernetes_nodes_spec.rb +56 -0
  233. data/spec/models/label_properties_spec.rb +58 -0
  234. data/spec/models/label_resource_properties_spec.rb +40 -0
  235. data/spec/models/label_resource_spec.rb +62 -0
  236. data/spec/models/label_resources_spec.rb +74 -0
  237. data/spec/models/label_spec.rb +62 -0
  238. data/spec/models/labels_spec.rb +56 -0
  239. data/spec/models/lan_entities_spec.rb +34 -0
  240. data/spec/models/lan_nics_spec.rb +70 -0
  241. data/spec/models/lan_post_spec.rb +64 -0
  242. data/spec/models/lan_properties_post_spec.rb +52 -0
  243. data/spec/models/lan_properties_spec.rb +52 -0
  244. data/spec/models/lan_spec.rb +64 -0
  245. data/spec/models/lans_spec.rb +70 -0
  246. data/spec/models/loadbalancer_entities_spec.rb +34 -0
  247. data/spec/models/loadbalancer_properties_spec.rb +50 -0
  248. data/spec/models/loadbalancer_spec.rb +64 -0
  249. data/spec/models/loadbalancers_spec.rb +70 -0
  250. data/spec/models/location_properties_spec.rb +50 -0
  251. data/spec/models/location_spec.rb +58 -0
  252. data/spec/models/locations_spec.rb +52 -0
  253. data/spec/models/nic_entities_spec.rb +34 -0
  254. data/spec/models/nic_properties_spec.rb +70 -0
  255. data/spec/models/nic_spec.rb +64 -0
  256. data/spec/models/nics_spec.rb +70 -0
  257. data/spec/models/no_state_meta_data_spec.rb +70 -0
  258. data/spec/models/pagination_links_spec.rb +46 -0
  259. data/spec/models/peer_spec.rb +58 -0
  260. data/spec/models/private_cross_connect_properties_spec.rb +52 -0
  261. data/spec/models/private_cross_connect_spec.rb +58 -0
  262. data/spec/models/private_cross_connects_spec.rb +52 -0
  263. data/spec/models/request_metadata_spec.rb +52 -0
  264. data/spec/models/request_properties_spec.rb +52 -0
  265. data/spec/models/request_spec.rb +58 -0
  266. data/spec/models/request_status_metadata_spec.rb +56 -0
  267. data/spec/models/request_status_spec.rb +52 -0
  268. data/spec/models/request_target_spec.rb +44 -0
  269. data/spec/models/requests_spec.rb +70 -0
  270. data/spec/models/resource_entities_spec.rb +34 -0
  271. data/spec/models/resource_groups_spec.rb +52 -0
  272. data/spec/models/resource_limits_spec.rb +130 -0
  273. data/spec/models/resource_properties_spec.rb +40 -0
  274. data/spec/models/resource_reference_spec.rb +46 -0
  275. data/spec/models/resource_spec.rb +64 -0
  276. data/spec/models/resources_spec.rb +52 -0
  277. data/spec/models/resources_users_spec.rb +52 -0
  278. data/spec/models/s3_key_metadata_spec.rb +40 -0
  279. data/spec/models/s3_key_properties_spec.rb +40 -0
  280. data/spec/models/s3_key_spec.rb +58 -0
  281. data/spec/models/s3_keys_spec.rb +52 -0
  282. data/spec/models/s3_object_storage_sso_spec.rb +34 -0
  283. data/spec/models/server_entities_spec.rb +46 -0
  284. data/spec/models/server_properties_spec.rb +84 -0
  285. data/spec/models/server_spec.rb +64 -0
  286. data/spec/models/servers_spec.rb +70 -0
  287. data/spec/models/snapshot_properties_spec.rb +128 -0
  288. data/spec/models/snapshot_spec.rb +58 -0
  289. data/spec/models/snapshots_spec.rb +52 -0
  290. data/spec/models/type_spec.rb +28 -0
  291. data/spec/models/user_metadata_spec.rb +46 -0
  292. data/spec/models/user_properties_spec.rb +82 -0
  293. data/spec/models/user_spec.rb +64 -0
  294. data/spec/models/users_entities_spec.rb +40 -0
  295. data/spec/models/users_spec.rb +52 -0
  296. data/spec/models/volume_properties_spec.rb +152 -0
  297. data/spec/models/volume_spec.rb +58 -0
  298. data/spec/models/volumes_spec.rb +70 -0
  299. data/spec/spec_helper.rb +111 -0
  300. metadata +532 -0
@@ -0,0 +1,521 @@
1
+ =begin
2
+ #CLOUD API
3
+
4
+ #An enterprise-grade Infrastructure is provided as a Service (IaaS) solution that can be managed through a browser-based \"Data Center Designer\" (DCD) tool or via an easy to use API. The API allows you to perform a variety of management tasks such as spinning up additional servers, adding volumes, adjusting networking, and so forth. It is designed to allow users to leverage the same power and flexibility found within the DCD visual tool. Both tools are consistent with their concepts and lend well to making the experience smooth and intuitive.
5
+
6
+ The version of the OpenAPI document: 5.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.0.1-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'net/http'
17
+ require 'set'
18
+ require 'tempfile'
19
+ require 'time'
20
+ require 'typhoeus'
21
+
22
+ module Ionoscloud
23
+ class ApiClient
24
+ # The Configuration object holding settings to be used in the API client.
25
+ attr_accessor :config
26
+
27
+ # Defines the headers to be used in HTTP requests of all API calls by default.
28
+ #
29
+ # @return [Hash]
30
+ attr_accessor :default_headers
31
+
32
+ # Initializes the ApiClient
33
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
34
+ def initialize(config = Configuration.default)
35
+ @config = config
36
+ @user_agent = "ionos-cloud-sdk-ruby/v5"
37
+ @default_headers = {
38
+ 'Content-Type' => 'application/json',
39
+ 'User-Agent' => @user_agent
40
+ }
41
+ end
42
+
43
+ def self.default
44
+ @@default ||= ApiClient.new
45
+ end
46
+
47
+ # Call an API with given options.
48
+ #
49
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
50
+ # the data deserialized from response body (could be nil), response status code and response headers.
51
+ def call_api(http_method, path, opts = {})
52
+ retry_count = 0
53
+ request = build_request(http_method, path, opts)
54
+
55
+ while true
56
+ retry_count += 1
57
+ response = request.run
58
+
59
+ if @config.debugging
60
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
61
+ end
62
+
63
+ case Net::HTTPResponse::CODE_TO_OBJ[response.code.to_s]
64
+ when Set[Net::HTTPBadGateway, Net::HTTPServiceUnavailable, Net::HTTPGatewayTimeout]
65
+ backoff_time = @config.wait_time
66
+ when Set[Net::HTTPTooManyRequests]
67
+ backoff_time = @config.wait_time
68
+ begin
69
+ backoff_time = Integer(response.headers['Retry-After'])
70
+ rescue ArgumentError
71
+ end
72
+ else
73
+ break
74
+ end
75
+
76
+ if retry_count >= @config.max_retries
77
+ if @config.debugging
78
+ @config.logger.debug "number of maximum retries exceeded #{@config.max_retries}"
79
+ end
80
+ break
81
+ end
82
+
83
+ if backoff_time > @config.max_wait_time
84
+ backoff_time = @config.max_wait_time
85
+ end
86
+
87
+ if @config.debugging
88
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
89
+ end
90
+ sleep(backoff_time)
91
+ end
92
+
93
+ unless response.success?
94
+ if response.timed_out?
95
+ fail ApiError.new('Connection timed out')
96
+ elsif response.code == 0
97
+ # Errors from libcurl will be made visible here
98
+ fail ApiError.new(:code => 0,
99
+ :message => response.return_message)
100
+ else
101
+ fail ApiError.new(:code => response.code,
102
+ :response_headers => response.headers,
103
+ :response_body => response.body),
104
+ response.status_message
105
+ end
106
+ end
107
+
108
+ if opts[:return_type]
109
+ data = deserialize(response, opts[:return_type])
110
+ else
111
+ data = nil
112
+ end
113
+ return data, response.code, response.headers
114
+ end
115
+
116
+ # Builds the HTTP request
117
+ #
118
+ # @param [String] http_method HTTP method/verb (e.g. POST)
119
+ # @param [String] path URL path (e.g. /account/new)
120
+ # @option opts [Hash] :header_params Header parameters
121
+ # @option opts [Hash] :query_params Query parameters
122
+ # @option opts [Hash] :form_params Query parameters
123
+ # @option opts [Object] :body HTTP body (JSON/XML)
124
+ # @return [Typhoeus::Request] A Typhoeus Request
125
+ def build_request(http_method, path, opts = {})
126
+ url = build_request_url(path, opts)
127
+ http_method = http_method.to_sym.downcase
128
+
129
+ header_params = @default_headers.merge(opts[:header_params] || {})
130
+ query_params = opts[:query_params] || {}
131
+ form_params = opts[:form_params] || {}
132
+
133
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
134
+
135
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
136
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
137
+
138
+ req_opts = {
139
+ :method => http_method,
140
+ :headers => header_params,
141
+ :params => query_params,
142
+ :params_encoding => @config.params_encoding,
143
+ :timeout => @config.timeout,
144
+ :ssl_verifypeer => @config.verify_ssl,
145
+ :ssl_verifyhost => _verify_ssl_host,
146
+ :sslcert => @config.cert_file,
147
+ :sslkey => @config.key_file,
148
+ :verbose => @config.debugging
149
+ }
150
+
151
+ # set custom cert, if provided
152
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
153
+
154
+ if [:post, :patch, :put, :delete].include?(http_method)
155
+ req_body = build_request_body(header_params, form_params, opts[:body])
156
+ req_opts.update :body => req_body
157
+ if @config.debugging
158
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
159
+ end
160
+ end
161
+
162
+ request = Typhoeus::Request.new(url, req_opts)
163
+ download_file(request) if opts[:return_type] == 'File'
164
+ request
165
+ end
166
+
167
+ # Builds the HTTP request body
168
+ #
169
+ # @param [Hash] header_params Header parameters
170
+ # @param [Hash] form_params Query parameters
171
+ # @param [Object] body HTTP body (JSON/XML)
172
+ # @return [String] HTTP body data in the form of string
173
+ def build_request_body(header_params, form_params, body)
174
+ # http form
175
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
176
+ header_params['Content-Type'] == 'multipart/form-data'
177
+ data = {}
178
+ form_params.each do |key, value|
179
+ case value
180
+ when ::File, ::Array, nil
181
+ # let typhoeus handle File, Array and nil parameters
182
+ data[key] = value
183
+ else
184
+ data[key] = value.to_s
185
+ end
186
+ end
187
+ elsif body
188
+ data = body.is_a?(String) ? body : body.to_json
189
+ else
190
+ data = nil
191
+ end
192
+ data
193
+ end
194
+
195
+ # Save response body into a file in (the defined) temporary folder, using the filename
196
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
197
+ # The response body is written to the file in chunks in order to handle files which
198
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
199
+ # process can use.
200
+ #
201
+ # @see Configuration#temp_folder_path
202
+ def download_file(request)
203
+ tempfile = nil
204
+ encoding = nil
205
+ request.on_headers do |response|
206
+ content_disposition = response.headers['Content-Disposition']
207
+ if content_disposition && content_disposition =~ /filename=/i
208
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
209
+ prefix = sanitize_filename(filename)
210
+ else
211
+ prefix = 'download-'
212
+ end
213
+ prefix = prefix + '-' unless prefix.end_with?('-')
214
+ encoding = response.body.encoding
215
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
216
+ @tempfile = tempfile
217
+ end
218
+ request.on_body do |chunk|
219
+ chunk.force_encoding(encoding)
220
+ tempfile.write(chunk)
221
+ end
222
+ request.on_complete do |response|
223
+ if tempfile
224
+ tempfile.close
225
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
226
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
227
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
228
+ "explicitly with `tempfile.delete`"
229
+ end
230
+ end
231
+ end
232
+
233
+ # Check if the given MIME is a JSON MIME.
234
+ # JSON MIME examples:
235
+ # application/json
236
+ # application/json; charset=UTF8
237
+ # APPLICATION/JSON
238
+ # */*
239
+ # @param [String] mime MIME
240
+ # @return [Boolean] True if the MIME is application/json
241
+ def json_mime?(mime)
242
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
243
+ end
244
+
245
+ # Deserialize the response to the given return type.
246
+ #
247
+ # @param [Response] response HTTP response
248
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
249
+ def deserialize(response, return_type)
250
+ body = response.body
251
+
252
+ # handle file downloading - return the File instance processed in request callbacks
253
+ # note that response body is empty when the file is written in chunks in request on_body callback
254
+ return @tempfile if return_type == 'File'
255
+
256
+ return nil if body.nil? || body.empty?
257
+
258
+ # return response body directly for String return type
259
+ return body if return_type == 'String'
260
+
261
+ # ensuring a default content type
262
+ content_type = response.headers['Content-Type'] || 'application/json'
263
+
264
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
265
+
266
+ begin
267
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
268
+ rescue JSON::ParserError => e
269
+ if %w(String Date Time).include?(return_type)
270
+ data = body
271
+ else
272
+ raise e
273
+ end
274
+ end
275
+
276
+ convert_to_type data, return_type
277
+ end
278
+
279
+ # Convert data to the given return type.
280
+ # @param [Object] data Data to be converted
281
+ # @param [String] return_type Return type
282
+ # @return [Mixed] Data in a particular type
283
+ def convert_to_type(data, return_type)
284
+ return nil if data.nil?
285
+ case return_type
286
+ when 'String'
287
+ data.to_s
288
+ when 'Integer'
289
+ data.to_i
290
+ when 'Float'
291
+ data.to_f
292
+ when 'Boolean'
293
+ data == true
294
+ when 'Time'
295
+ # parse date time (expecting ISO 8601 format)
296
+ Time.parse data
297
+ when 'Date'
298
+ # parse date time (expecting ISO 8601 format)
299
+ Date.parse data
300
+ when 'Object'
301
+ # generic object (usually a Hash), return directly
302
+ data
303
+ when /\AArray<(.+)>\z/
304
+ # e.g. Array<Pet>
305
+ sub_type = $1
306
+ data.map { |item| convert_to_type(item, sub_type) }
307
+ when /\AHash\<String, (.+)\>\z/
308
+ # e.g. Hash<String, Integer>
309
+ sub_type = $1
310
+ {}.tap do |hash|
311
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
312
+ end
313
+ else
314
+ # models (e.g. Pet) or oneOf
315
+ klass = Ionoscloud.const_get(return_type)
316
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
317
+ end
318
+ end
319
+
320
+ # Sanitize filename by removing path.
321
+ # e.g. ../../sun.gif becomes sun.gif
322
+ #
323
+ # @param [String] filename the filename to be sanitized
324
+ # @return [String] the sanitized filename
325
+ def sanitize_filename(filename)
326
+ filename.gsub(/.*[\/\\]/, '')
327
+ end
328
+
329
+ def build_request_url(path, opts = {})
330
+ # Add leading and trailing slashes to path
331
+ path = "/#{path}".gsub(/\/+/, '/')
332
+ @config.base_url(opts[:operation]) + path
333
+ end
334
+
335
+ # Update hearder and query params based on authentication settings.
336
+ #
337
+ # @param [Hash] header_params Header parameters
338
+ # @param [Hash] query_params Query parameters
339
+ # @param [String] auth_names Authentication scheme name
340
+ def update_params_for_auth!(header_params, query_params, auth_names)
341
+ Array(auth_names).each do |auth_name|
342
+ auth_setting = @config.auth_settings[auth_name]
343
+ next unless auth_setting
344
+ case auth_setting[:in]
345
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
346
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
347
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
348
+ end
349
+ end
350
+ end
351
+
352
+ # Sets user agent in HTTP header
353
+ #
354
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
355
+ def user_agent=(user_agent)
356
+ @user_agent = user_agent
357
+ @default_headers['User-Agent'] = @user_agent
358
+ end
359
+
360
+ # Return Accept header based on an array of accepts provided.
361
+ # @param [Array] accepts array for Accept
362
+ # @return [String] the Accept header (e.g. application/json)
363
+ def select_header_accept(accepts)
364
+ return nil if accepts.nil? || accepts.empty?
365
+ # use JSON when present, otherwise use all of the provided
366
+ json_accept = accepts.find { |s| json_mime?(s) }
367
+ json_accept || accepts.join(',')
368
+ end
369
+
370
+ # Return Content-Type header based on an array of content types provided.
371
+ # @param [Array] content_types array for Content-Type
372
+ # @return [String] the Content-Type header (e.g. application/json)
373
+ def select_header_content_type(content_types)
374
+ # use application/json by default
375
+ return 'application/json' if content_types.nil? || content_types.empty?
376
+ # use JSON when present, otherwise use the first one
377
+ json_content_type = content_types.find { |s| json_mime?(s) }
378
+ json_content_type || content_types.first
379
+ end
380
+
381
+ # Convert object (array, hash, object, etc) to JSON string.
382
+ # @param [Object] model object to be converted into JSON string
383
+ # @return [String] JSON string representation of the object
384
+ def object_to_http_body(model)
385
+ return model if model.nil? || model.is_a?(String)
386
+ local_body = nil
387
+ if model.is_a?(Array)
388
+ local_body = model.map { |m| object_to_hash(m) }
389
+ else
390
+ local_body = object_to_hash(model)
391
+ end
392
+ local_body.to_json
393
+ end
394
+
395
+ # Convert object(non-array) to hash.
396
+ # @param [Object] obj object to be converted into JSON string
397
+ # @return [String] JSON string representation of the object
398
+ def object_to_hash(obj)
399
+ if obj.respond_to?(:to_hash)
400
+ obj.to_hash
401
+ else
402
+ obj
403
+ end
404
+ end
405
+
406
+ # Build parameter value according to the given collection format.
407
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
408
+ def build_collection_param(param, collection_format)
409
+ case collection_format
410
+ when :csv
411
+ param.join(',')
412
+ when :ssv
413
+ param.join(' ')
414
+ when :tsv
415
+ param.join("\t")
416
+ when :pipes
417
+ param.join('|')
418
+ when :multi
419
+ # return the array directly as typhoeus will handle it as expected
420
+ param
421
+ else
422
+ fail "unknown collection format: #{collection_format.inspect}"
423
+ end
424
+ end
425
+
426
+
427
+ # Poll resource request status until resource is provisioned.
428
+ # @param [String] request_id Request id of the action.
429
+ # @param [Integer] timeout Maximum waiting time in seconds. nil means infinite waiting time.
430
+ # @param [Integer] initial_wait Initial polling interval in seconds.
431
+ # @param [Integer] scaleup Double polling interval every scaleup steps, which will be doubled.
432
+ def wait_for_completion(request_id, timeout = 3600, initial_wait = 5, scaleup = 10)
433
+ if request_id.nil?
434
+ return nil
435
+ end
436
+
437
+ wait_period = initial_wait
438
+ next_increase = Time.now.to_i + wait_period * scaleup
439
+ unless timeout.nil?
440
+ timeout = Time.now.to_i + timeout
441
+ end
442
+
443
+ while true
444
+ request = Ionoscloud::RequestApi.new(self).requests_status_get(
445
+ request_id,
446
+ { :debug_auth_names => ['Basic Authentication'] },
447
+ )
448
+
449
+ if request.metadata.status == 'DONE'
450
+ break
451
+ else
452
+ if request.metadata.status == 'FAILED'
453
+ raise Ionoscloud::ApiError.new(
454
+ 'Request {0} failed to complete: {1}'.format(request_id, request.metadata.message),
455
+ )
456
+ end
457
+ end
458
+
459
+ current_time = Time.now.to_i
460
+ if timeout && current_time > timeout
461
+ raise Ionoscloud::ApiError.new(
462
+ 'Timed out waiting for request {0}.'.format(request_id),
463
+ )
464
+ end
465
+
466
+ if current_time > next_increase
467
+ wait_period *= 2
468
+ next_increase = Time.now.to_i + wait_period * scaleup
469
+ scaleup *= 2
470
+ end
471
+
472
+ if @config.debugging
473
+ @config.logger.info "Request #{request_id} is in state #{request.metadata.status}."\
474
+ "Sleeping for #{wait_period} seconds..."
475
+ end
476
+ sleep(wait_period)
477
+ end
478
+ end
479
+
480
+ # Execute block until it returns true
481
+ # @param [Block] _block Block to the executed.
482
+ # @param [Integer] timeout Maximum waiting time in seconds. nil means infinite waiting time.
483
+ # @param [Integer] initial_wait Initial polling interval in seconds.
484
+ # @param [Integer] scaleup Double polling interval every scaleup steps, which will be doubled.
485
+ def wait_for(timeout = 3600, initial_wait = 5, scaleup = 10, &_block)
486
+ if _block.nil?
487
+ return nil
488
+ end
489
+
490
+ wait_period = initial_wait
491
+ next_increase = Time.now.to_i + wait_period * scaleup
492
+ unless timeout.nil?
493
+ timeout = Time.now.to_i + timeout
494
+ end
495
+
496
+ while true
497
+ if yield
498
+ break
499
+ end
500
+
501
+ current_time = Time.now.to_i
502
+ if timeout && current_time > timeout
503
+ raise Ionoscloud::ApiError.new(
504
+ 'Timed out waiting for request {0}.'.format(request_id),
505
+ )
506
+ end
507
+
508
+ if current_time > next_increase
509
+ wait_period *= 2
510
+ next_increase = Time.now.to_i + wait_period * scaleup
511
+ scaleup *= 2
512
+ end
513
+
514
+ if @config.debugging
515
+ @config.logger.info "Sleeping for #{wait_period} seconds..."
516
+ end
517
+ sleep(wait_period)
518
+ end
519
+ end
520
+ end
521
+ end