oci 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +82 -0
  3. data/README.md +262 -0
  4. data/lib/oci.rb +25 -0
  5. data/lib/oci/api_client.rb +389 -0
  6. data/lib/oci/config.rb +118 -0
  7. data/lib/oci/config_file_loader.rb +96 -0
  8. data/lib/oci/core/blockstorage_client.rb +462 -0
  9. data/lib/oci/core/compute_client.rb +1415 -0
  10. data/lib/oci/core/core.rb +114 -0
  11. data/lib/oci/core/models/attach_i_scsi_volume_details.rb +137 -0
  12. data/lib/oci/core/models/attach_vnic_details.rb +144 -0
  13. data/lib/oci/core/models/attach_volume_details.rb +165 -0
  14. data/lib/oci/core/models/capture_console_history_details.rb +120 -0
  15. data/lib/oci/core/models/console_history.rb +213 -0
  16. data/lib/oci/core/models/cpe.rb +169 -0
  17. data/lib/oci/core/models/create_cpe_details.rb +145 -0
  18. data/lib/oci/core/models/create_cross_connect_details.rb +204 -0
  19. data/lib/oci/core/models/create_cross_connect_group_details.rb +133 -0
  20. data/lib/oci/core/models/create_dhcp_details.rb +153 -0
  21. data/lib/oci/core/models/create_drg_attachment_details.rb +142 -0
  22. data/lib/oci/core/models/create_drg_details.rb +131 -0
  23. data/lib/oci/core/models/create_image_details.rb +159 -0
  24. data/lib/oci/core/models/create_instance_console_connection_details.rb +131 -0
  25. data/lib/oci/core/models/create_internet_gateway_details.rb +153 -0
  26. data/lib/oci/core/models/create_ip_sec_connection_details.rb +168 -0
  27. data/lib/oci/core/models/create_private_ip_details.rb +173 -0
  28. data/lib/oci/core/models/create_route_table_details.rb +153 -0
  29. data/lib/oci/core/models/create_security_list_details.rb +164 -0
  30. data/lib/oci/core/models/create_subnet_details.rb +257 -0
  31. data/lib/oci/core/models/create_vcn_details.rb +171 -0
  32. data/lib/oci/core/models/create_virtual_circuit_details.rb +260 -0
  33. data/lib/oci/core/models/create_vnic_details.rb +214 -0
  34. data/lib/oci/core/models/create_volume_backup_details.rb +133 -0
  35. data/lib/oci/core/models/create_volume_details.rb +170 -0
  36. data/lib/oci/core/models/cross_connect.rb +235 -0
  37. data/lib/oci/core/models/cross_connect_group.rb +187 -0
  38. data/lib/oci/core/models/cross_connect_location.rb +134 -0
  39. data/lib/oci/core/models/cross_connect_mapping.rb +190 -0
  40. data/lib/oci/core/models/cross_connect_port_speed_shape.rb +137 -0
  41. data/lib/oci/core/models/cross_connect_status.rb +200 -0
  42. data/lib/oci/core/models/dhcp_dns_option.rb +171 -0
  43. data/lib/oci/core/models/dhcp_option.rb +135 -0
  44. data/lib/oci/core/models/dhcp_options.rb +208 -0
  45. data/lib/oci/core/models/dhcp_search_domain_option.rb +141 -0
  46. data/lib/oci/core/models/drg.rb +186 -0
  47. data/lib/oci/core/models/drg_attachment.rb +208 -0
  48. data/lib/oci/core/models/egress_security_rule.rb +198 -0
  49. data/lib/oci/core/models/export_image_details.rb +134 -0
  50. data/lib/oci/core/models/export_image_via_object_storage_tuple_details.rb +150 -0
  51. data/lib/oci/core/models/export_image_via_object_storage_uri_details.rb +130 -0
  52. data/lib/oci/core/models/fast_connect_provider_service.rb +145 -0
  53. data/lib/oci/core/models/i_scsi_volume_attachment.rb +212 -0
  54. data/lib/oci/core/models/icmp_options.rb +131 -0
  55. data/lib/oci/core/models/image.rb +245 -0
  56. data/lib/oci/core/models/image_source_details.rb +134 -0
  57. data/lib/oci/core/models/image_source_via_object_storage_tuple_details.rb +150 -0
  58. data/lib/oci/core/models/image_source_via_object_storage_uri_details.rb +128 -0
  59. data/lib/oci/core/models/ingress_security_rule.rb +198 -0
  60. data/lib/oci/core/models/instance.rb +307 -0
  61. data/lib/oci/core/models/instance_console_connection.rb +193 -0
  62. data/lib/oci/core/models/instance_credentials.rb +131 -0
  63. data/lib/oci/core/models/internet_gateway.rb +210 -0
  64. data/lib/oci/core/models/ip_sec_connection.rb +223 -0
  65. data/lib/oci/core/models/ip_sec_connection_device_config.rb +153 -0
  66. data/lib/oci/core/models/ip_sec_connection_device_status.rb +156 -0
  67. data/lib/oci/core/models/launch_instance_details.rb +336 -0
  68. data/lib/oci/core/models/letter_of_authority.rb +194 -0
  69. data/lib/oci/core/models/port_range.rb +133 -0
  70. data/lib/oci/core/models/private_ip.rb +248 -0
  71. data/lib/oci/core/models/route_rule.rb +135 -0
  72. data/lib/oci/core/models/route_table.rb +208 -0
  73. data/lib/oci/core/models/security_list.rb +219 -0
  74. data/lib/oci/core/models/shape.rb +122 -0
  75. data/lib/oci/core/models/subnet.rb +351 -0
  76. data/lib/oci/core/models/tcp_options.rb +135 -0
  77. data/lib/oci/core/models/tunnel_config.rb +151 -0
  78. data/lib/oci/core/models/tunnel_status.rb +178 -0
  79. data/lib/oci/core/models/udp_options.rb +135 -0
  80. data/lib/oci/core/models/update_cpe_details.rb +122 -0
  81. data/lib/oci/core/models/update_cross_connect_details.rb +138 -0
  82. data/lib/oci/core/models/update_cross_connect_group_details.rb +122 -0
  83. data/lib/oci/core/models/update_dhcp_details.rb +132 -0
  84. data/lib/oci/core/models/update_drg_attachment_details.rb +122 -0
  85. data/lib/oci/core/models/update_drg_details.rb +122 -0
  86. data/lib/oci/core/models/update_image_details.rb +124 -0
  87. data/lib/oci/core/models/update_instance_details.rb +124 -0
  88. data/lib/oci/core/models/update_internet_gateway_details.rb +133 -0
  89. data/lib/oci/core/models/update_ip_sec_connection_details.rb +122 -0
  90. data/lib/oci/core/models/update_private_ip_details.rb +157 -0
  91. data/lib/oci/core/models/update_route_table_details.rb +133 -0
  92. data/lib/oci/core/models/update_security_list_details.rb +144 -0
  93. data/lib/oci/core/models/update_subnet_details.rb +122 -0
  94. data/lib/oci/core/models/update_vcn_details.rb +122 -0
  95. data/lib/oci/core/models/update_virtual_circuit_details.rb +240 -0
  96. data/lib/oci/core/models/update_vnic_details.rb +144 -0
  97. data/lib/oci/core/models/update_volume_backup_details.rb +122 -0
  98. data/lib/oci/core/models/update_volume_details.rb +122 -0
  99. data/lib/oci/core/models/vcn.rb +276 -0
  100. data/lib/oci/core/models/virtual_circuit.rb +395 -0
  101. data/lib/oci/core/models/virtual_circuit_bandwidth_shape.rb +137 -0
  102. data/lib/oci/core/models/vnic.rb +287 -0
  103. data/lib/oci/core/models/vnic_attachment.rb +250 -0
  104. data/lib/oci/core/models/volume.rb +210 -0
  105. data/lib/oci/core/models/volume_attachment.rb +246 -0
  106. data/lib/oci/core/models/volume_backup.rb +235 -0
  107. data/lib/oci/core/util.rb +1 -0
  108. data/lib/oci/core/virtual_network_client.rb +3421 -0
  109. data/lib/oci/errors.rb +78 -0
  110. data/lib/oci/global_context.rb +20 -0
  111. data/lib/oci/identity/identity.rb +55 -0
  112. data/lib/oci/identity/identity_client.rb +2148 -0
  113. data/lib/oci/identity/models/add_user_to_group_details.rb +131 -0
  114. data/lib/oci/identity/models/api_key.rb +211 -0
  115. data/lib/oci/identity/models/availability_domain.rb +131 -0
  116. data/lib/oci/identity/models/compartment.rb +211 -0
  117. data/lib/oci/identity/models/create_api_key_details.rb +120 -0
  118. data/lib/oci/identity/models/create_compartment_details.rb +145 -0
  119. data/lib/oci/identity/models/create_customer_secret_key_details.rb +121 -0
  120. data/lib/oci/identity/models/create_group_details.rb +144 -0
  121. data/lib/oci/identity/models/create_identity_provider_details.rb +215 -0
  122. data/lib/oci/identity/models/create_idp_group_mapping_details.rb +133 -0
  123. data/lib/oci/identity/models/create_policy_details.rb +173 -0
  124. data/lib/oci/identity/models/create_region_subscription_details.rb +128 -0
  125. data/lib/oci/identity/models/create_saml2_identity_provider_details.rb +154 -0
  126. data/lib/oci/identity/models/create_swift_password_details.rb +121 -0
  127. data/lib/oci/identity/models/create_user_details.rb +144 -0
  128. data/lib/oci/identity/models/customer_secret_key.rb +225 -0
  129. data/lib/oci/identity/models/customer_secret_key_summary.rb +213 -0
  130. data/lib/oci/identity/models/group.rb +211 -0
  131. data/lib/oci/identity/models/identity_provider.rb +261 -0
  132. data/lib/oci/identity/models/idp_group_mapping.rb +220 -0
  133. data/lib/oci/identity/models/policy.rb +237 -0
  134. data/lib/oci/identity/models/region.rb +143 -0
  135. data/lib/oci/identity/models/region_subscription.rb +180 -0
  136. data/lib/oci/identity/models/saml2_identity_provider.rb +180 -0
  137. data/lib/oci/identity/models/swift_password.rb +226 -0
  138. data/lib/oci/identity/models/tenancy.rb +159 -0
  139. data/lib/oci/identity/models/ui_password.rb +187 -0
  140. data/lib/oci/identity/models/update_compartment_details.rb +132 -0
  141. data/lib/oci/identity/models/update_customer_secret_key_details.rb +120 -0
  142. data/lib/oci/identity/models/update_group_details.rb +120 -0
  143. data/lib/oci/identity/models/update_identity_provider_details.rb +160 -0
  144. data/lib/oci/identity/models/update_idp_group_mapping_details.rb +131 -0
  145. data/lib/oci/identity/models/update_policy_details.rb +148 -0
  146. data/lib/oci/identity/models/update_saml2_identity_provider_details.rb +145 -0
  147. data/lib/oci/identity/models/update_state_details.rb +121 -0
  148. data/lib/oci/identity/models/update_swift_password_details.rb +120 -0
  149. data/lib/oci/identity/models/update_user_details.rb +120 -0
  150. data/lib/oci/identity/models/user.rb +217 -0
  151. data/lib/oci/identity/models/user_group_membership.rb +209 -0
  152. data/lib/oci/identity/util.rb +1 -0
  153. data/lib/oci/internal/internal.rb +10 -0
  154. data/lib/oci/internal/util.rb +69 -0
  155. data/lib/oci/load_balancer/load_balancer.rb +51 -0
  156. data/lib/oci/load_balancer/load_balancer_client.rb +1449 -0
  157. data/lib/oci/load_balancer/models/backend.rb +220 -0
  158. data/lib/oci/load_balancer/models/backend_details.rb +206 -0
  159. data/lib/oci/load_balancer/models/backend_health.rb +158 -0
  160. data/lib/oci/load_balancer/models/backend_set.rb +182 -0
  161. data/lib/oci/load_balancer/models/backend_set_details.rb +165 -0
  162. data/lib/oci/load_balancer/models/backend_set_health.rb +207 -0
  163. data/lib/oci/load_balancer/models/certificate.rb +169 -0
  164. data/lib/oci/load_balancer/models/certificate_details.rb +205 -0
  165. data/lib/oci/load_balancer/models/create_backend_details.rb +206 -0
  166. data/lib/oci/load_balancer/models/create_backend_set_details.rb +181 -0
  167. data/lib/oci/load_balancer/models/create_certificate_details.rb +205 -0
  168. data/lib/oci/load_balancer/models/create_listener_details.rb +175 -0
  169. data/lib/oci/load_balancer/models/create_load_balancer_details.rb +220 -0
  170. data/lib/oci/load_balancer/models/health_check_result.rb +183 -0
  171. data/lib/oci/load_balancer/models/health_checker.rb +224 -0
  172. data/lib/oci/load_balancer/models/health_checker_details.rb +223 -0
  173. data/lib/oci/load_balancer/models/ip_address.rb +139 -0
  174. data/lib/oci/load_balancer/models/listener.rb +174 -0
  175. data/lib/oci/load_balancer/models/listener_details.rb +160 -0
  176. data/lib/oci/load_balancer/models/load_balancer.rb +280 -0
  177. data/lib/oci/load_balancer/models/load_balancer_health.rb +215 -0
  178. data/lib/oci/load_balancer/models/load_balancer_health_summary.rb +168 -0
  179. data/lib/oci/load_balancer/models/load_balancer_policy.rb +120 -0
  180. data/lib/oci/load_balancer/models/load_balancer_protocol.rb +120 -0
  181. data/lib/oci/load_balancer/models/load_balancer_shape.rb +120 -0
  182. data/lib/oci/load_balancer/models/session_persistence_configuration_details.rb +141 -0
  183. data/lib/oci/load_balancer/models/ssl_configuration.rb +155 -0
  184. data/lib/oci/load_balancer/models/ssl_configuration_details.rb +155 -0
  185. data/lib/oci/load_balancer/models/update_backend_details.rb +178 -0
  186. data/lib/oci/load_balancer/models/update_backend_set_details.rb +165 -0
  187. data/lib/oci/load_balancer/models/update_health_checker_details.rb +222 -0
  188. data/lib/oci/load_balancer/models/update_listener_details.rb +160 -0
  189. data/lib/oci/load_balancer/models/update_load_balancer_details.rb +124 -0
  190. data/lib/oci/load_balancer/models/work_request.rb +229 -0
  191. data/lib/oci/load_balancer/models/work_request_error.rb +145 -0
  192. data/lib/oci/load_balancer/util.rb +58 -0
  193. data/lib/oci/object_storage/models/bucket.rb +216 -0
  194. data/lib/oci/object_storage/models/bucket_summary.rb +175 -0
  195. data/lib/oci/object_storage/models/commit_multipart_upload_details.rb +133 -0
  196. data/lib/oci/object_storage/models/commit_multipart_upload_part_details.rb +131 -0
  197. data/lib/oci/object_storage/models/create_bucket_details.rb +173 -0
  198. data/lib/oci/object_storage/models/create_multipart_upload_details.rb +166 -0
  199. data/lib/oci/object_storage/models/create_preauthenticated_request_details.rb +171 -0
  200. data/lib/oci/object_storage/models/list_objects.rb +146 -0
  201. data/lib/oci/object_storage/models/multipart_upload.rb +164 -0
  202. data/lib/oci/object_storage/models/multipart_upload_part_summary.rb +153 -0
  203. data/lib/oci/object_storage/models/object_summary.rb +153 -0
  204. data/lib/oci/object_storage/models/preauthenticated_request.rb +207 -0
  205. data/lib/oci/object_storage/models/preauthenticated_request_summary.rb +196 -0
  206. data/lib/oci/object_storage/models/update_bucket_details.rb +171 -0
  207. data/lib/oci/object_storage/object_storage.rb +30 -0
  208. data/lib/oci/object_storage/object_storage_client.rb +1185 -0
  209. data/lib/oci/object_storage/util.rb +1 -0
  210. data/lib/oci/regions.rb +43 -0
  211. data/lib/oci/response.rb +80 -0
  212. data/lib/oci/response_headers.rb +144 -0
  213. data/lib/oci/signer.rb +157 -0
  214. data/lib/oci/version.rb +5 -0
  215. data/lib/oci/waiter.rb +101 -0
  216. data/lib/oraclebmc.rb +3 -0
  217. metadata +375 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 488c00cdc5eeffc80b243c41eda2e48a3a636d13
4
+ data.tar.gz: dc295148c7edd143d92421cfbe7a4b11c95711e6
5
+ SHA512:
6
+ metadata.gz: a012d576d2f27aebeef2e26ea37ec52038e51a550aa73b684a816e73c109b2b6686195ac4ebd7c996e6a891a9b4941a71b1ab5ae03a7fc16af758fd3bbf19869
7
+ data.tar.gz: 27faeab73bd7fa8359969ce79a54b830597ac310bbe590b294b556759d289ca51581e5d6cabeefc3445304e3657292e875dfa17862517af6df32d74fa4256253
@@ -0,0 +1,82 @@
1
+ Copyright (c) 2016, 2017, Oracle and/or its affiliates.  All rights reserved.
2
+
3
+ This software is dual-licensed to you under the Universal Permissive License (UPL) and Apache License 2.0.  See below for license terms.  You may choose either license, or both.
4
+  ____________________________
5
+ The Universal Permissive License (UPL), Version 1.0
6
+ Copyright (c) 2016, 2017, Oracle and/or its affiliates.  All rights reserved.
7
+
8
+ Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both
9
+
10
+ (a) the Software, and
11
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a "Larger Work" to which the Software is contributed by such licensors),
12
+
13
+ without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.
14
+
15
+ This license is subject to the following condition:
16
+
17
+ The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ The Apache Software License, Version 2.0
22
+ Copyright (c) 2016, 2017, Oracle and/or its affiliates.  All rights reserved.
23
+
24
+ Licensed under the Apache License, Version 2.0 (the "License"); You may not use this product except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. A copy of the license is also reproduced below. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
25
+
26
+ Apache License
27
+
28
+ Version 2.0, January 2004
29
+
30
+ http://www.apache.org/licenses/
31
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
32
+ 1. Definitions.
33
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
34
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
35
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
36
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
37
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
38
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
39
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
40
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
41
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
42
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
43
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
44
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
45
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
46
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
47
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
48
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
49
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
50
+
51
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
52
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
53
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
54
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
55
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
56
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
57
+ END OF TERMS AND CONDITIONS
58
+
59
+ APPENDIX: How to apply the Apache License to your work.
60
+
61
+ To apply the Apache License to your work, attach the following
62
+ boilerplate notice, with the fields enclosed by brackets "[]"
63
+ replaced with your own identifying information. (Don't include
64
+ the brackets!) The text should be enclosed in the appropriate
65
+ comment syntax for the file format. We also recommend that a
66
+ file or class name and description of purpose be included on the
67
+ same "printed page" as the copyright notice for easier
68
+ identification within third-party archives.
69
+
70
+ Copyright [yyyy] [name of copyright owner]
71
+
72
+ Licensed under the Apache License, Version 2.0 (the "License");
73
+ you may not use this file except in compliance with the License.
74
+ You may obtain a copy of the License at
75
+
76
+ http://www.apache.org/licenses/LICENSE-2.0
77
+
78
+ Unless required by applicable law or agreed to in writing, software
79
+ distributed under the License is distributed on an "AS IS" BASIS,
80
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81
+ See the License for the specific language governing permissions and
82
+ limitations under the License.
@@ -0,0 +1,262 @@
1
+ # Oracle Cloud Infrastructure Ruby SDK
2
+ **Version 2.0.0**
3
+
4
+ This topic describes how to install, configure, and use the Oracle Cloud Infrastructure Ruby SDK.
5
+
6
+ ## SDK Overview
7
+
8
+ The Ruby SDK supports the following services:
9
+
10
+ * Core Services (which includes Networking Service, Compute Service, and Block Volume Service)
11
+ * Identity and Access Management Service
12
+ * Load Balancing Service
13
+ * Object Storage Service
14
+
15
+ **Licensing:** This SDK and sample is dual licensed under the Universal Permissive License 1.0 and the Apache License.
16
+
17
+
18
+ ## SDK Attributes
19
+ The following table provides details about some of the attributes of the SDK.
20
+
21
+ <table>
22
+ <tbody>
23
+ <tr>
24
+ <td>Requests</td>
25
+ <td>API methods expose required parameters as arguments and optional arguments as a hash (opts = {}). Create and update operations take request objects that mirror the properties of those objects.</td>
26
+ </tr>
27
+ <tr>
28
+ <td>Responses</td>
29
+ <td>All API methods return a Response object, which contains an HTTP status (200, 204, etc), headers, and data, and also directly exposes some commonly used response headers such as <code>opc-next_page</code>, and <code>opc-request_id</code>.</td>
30
+ </tr>
31
+ <tr>
32
+ <td>Models</td>
33
+ <td>Get, update, and create operations return first class objects of the corresponding type (such as User, Instance, etc) in Response.data.</td>
34
+ </tr>
35
+ <tr>
36
+ <td>Errors</td>
37
+ <td>Unsuccessful requests will always raise an exception. {OCI::Errors::ServiceError ServiceError} is raised when the service returns an error, and {OCI::Errors::NetworkError NetworkError} is raised for network issues (such as failed host resolution).</td>
38
+ </tr>
39
+ <tr>
40
+ <td>Signing</td>
41
+ <td>Requests made through the API classes are automatically signed, but you can also use the {OCI::Signer Signer} directly to sign your own requests if needed.</td>
42
+ </tr>
43
+ <tr>
44
+ <td>Automatic Paging</td>
45
+ <td>Response objects for lists support {OCI::Response#each page enumeration}. See example code later in this file.</td>
46
+ </tr>
47
+ <tr>
48
+ <td>Waiters</td>
49
+ <td>Responses for get requests support waiting for a particular states using {OCI::Response#wait_until wait_until}. See example code later in this file.</td>
50
+ </tr>
51
+ <tr>
52
+ <td>HTTP Client</td>
53
+ <td>The Ruby SDK uses Net::HTTP for HTTP requests, if needed, options may be passed to each Net::HTTP by specifying them in {OCI::ApiClient#request_option_overrides ApiClient.request_option_overrides}.</br>
54
+ Please check http://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start for the supported options.</td>
55
+ </tr>
56
+ </tbody>
57
+ </table>
58
+
59
+
60
+ ## SDK Requirements
61
+
62
+ To use the Ruby SDK, you must have:
63
+
64
+ * An Oracle Cloud Infrastructure account.
65
+ * A user created in that account, in a group with a policy that grants the desired permissions. This can be a user for yourself, or another person/system that needs to call the API. For an example of how to set up a new user, group, compartment, and policy, see [Adding Users](https://docs.us-phoenix-1.oraclecloud.com/Content/GSG/Tasks/addingusers.htm) in the Getting Started Guide. For a list of typical policies you may want to use, see [Common Policies](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/commonpolicies.htm) in the User Guide.
66
+ * A keypair used for signing API requests, with the public key uploaded to Oracle. Only the user calling the API should be in possession of the private key. See the configuration information below.
67
+ * Ruby version 2.2 or later running on Mac or Linux. Windows is not supported at this time.
68
+
69
+ # Downloading and Installing the Gem File
70
+ ## Installing the SDK
71
+
72
+
73
+ Install from [RubyGems](https://rubygems.org/gems/oci):
74
+
75
+ `gem install oci`
76
+
77
+ You can also [download the SDK](https://docs.us-phoenix-1.oraclecloud.com/tools/ruby/latest/download/oci-ruby-sdk.zip) as a zip file containing the gem file, examples, and documentation.
78
+
79
+ Install the gem with the following command:
80
+
81
+
82
+ `gem install oci-*.gem`
83
+
84
+ ### Troubleshooting an Installation
85
+ If you see "Unable to resolve dependencies”, you can install the dependencies manually:
86
+
87
+ gem install inifile
88
+
89
+ ## SDK modules and namespacing
90
+ The top level module name for the Ruby SDK is `OCI`, however using `OracleBMC` as the top level namespace is also supported. For example, you can reference the configuration object as both `OCI::Config` and `OracleBMC::Config`.
91
+
92
+ Using `OCI` as the top level module name is preferred and it is also used in the SDK API Reference. Additionally, if you inspect the type of an SDK object it will always be reported as being under the `OCI::` module.
93
+
94
+ ## Configuring the SDK
95
+
96
+ To use any of the APIs, you must supply a {OCI::Config Config} object. You can create the object directly in code, or you can create one in a config file. The configuration includes:
97
+
98
+ * Required credentials and settings: See [SDK and Tool Configuration](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm) in the User Guide.
99
+ * Optional SDK-specific settings: See the {OCI::Config Config} object for the full list of config options.
100
+
101
+ ## Forward Compatibility
102
+
103
+ Some response fields are enum-typed. In the future, individual services may return values not covered by existing enums for that field. To address this possibility, every enum-type response field has an additional value named "UNKNOWN_ENUM_VALUE". If a service returns a value that is not recognized by your version of the SDK, then the response field will be set to this value. Please ensure that your code handles the "UNKNOWN_ENUM_VALUE" case if you have conditional logic based on an enum-typed field.
104
+
105
+ ## Writing Your First Ruby Program with the SDK
106
+
107
+ require 'oci'
108
+
109
+ # This will load the config file at the default location, and will
110
+ # use the tenancy from that config as the compartment in the
111
+ # call to list_users.
112
+ api = OCI::Identity::IdentityClient.new(region: OCI::Regions::REGION_US_PHOENIX_1)
113
+ response = api.list_users(OCI.config.tenancy)
114
+ response.data.each { |user| puts user.name }
115
+
116
+ ## Loading Alternate Configurations
117
+
118
+ You can also load a config file from a different location, and/or specify a different profile from the config file:
119
+
120
+ require 'oci'
121
+
122
+ my_config = OCI::ConfigFileLoader.load_config(config_file_location:'my_config', profile_name:'USER_TWO')
123
+ api = OCI::Identity::IdentityClient.new(config:my_config)
124
+ response = api.get_user(my_config.user)
125
+ puts 'User Name: ' + response.data.name
126
+
127
+ Or you can create a {OCI::Config Config} programmatically. Note that the global value {OCI#config OCI.config} will always attempt to load the DEFAULT profile from the default config file location unless it has been explicitly set to another value.
128
+
129
+ The default config file location is `~/.oci/config` (on Windows `C:\Users\{user}\.oci\config`).
130
+
131
+ ## Service Errors
132
+
133
+ Any operation resulting in a service error will cause an exception of type OCI::Errors::ServiceError to be thrown by the SDK. For information about common service errors returned by OCI, see [API Errors](https://docs.us-phoenix-1.oraclecloud.com/Content/API/References/apierrors.htm).
134
+
135
+ ## Examples
136
+ The example code in this section shows how various parts of the Ruby SDK work. More examples can be found in the SDK download.
137
+
138
+ ### Management Operations on a User
139
+ The following example runs create, read, update, and delete (CRUD) operations on users.
140
+
141
+ require 'oci'
142
+
143
+ compartment = OCI.config.tenancy
144
+
145
+ api = OCI::Identity::IdentityClient.new
146
+ users = api.list_users(compartment_id = compartment).data
147
+ puts "There are currently " + users.length.to_s + " users."
148
+
149
+ # Create User
150
+ request = OCI::Identity::Models::CreateUserDetails.new
151
+ request.compartment_id = compartment
152
+ request.name = "userA"
153
+ request.description = "example user"
154
+ response = api.create_user(request)
155
+
156
+ puts "Created user " + response.data.name
157
+ user_id = response.data.id
158
+
159
+ users = api.list_users(compartment_id = compartment).data
160
+ puts "There are now " + users.length.to_s + " users."
161
+
162
+ # Get User
163
+ response = api.get_user(user_id = user_id)
164
+
165
+ # Update User (using a request object)
166
+ newDescription = "updated user description"
167
+ request = OCI::Identity::Models::UpdateUserDetails.new
168
+ request.description = "Updated description"
169
+ response = api.update_user(user_id, request)
170
+
171
+ puts "Updated description to:" + response.data.description
172
+
173
+ # Update User (using a hash)
174
+ newDescription = "updated without a request object"
175
+ response = api.update_user(user_id, { description: "Updated again, but using a hash instead of an object." })
176
+
177
+ # Delete User
178
+ api.delete_user(user_id)
179
+
180
+ users = api.list_users(compartment_id = compartment).data
181
+ puts "Back to " + users.length.to_s + " users."
182
+
183
+ ### Paging Through Results
184
+ The following example shows how to page through results. It also gives an example of supplying optional parameters.
185
+
186
+ require 'oci'
187
+
188
+ api = OCI::Identity::IdentityClient.new
189
+ compartment = OCI.config.tenancy
190
+
191
+ ### Automatic paging:
192
+ api.list_users(compartment, limit:'3').each { |r| r.data.each { |user| puts user.name }}
193
+
194
+ ### Manual paging:
195
+ request_number = 0
196
+ next_page = nil
197
+
198
+ loop do
199
+ response = api.list_users(compartment, {limit: '3', page: next_page})
200
+
201
+ puts "Page " + request_number.to_s
202
+ response.data.each { |user| puts user.name }
203
+
204
+ break unless response.has_next_page?
205
+ next_page = response.next_page
206
+ request_number += 1
207
+ end
208
+
209
+ ### Launching an Instance and Waiting for a State
210
+ The following example shows how to launch an instance (which assumes that you already have a subnet created), and then wait until the instance is running.
211
+
212
+ require 'oci'
213
+
214
+ ssh_public_key = File.open(File.expand_path(public_key_file), "rb").read
215
+
216
+ request = OCI::Core::Models::LaunchInstanceDetails.new
217
+ request.availability_domain = availability_domain # TODO: Set an availability domain, such as 'kIdk:PHX-AD-2'
218
+ request.compartment_id = compartment_id # TODO: set your compartment ID here
219
+ request.display_name = 'my_instance'
220
+ request.image_id = image_id # TODO: set your image ID here. You can see the available options with list_images.
221
+ request.shape = shape # TODO: set your instance shape. You can see the available options with list_shapes.
222
+ request.subnet_id = subnet_id # TODO: set your subnet ID here
223
+ request.metadata = {'ssh_authorized_keys' => ssh_public_key}
224
+
225
+ api = OCI::Core::ComputeClient.new
226
+ response = api.launch_instance(request)
227
+ instance_id = response.data.id
228
+ response = api.get_instance(instance_id).wait_until(:lifecycle_state, OCI::Core::Models::Instance::LIFECYCLE_STATE_RUNNING)
229
+
230
+ ### Signing a Raw Request
231
+ The {OCI::Signer} can be used to sign arbitrary requests to the Oracle Cloud Infrastructure Services. The following example uses Net::HTTP to call the IAM service directly.
232
+
233
+ require 'oci'
234
+ require 'net/http'
235
+
236
+ config = OCI::ConfigFileLoader.load_config(config_file_location:my_config_file_location)
237
+ endpoint = OCI::Regions.get_service_endpoint(config.region, :IdentityClient)
238
+
239
+ uri = URI(endpoint + '/20160918/users/' + config.user)
240
+ request = Net::HTTP::Get.new(uri)
241
+
242
+ signer = OCI::Signer.new(config.user, config.fingerprint, config.tenancy, config.key_file, pass_phrase:my_private_key_pass_phrase)
243
+ signer.sign(:get, uri.to_s, request, nil)
244
+
245
+ result = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
246
+ http.request(request)
247
+ }
248
+
249
+ puts result.body
250
+
251
+ ## Notifications
252
+ To be notified when a new version of the Ruby SDK is released, subscribe to the [Atom feed](https://rubygems.org/gems/oci/versions.atom).
253
+
254
+ ## Questions or Feedback?
255
+ Ways to get in touch:
256
+
257
+ * [Stack Overflow](https://stackoverflow.com/): Please use the [oracle-cloud-infrastructure](https://stackoverflow.com/questions/tagged/oracle-cloud-infrastructure) and [oci-ruby-sdk](https://stackoverflow.com/questions/tagged/oci-ruby-sdk) tags in your post
258
+ * [Developer Tools section](https://community.oracle.com/community/cloud_computing/bare-metal/content?filterID=contentstatus%5Bpublished%5D~category%5Bdeveloper-tools%5D&filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bthread%5D) of the Oracle Cloud forums
259
+ * [My Oracle Support](https://support.oracle.com)
260
+
261
+
262
+
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'oci/api_client'
4
+ require 'oci/config'
5
+ require 'oci/config_file_loader'
6
+ require 'oci/errors'
7
+ require 'oci/global_context'
8
+ require 'oci/internal/internal'
9
+ require 'oci/regions'
10
+ require 'oci/response_headers'
11
+ require 'oci/response'
12
+ require 'oci/signer'
13
+ require 'oci/version'
14
+ require 'oci/waiter'
15
+
16
+ require 'oci/core/core'
17
+ require 'oci/identity/identity'
18
+ require 'oci/load_balancer/load_balancer'
19
+ require 'oci/object_storage/object_storage'
20
+
21
+ # Top level module for the Oracle Cloud Infrastructure SDK
22
+ module OCI
23
+ end
24
+
25
+ OracleBMC = OCI
@@ -0,0 +1,389 @@
1
+ # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'date'
4
+ require 'json'
5
+ require 'logger'
6
+ require 'net/http'
7
+ require 'securerandom'
8
+ require 'tempfile'
9
+ require 'uri'
10
+
11
+ require_relative 'signer'
12
+ require_relative 'version'
13
+ require_relative 'response'
14
+
15
+ module OCI
16
+ class ApiClient
17
+ # The Config object holding settings to be used in the API client.
18
+ attr_accessor :config
19
+
20
+ # Defines the headers to be used in HTTP requests of all API calls by default.
21
+ #
22
+ # @return [Hash]
23
+ attr_accessor :default_headers
24
+
25
+ # Request options to be sent with Net::HTTP.
26
+ # These options will override any defaults normally set by ApiClient.
27
+ # See {http://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#method-c-start} for
28
+ # some of the available options.
29
+ #
30
+ # @return [Hash]
31
+ attr_accessor :request_option_overrides
32
+
33
+ def initialize(config, signer)
34
+ raise "Missing the required parameter 'config' when initializing ApiClient." if config.nil?
35
+ raise "Missing the required parameter 'signer' when initializing ApiClient." if signer.nil?
36
+
37
+ @config = config
38
+ @signer = signer
39
+ @default_headers = {}
40
+ @request_option_overrides = {}
41
+ end
42
+
43
+ # Call an API with given options.
44
+ #
45
+ # @param [Symbol] http_method HTTP method/verb (e.g. :post, :get)
46
+ # @param [String] path URL path (e.g. /volumeAttachments/)
47
+ # @param [String] endpoint URL of the endpoint (e.g https://iaas.us-phoenix-1.oraclecloud.com/20160918)
48
+ # @option opts [Hash] :header_params Header parameters
49
+ # @option opts [Hash] :query_params Query parameters
50
+ # @option opts [Hash] :form_params Form parameters
51
+ # @option opts [Object] :body HTTP body in JSON
52
+ # @option [Block] block Allow to receive data from http body as streaming
53
+ #
54
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
55
+ # the data deserialized from response body (could be nil), response status code,
56
+ # and response headers.
57
+ def call_api(http_method, path, endpoint, opts, &block)
58
+ http_method = http_method.to_sym.downcase
59
+
60
+ return call_api_inner(http_method, path, endpoint, opts, &block) unless http_method == :get
61
+
62
+ # Wrap get calls in a lambda that can be called later for paging
63
+ # and wait_until.
64
+ proc = lambda { |page|
65
+ unless page.nil?
66
+ opts[:query_params] ||= {}
67
+ opts[:query_params][:page] = page
68
+ end
69
+
70
+ return call_api_inner(http_method, path, endpoint, opts, &block)
71
+ }
72
+
73
+ response = proc.call(nil)
74
+ response.api_call = proc
75
+ response
76
+ end
77
+
78
+ # Convert object (array, hash, object, etc) to JSON string.
79
+ # @param [Object] model object to be converted into JSON string
80
+ # @return [String] JSON string representation of the object
81
+ def object_to_http_body(model)
82
+ # to support IO-like object as well like StringIO
83
+ return model if model.nil? || model.is_a?(String) || (model.respond_to?(:read) && model.respond_to?(:write))
84
+ if model.is_a?(Array)
85
+ local_body = model.map{|m| object_to_hash(m) }
86
+ else
87
+ local_body = object_to_hash(model)
88
+ end
89
+ local_body.to_json
90
+ end
91
+
92
+ # Builds the client info string to be sent with each request.
93
+ def build_request_id
94
+ return SecureRandom.uuid.gsub!('-', '').upcase
95
+ end
96
+
97
+ # Builds the client info string to be sent with each request.
98
+ def build_user_info
99
+ return "Oracle-RubySDK/#{VERSION}"
100
+ end
101
+
102
+ # Build the user agent string to be send with each request.
103
+ def build_user_agent
104
+ agent = "#{build_user_info} (ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})"
105
+
106
+ if config.additional_user_agent
107
+ agent = "#{agent} #{config.additional_user_agent}"
108
+ end
109
+
110
+ agent
111
+ end
112
+
113
+ private
114
+
115
+ def call_api_inner(http_method, path, endpoint, opts, &block)
116
+ query_params = opts[:query_params] || {}
117
+ header_params = @default_headers.merge(opts[:header_params] || {})
118
+ form_params = opts[:form_params] || {}
119
+ body = opts[:body] || nil
120
+
121
+ url = ApiClient.append_query_params(build_request_url(path, endpoint), query_params)
122
+ uri = URI(url)
123
+
124
+ request = nil
125
+
126
+ if http_method == :get
127
+ request = Net::HTTP::Get.new(uri)
128
+ elsif http_method == :put
129
+ request = Net::HTTP::Put.new(uri)
130
+ elsif http_method == :post
131
+ request = Net::HTTP::Post.new(uri)
132
+ elsif http_method == :delete
133
+ request = Net::HTTP::Delete.new(uri)
134
+ elsif http_method == :head
135
+ request = Net::HTTP::Head.new(uri)
136
+ else
137
+ fail "new http method (#{http_method}) needs to be supported!"
138
+ end
139
+
140
+ if body.respond_to?(:read) && body.respond_to?(:write)
141
+ request.body_stream = body
142
+ else
143
+ if %i[post, put, delete].include?(http_method)
144
+ body = build_request_body(header_params, form_params, body)
145
+ end
146
+
147
+ request.body = body
148
+ end
149
+
150
+ if @config.logger
151
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{body}\n~END~\n"
152
+ end
153
+
154
+ @signer.sign(http_method, url, header_params, body)
155
+
156
+ header_params.each do |key, value|
157
+ request[key.to_s] = value
158
+ end
159
+
160
+ request['opc-client-info'] = build_user_info
161
+ request['opc-request-id'] ||= build_request_id
162
+ request['User-Agent'] = build_user_agent
163
+
164
+ http = Net::HTTP.new(uri.hostname, uri.port)
165
+
166
+ unless @request_option_overrides.empty?
167
+ http.methods.grep(/\A(\w+)=\z/) do |meth|
168
+ key = $1.to_sym
169
+ @request_option_overrides.key?(key) or next
170
+ http.__send__(meth, @request_option_overrides[key])
171
+ end
172
+ end
173
+
174
+ http.use_ssl = (uri.scheme == 'https')
175
+ http.set_debug_output(@config.log_requests ? $stdout : nil)
176
+ http.open_timeout = @config.connection_timeout
177
+ http.read_timeout = @config.timeout.zero? ? 31_536_000 : @config.timeout # 31536000 means 365 days
178
+
179
+ begin
180
+ http.start do
181
+ http.request request do |response|
182
+
183
+ # If the response is timeout already, does not make sense to parse the http body because partial
184
+ # response may be returned, we should skip JSON parser and raise exception immediately
185
+ if response.is_a? Net::HTTPRequestTimeOut
186
+ raise Errors::NetworkError, response.message
187
+ end
188
+
189
+ # process headers for opc-meta- key
190
+ metadata = {}
191
+ prefix_size = 'opc-meta-'.length.freeze
192
+ response.each_header do |key, value|
193
+ if key.start_with? 'opc-meta-'
194
+ metadata[key[prefix_size..-1]] = value
195
+ end
196
+ end
197
+
198
+ metadata.each do |key, value|
199
+ response.delete "opc-meta-#{key}"
200
+ response[key] = value
201
+ end
202
+
203
+ if block.nil? || !success?(response)
204
+ if @config.logger
205
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
206
+ end
207
+
208
+ # In the case of an error, deserialize to a plain hash by indicating 'Object'.
209
+ return_type = success?(response) ? opts[:return_type] : 'Object'
210
+ data = return_type ? deserialize(response, return_type) : nil
211
+
212
+ unless success? response
213
+ if data
214
+ raise Errors::ServiceError.new(response.code.to_i,
215
+ data[:code],
216
+ response.header['opc-request-id'],
217
+ data[:message])
218
+ else
219
+ raise Errors::NetworkError, response.message
220
+ end
221
+ end
222
+
223
+ if @config.logger
224
+ @config.logger.debug "API Response Received:\nData: #{data.inspect}\nStatus code: #{response.code}\nHeaders: #{response.header}"
225
+ end
226
+
227
+ return Response.new(response.code.to_i, response.header, data)
228
+ else
229
+ response.read_body do |chunk|
230
+ yield chunk, response
231
+ end
232
+ return Response.new(response.code.to_i, response.header, nil)
233
+ end
234
+ end
235
+ end
236
+ rescue Errors::NetworkError, Errors::ServiceError, JSON::ParserError
237
+ raise
238
+ rescue => ex
239
+ raise Errors::NetworkError, ex.message
240
+ end
241
+ end
242
+
243
+ def success?(response)
244
+ response.is_a?(Net::HTTPSuccess)
245
+ end
246
+
247
+ def self.append_query_params(url, query_params)
248
+ if query_params.empty?
249
+ url
250
+ else
251
+ # First divide our query params into ones where the param value is and isn't a hash. The params where the value is a hash
252
+ # are, for example, tags we need to handle differently for inclusion in the query string. An example query_params is:
253
+ #
254
+ # {
255
+ # "stuff" => "things",
256
+ # "definedTags" => { "tag1" => ["val1", "val2", "val3"], "tag2" => ["val1"] },
257
+ # "definedTagsExists" => { "tag3" => true, "tag4" => true }
258
+ # }
259
+ #
260
+ # So our non_hash_params will be: { "stuff" => "things" }
261
+ # And our hash_params will be: { "definedTags" => { "tag1" => ["val1", "val2", "val3"], "tag2" => ["val1"] }, "definedTagsExists" => { "tag3" => true, "tag4" => true } }
262
+ non_hash_params = query_params.select { |k,v| !v.is_a?(Hash) }.to_h
263
+ hash_params = query_params.select { |k,v| v.is_a?(Hash) }.to_h
264
+
265
+ # Simple params just go key to value
266
+ base_query_string = ''
267
+ base_query_string << non_hash_params.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&') unless non_hash_params.empty?
268
+
269
+ # Using the previous comment:
270
+ # k = "definedTags", v = { "tag1" => [...] }
271
+ #
272
+ # Hash params are exploded as follows:
273
+ #
274
+ # - If value in v is an array then we explode the content like: #{k}.#{v.key}=#{v.value[0]}&#{k}.#{v.key}=#{v.value[1]}&... so that there is
275
+ # one query string parameter per item in the array
276
+ # - If value in v is not an array then we explode the content like: #{k}.#{v.key}=#{v.value}
277
+ hash_params.each do |k,v|
278
+ v.each do |tag_key, tag_val|
279
+ # TODO: Should this be ERB::Util.url_encode instead? CGI.escape gives "+" here but url_encode will give %20
280
+ # CGI.escape is what we've been using until now, and it looks like it works...A literal "+" in the string will
281
+ # be encoded to %2B
282
+ query_string_val = if tag_val.is_a?(Array)
283
+ # to_s tag_key to avoid errors around implicit conversion of symbols to strings
284
+ tag_val.map { |tv| "#{k}.#{CGI.escape(tag_key.to_s)}=#{CGI.escape(tv.to_s)}" }.join('&')
285
+ else
286
+ "#{k}.#{CGI.escape(tag_key.to_s)}=#{CGI.escape(tag_val.to_s)}"
287
+ end
288
+ base_query_string << '&' unless base_query_string.empty?
289
+ base_query_string << query_string_val
290
+ end
291
+ end
292
+
293
+ url << '?' unless base_query_string.empty?
294
+ url << base_query_string
295
+
296
+ url
297
+ end
298
+ end
299
+
300
+ # Check if the given MIME is a JSON MIME.
301
+ # JSON MIME examples:
302
+ # application/json
303
+ # application/json; charset=UTF8
304
+ # APPLICATION/JSON
305
+ # @param [String] mime MIME
306
+ # @return [Boolean] True if the MIME is applicaton/json
307
+ def json_mime?(mime)
308
+ !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
309
+ end
310
+
311
+ # Deserialize the response to the given return type.
312
+ #
313
+ # @param [Response] response HTTP response
314
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
315
+ def deserialize(response, return_type)
316
+ body = response.body
317
+ return if body.nil? || body.empty?
318
+
319
+ # ensuring a default content type
320
+ content_type = response.content_type || 'application/json'
321
+
322
+ return body if (return_type == 'String' && !json_mime?(content_type)) || return_type == 'Stream'
323
+
324
+ fail "content-type is not supported: #{content_type}" unless json_mime?(content_type)
325
+
326
+ begin
327
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
328
+ rescue JSON::ParserError => e
329
+ if %w(String Date DateTime).include?(return_type)
330
+ data = body
331
+ else
332
+ raise e
333
+ end
334
+ end
335
+
336
+ OCI::Internal::Util.convert_to_type return_type, data
337
+ end
338
+
339
+ def build_request_url(path, endpoint)
340
+ # Add leading and trailing slashes to path
341
+ path = "/#{path}".gsub(/\/+/, '/')
342
+
343
+ if endpoint.end_with? '/'
344
+ endpoint = endpoint.chop
345
+ end
346
+ URI.encode(endpoint + path)
347
+ end
348
+
349
+ # Builds the HTTP request body
350
+ #
351
+ # @param [Hash] header_params Header parameters
352
+ # @param [Hash] form_params Query parameters
353
+ # @param [Object] body HTTP body (JSON/XML)
354
+ # @return [String] HTTP body data in the form of string
355
+ def build_request_body(header_params, form_params, body)
356
+ # http form
357
+ if header_params['content-type'] == 'application/x-www-form-urlencoded' ||
358
+ header_params['content-type'] == 'multipart/form-data'
359
+ data = {}
360
+ form_params.each do |key, value|
361
+ case value
362
+ when File, Array, nil
363
+ # let typhoeus handle File, Array and nil parameters
364
+ data[key] = value
365
+ else
366
+ data[key] = value.to_s
367
+ end
368
+ end
369
+ elsif body
370
+ data = body.is_a?(String) ? body : body.to_json
371
+ else
372
+ data = nil
373
+ end
374
+ data
375
+ end
376
+
377
+ # Convert object(non-array) to hash.
378
+ # @param [Object] obj object to be converted into JSON string
379
+ # @return [String] JSON string representation of the object
380
+ def object_to_hash(obj)
381
+ if obj.respond_to?(:to_hash)
382
+ obj.to_hash
383
+ else
384
+ obj
385
+ end
386
+ end
387
+
388
+ end
389
+ end