oraclebmc 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/{README.md → README_BMCS.md} +21 -26
  3. data/lib/oraclebmc.rb +1 -19
  4. metadata +16 -259
  5. data/lib/oraclebmc/api_client.rb +0 -306
  6. data/lib/oraclebmc/config.rb +0 -80
  7. data/lib/oraclebmc/config_file_loader.rb +0 -85
  8. data/lib/oraclebmc/core/blockstorage_client.rb +0 -460
  9. data/lib/oraclebmc/core/compute_client.rb +0 -1267
  10. data/lib/oraclebmc/core/core.rb +0 -112
  11. data/lib/oraclebmc/core/models/attach_i_scsi_volume_details.rb +0 -137
  12. data/lib/oraclebmc/core/models/attach_vnic_details.rb +0 -144
  13. data/lib/oraclebmc/core/models/attach_volume_details.rb +0 -165
  14. data/lib/oraclebmc/core/models/capture_console_history_details.rb +0 -120
  15. data/lib/oraclebmc/core/models/console_history.rb +0 -213
  16. data/lib/oraclebmc/core/models/cpe.rb +0 -169
  17. data/lib/oraclebmc/core/models/create_cpe_details.rb +0 -145
  18. data/lib/oraclebmc/core/models/create_cross_connect_details.rb +0 -204
  19. data/lib/oraclebmc/core/models/create_cross_connect_group_details.rb +0 -133
  20. data/lib/oraclebmc/core/models/create_dhcp_details.rb +0 -153
  21. data/lib/oraclebmc/core/models/create_drg_attachment_details.rb +0 -142
  22. data/lib/oraclebmc/core/models/create_drg_details.rb +0 -131
  23. data/lib/oraclebmc/core/models/create_image_details.rb +0 -159
  24. data/lib/oraclebmc/core/models/create_internet_gateway_details.rb +0 -153
  25. data/lib/oraclebmc/core/models/create_ip_sec_connection_details.rb +0 -168
  26. data/lib/oraclebmc/core/models/create_private_ip_details.rb +0 -173
  27. data/lib/oraclebmc/core/models/create_route_table_details.rb +0 -153
  28. data/lib/oraclebmc/core/models/create_security_list_details.rb +0 -164
  29. data/lib/oraclebmc/core/models/create_subnet_details.rb +0 -257
  30. data/lib/oraclebmc/core/models/create_vcn_details.rb +0 -171
  31. data/lib/oraclebmc/core/models/create_virtual_circuit_details.rb +0 -260
  32. data/lib/oraclebmc/core/models/create_vnic_details.rb +0 -214
  33. data/lib/oraclebmc/core/models/create_volume_backup_details.rb +0 -133
  34. data/lib/oraclebmc/core/models/create_volume_details.rb +0 -170
  35. data/lib/oraclebmc/core/models/cross_connect.rb +0 -235
  36. data/lib/oraclebmc/core/models/cross_connect_group.rb +0 -187
  37. data/lib/oraclebmc/core/models/cross_connect_location.rb +0 -134
  38. data/lib/oraclebmc/core/models/cross_connect_mapping.rb +0 -190
  39. data/lib/oraclebmc/core/models/cross_connect_port_speed_shape.rb +0 -137
  40. data/lib/oraclebmc/core/models/cross_connect_status.rb +0 -200
  41. data/lib/oraclebmc/core/models/dhcp_dns_option.rb +0 -171
  42. data/lib/oraclebmc/core/models/dhcp_option.rb +0 -135
  43. data/lib/oraclebmc/core/models/dhcp_options.rb +0 -208
  44. data/lib/oraclebmc/core/models/dhcp_search_domain_option.rb +0 -141
  45. data/lib/oraclebmc/core/models/drg.rb +0 -186
  46. data/lib/oraclebmc/core/models/drg_attachment.rb +0 -208
  47. data/lib/oraclebmc/core/models/egress_security_rule.rb +0 -198
  48. data/lib/oraclebmc/core/models/export_image_details.rb +0 -134
  49. data/lib/oraclebmc/core/models/export_image_via_object_storage_tuple_details.rb +0 -150
  50. data/lib/oraclebmc/core/models/export_image_via_object_storage_uri_details.rb +0 -130
  51. data/lib/oraclebmc/core/models/fast_connect_provider_service.rb +0 -145
  52. data/lib/oraclebmc/core/models/i_scsi_volume_attachment.rb +0 -212
  53. data/lib/oraclebmc/core/models/icmp_options.rb +0 -131
  54. data/lib/oraclebmc/core/models/image.rb +0 -245
  55. data/lib/oraclebmc/core/models/image_source_details.rb +0 -134
  56. data/lib/oraclebmc/core/models/image_source_via_object_storage_tuple_details.rb +0 -150
  57. data/lib/oraclebmc/core/models/image_source_via_object_storage_uri_details.rb +0 -128
  58. data/lib/oraclebmc/core/models/ingress_security_rule.rb +0 -198
  59. data/lib/oraclebmc/core/models/instance.rb +0 -307
  60. data/lib/oraclebmc/core/models/instance_credentials.rb +0 -131
  61. data/lib/oraclebmc/core/models/internet_gateway.rb +0 -210
  62. data/lib/oraclebmc/core/models/ip_sec_connection.rb +0 -223
  63. data/lib/oraclebmc/core/models/ip_sec_connection_device_config.rb +0 -153
  64. data/lib/oraclebmc/core/models/ip_sec_connection_device_status.rb +0 -156
  65. data/lib/oraclebmc/core/models/launch_instance_details.rb +0 -336
  66. data/lib/oraclebmc/core/models/letter_of_authority.rb +0 -194
  67. data/lib/oraclebmc/core/models/port_range.rb +0 -133
  68. data/lib/oraclebmc/core/models/private_ip.rb +0 -248
  69. data/lib/oraclebmc/core/models/route_rule.rb +0 -135
  70. data/lib/oraclebmc/core/models/route_table.rb +0 -208
  71. data/lib/oraclebmc/core/models/security_list.rb +0 -219
  72. data/lib/oraclebmc/core/models/shape.rb +0 -122
  73. data/lib/oraclebmc/core/models/subnet.rb +0 -351
  74. data/lib/oraclebmc/core/models/tcp_options.rb +0 -135
  75. data/lib/oraclebmc/core/models/tunnel_config.rb +0 -151
  76. data/lib/oraclebmc/core/models/tunnel_status.rb +0 -178
  77. data/lib/oraclebmc/core/models/udp_options.rb +0 -135
  78. data/lib/oraclebmc/core/models/update_cpe_details.rb +0 -122
  79. data/lib/oraclebmc/core/models/update_cross_connect_details.rb +0 -138
  80. data/lib/oraclebmc/core/models/update_cross_connect_group_details.rb +0 -122
  81. data/lib/oraclebmc/core/models/update_dhcp_details.rb +0 -132
  82. data/lib/oraclebmc/core/models/update_drg_attachment_details.rb +0 -122
  83. data/lib/oraclebmc/core/models/update_drg_details.rb +0 -122
  84. data/lib/oraclebmc/core/models/update_image_details.rb +0 -124
  85. data/lib/oraclebmc/core/models/update_instance_details.rb +0 -124
  86. data/lib/oraclebmc/core/models/update_internet_gateway_details.rb +0 -133
  87. data/lib/oraclebmc/core/models/update_ip_sec_connection_details.rb +0 -122
  88. data/lib/oraclebmc/core/models/update_private_ip_details.rb +0 -157
  89. data/lib/oraclebmc/core/models/update_route_table_details.rb +0 -133
  90. data/lib/oraclebmc/core/models/update_security_list_details.rb +0 -144
  91. data/lib/oraclebmc/core/models/update_subnet_details.rb +0 -122
  92. data/lib/oraclebmc/core/models/update_vcn_details.rb +0 -122
  93. data/lib/oraclebmc/core/models/update_virtual_circuit_details.rb +0 -240
  94. data/lib/oraclebmc/core/models/update_vnic_details.rb +0 -144
  95. data/lib/oraclebmc/core/models/update_volume_backup_details.rb +0 -122
  96. data/lib/oraclebmc/core/models/update_volume_details.rb +0 -122
  97. data/lib/oraclebmc/core/models/vcn.rb +0 -276
  98. data/lib/oraclebmc/core/models/virtual_circuit.rb +0 -395
  99. data/lib/oraclebmc/core/models/virtual_circuit_bandwidth_shape.rb +0 -137
  100. data/lib/oraclebmc/core/models/vnic.rb +0 -287
  101. data/lib/oraclebmc/core/models/vnic_attachment.rb +0 -250
  102. data/lib/oraclebmc/core/models/volume.rb +0 -210
  103. data/lib/oraclebmc/core/models/volume_attachment.rb +0 -246
  104. data/lib/oraclebmc/core/models/volume_backup.rb +0 -235
  105. data/lib/oraclebmc/core/util.rb +0 -1
  106. data/lib/oraclebmc/core/virtual_network_client.rb +0 -3419
  107. data/lib/oraclebmc/errors.rb +0 -80
  108. data/lib/oraclebmc/global_context.rb +0 -21
  109. data/lib/oraclebmc/identity/identity.rb +0 -51
  110. data/lib/oraclebmc/identity/identity_client.rb +0 -1983
  111. data/lib/oraclebmc/identity/models/add_user_to_group_details.rb +0 -131
  112. data/lib/oraclebmc/identity/models/api_key.rb +0 -211
  113. data/lib/oraclebmc/identity/models/availability_domain.rb +0 -131
  114. data/lib/oraclebmc/identity/models/compartment.rb +0 -211
  115. data/lib/oraclebmc/identity/models/create_api_key_details.rb +0 -120
  116. data/lib/oraclebmc/identity/models/create_compartment_details.rb +0 -145
  117. data/lib/oraclebmc/identity/models/create_group_details.rb +0 -144
  118. data/lib/oraclebmc/identity/models/create_identity_provider_details.rb +0 -212
  119. data/lib/oraclebmc/identity/models/create_idp_group_mapping_details.rb +0 -133
  120. data/lib/oraclebmc/identity/models/create_policy_details.rb +0 -173
  121. data/lib/oraclebmc/identity/models/create_region_subscription_details.rb +0 -127
  122. data/lib/oraclebmc/identity/models/create_saml2_identity_provider_details.rb +0 -154
  123. data/lib/oraclebmc/identity/models/create_swift_password_details.rb +0 -121
  124. data/lib/oraclebmc/identity/models/create_user_details.rb +0 -144
  125. data/lib/oraclebmc/identity/models/group.rb +0 -211
  126. data/lib/oraclebmc/identity/models/identity_provider.rb +0 -256
  127. data/lib/oraclebmc/identity/models/idp_group_mapping.rb +0 -220
  128. data/lib/oraclebmc/identity/models/policy.rb +0 -237
  129. data/lib/oraclebmc/identity/models/region.rb +0 -141
  130. data/lib/oraclebmc/identity/models/region_subscription.rb +0 -178
  131. data/lib/oraclebmc/identity/models/saml2_identity_provider.rb +0 -180
  132. data/lib/oraclebmc/identity/models/swift_password.rb +0 -226
  133. data/lib/oraclebmc/identity/models/tenancy.rb +0 -158
  134. data/lib/oraclebmc/identity/models/ui_password.rb +0 -187
  135. data/lib/oraclebmc/identity/models/update_compartment_details.rb +0 -120
  136. data/lib/oraclebmc/identity/models/update_group_details.rb +0 -120
  137. data/lib/oraclebmc/identity/models/update_identity_provider_details.rb +0 -160
  138. data/lib/oraclebmc/identity/models/update_idp_group_mapping_details.rb +0 -131
  139. data/lib/oraclebmc/identity/models/update_policy_details.rb +0 -148
  140. data/lib/oraclebmc/identity/models/update_saml2_identity_provider_details.rb +0 -145
  141. data/lib/oraclebmc/identity/models/update_state_details.rb +0 -121
  142. data/lib/oraclebmc/identity/models/update_swift_password_details.rb +0 -120
  143. data/lib/oraclebmc/identity/models/update_user_details.rb +0 -120
  144. data/lib/oraclebmc/identity/models/user.rb +0 -217
  145. data/lib/oraclebmc/identity/models/user_group_membership.rb +0 -209
  146. data/lib/oraclebmc/identity/util.rb +0 -1
  147. data/lib/oraclebmc/internal/internal.rb +0 -11
  148. data/lib/oraclebmc/internal/util.rb +0 -69
  149. data/lib/oraclebmc/load_balancer/load_balancer.rb +0 -46
  150. data/lib/oraclebmc/load_balancer/load_balancer_client.rb +0 -1281
  151. data/lib/oraclebmc/load_balancer/models/backend.rb +0 -220
  152. data/lib/oraclebmc/load_balancer/models/backend_details.rb +0 -206
  153. data/lib/oraclebmc/load_balancer/models/backend_set.rb +0 -179
  154. data/lib/oraclebmc/load_balancer/models/backend_set_details.rb +0 -165
  155. data/lib/oraclebmc/load_balancer/models/certificate.rb +0 -167
  156. data/lib/oraclebmc/load_balancer/models/certificate_details.rb +0 -203
  157. data/lib/oraclebmc/load_balancer/models/create_backend_details.rb +0 -206
  158. data/lib/oraclebmc/load_balancer/models/create_backend_set_details.rb +0 -178
  159. data/lib/oraclebmc/load_balancer/models/create_certificate_details.rb +0 -203
  160. data/lib/oraclebmc/load_balancer/models/create_listener_details.rb +0 -174
  161. data/lib/oraclebmc/load_balancer/models/create_load_balancer_details.rb +0 -219
  162. data/lib/oraclebmc/load_balancer/models/health_checker.rb +0 -223
  163. data/lib/oraclebmc/load_balancer/models/health_checker_details.rb +0 -222
  164. data/lib/oraclebmc/load_balancer/models/ip_address.rb +0 -139
  165. data/lib/oraclebmc/load_balancer/models/listener.rb +0 -174
  166. data/lib/oraclebmc/load_balancer/models/listener_details.rb +0 -160
  167. data/lib/oraclebmc/load_balancer/models/load_balancer.rb +0 -280
  168. data/lib/oraclebmc/load_balancer/models/load_balancer_policy.rb +0 -120
  169. data/lib/oraclebmc/load_balancer/models/load_balancer_protocol.rb +0 -120
  170. data/lib/oraclebmc/load_balancer/models/load_balancer_shape.rb +0 -120
  171. data/lib/oraclebmc/load_balancer/models/session_persistence_configuration_details.rb +0 -141
  172. data/lib/oraclebmc/load_balancer/models/ssl_configuration.rb +0 -153
  173. data/lib/oraclebmc/load_balancer/models/ssl_configuration_details.rb +0 -153
  174. data/lib/oraclebmc/load_balancer/models/update_backend_details.rb +0 -178
  175. data/lib/oraclebmc/load_balancer/models/update_backend_set_details.rb +0 -165
  176. data/lib/oraclebmc/load_balancer/models/update_health_checker_details.rb +0 -221
  177. data/lib/oraclebmc/load_balancer/models/update_listener_details.rb +0 -160
  178. data/lib/oraclebmc/load_balancer/models/update_load_balancer_details.rb +0 -123
  179. data/lib/oraclebmc/load_balancer/models/work_request.rb +0 -229
  180. data/lib/oraclebmc/load_balancer/models/work_request_error.rb +0 -145
  181. data/lib/oraclebmc/load_balancer/util.rb +0 -55
  182. data/lib/oraclebmc/regions.rb +0 -41
  183. data/lib/oraclebmc/response.rb +0 -86
  184. data/lib/oraclebmc/signer.rb +0 -119
  185. data/lib/oraclebmc/version.rb +0 -5
  186. data/lib/oraclebmc/waiter.rb +0 -111
@@ -1,306 +0,0 @@
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 'securerandom'
7
- require 'tempfile'
8
- require 'typhoeus'
9
- require 'uri'
10
- require_relative 'signer'
11
- require_relative 'version'
12
- require_relative 'response'
13
-
14
- module OracleBMC
15
- class ApiClient
16
- # The Config object holding settings to be used in the API client.
17
- attr_accessor :config
18
-
19
- # Defines the headers to be used in HTTP requests of all API calls by default.
20
- #
21
- # @return [Hash]
22
- attr_accessor :default_headers
23
-
24
- # Request options to be sent with each Typhoeus request.
25
- # These options will override any defaults normally set by ApiClient.
26
- # See {https://github.com/typhoeus/ethon/blob/master/lib/ethon/curls/options.rb} for
27
- # some of the available options.
28
- #
29
- # @return [Hash]
30
- attr_accessor :request_option_overrides
31
-
32
- def initialize(config, signer)
33
- fail "Missing the required parameter 'config' when initializing ApiClient." if config.nil?
34
- fail "Missing the required parameter 'signer' when initializing ApiClient." if signer.nil?
35
-
36
- @config = config
37
- @signer = signer
38
- @default_headers = {}
39
- @request_option_overrides = {}
40
- end
41
-
42
- # Call an API with given options.
43
- #
44
- # @param [Symbol] http_method HTTP method/verb (e.g. :post, :get)
45
- # @param [String] path URL path (e.g. /volumeAttachments/)
46
- # @param [String] endpoint URL of the endpoint (e.g https://iaas.us-phoenix-1.oraclecloud.com/20160918)
47
- # @option opts [Hash] :header_params Header parameters
48
- # @option opts [Hash] :query_params Query parameters
49
- # @option opts [Hash] :form_params Form parameters
50
- # @option opts [Object] :body HTTP body in JSON
51
- #
52
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
53
- # the data deserialized from response body (could be nil), response status code, and response headers.
54
- def call_api(http_method, path, endpoint, opts)
55
- http_method = http_method.to_sym.downcase
56
-
57
- if http_method == :get
58
- # Wrap get calls in a lambda that can be called later for paging
59
- # and wait_until.
60
- proc = lambda { |page|
61
- if !page.nil?
62
- opts[:query_params] ||= {}
63
- opts[:query_params][:page] = page
64
- end
65
-
66
- return call_api_inner(http_method, path, endpoint, opts)
67
- }
68
-
69
- response = proc.call(nil)
70
- response.api_call = proc
71
- return response
72
- else
73
- # No need to wrap methods other than GET, just call them directly.
74
- return call_api_inner(http_method, path, endpoint, opts)
75
- end
76
-
77
- end
78
-
79
- # Convert object (array, hash, object, etc) to JSON string.
80
- # @param [Object] model object to be converted into JSON string
81
- # @return [String] JSON string representation of the object
82
- def object_to_http_body(model)
83
- return model if model.nil? || model.is_a?(String)
84
- local_body = nil
85
- if model.is_a?(Array)
86
- local_body = model.map{|m| object_to_hash(m) }
87
- else
88
- local_body = object_to_hash(model)
89
- end
90
- local_body.to_json
91
- end
92
-
93
- # Builds the client info string to be sent with each request.
94
- def build_request_id
95
- return SecureRandom.uuid.gsub!('-', '').upcase
96
- end
97
-
98
- # Builds the client info string to be sent with each request.
99
- def build_user_info
100
- return "Oracle-RubySDK/#{VERSION}"
101
- end
102
-
103
- # Build the user agent string to be send with each request.
104
- def build_user_agent
105
- agent = "#{build_user_info} (ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})"
106
-
107
- if config.additional_user_agent
108
- agent = "#{agent} #{config.additional_user_agent}"
109
- end
110
-
111
- agent
112
- end
113
-
114
- private
115
-
116
- def call_api_inner(http_method, path, endpoint, opts)
117
- request = build_request(http_method, path, endpoint, opts)
118
-
119
- if defined? ResponseMocker
120
- ResponseMocker.instance.process_request(request)
121
- end
122
-
123
- response = request.run
124
-
125
- if defined? ResponseMocker
126
- ResponseMocker.instance.process_response(response)
127
- end
128
-
129
- if @config.logger
130
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
131
- end
132
-
133
- # In the case of an error, deserialize to a plain hash by indicating 'Object'.
134
- return_type = response.success? ? opts[:return_type] : 'Object'
135
-
136
- # If the response is timeout already ready, does not make sense to parse the http body because for lower
137
- # version of CURL, partial response will be returned as well, we should ignore it.
138
- if response.return_code.to_sym.downcase == :operation_timedout
139
- fail Errors::NetworkError.new(response.return_code)
140
- end
141
-
142
- if return_type
143
- data = deserialize(response, return_type)
144
- else
145
- data = nil
146
- end
147
-
148
- unless response.success?
149
- if data and not response.success?
150
- fail Errors::ServiceError.new(response.code, data[:code], response.headers['opc-request-id'], data[:message])
151
- else
152
- fail Errors::NetworkError.new(response.return_code)
153
- end
154
- end
155
-
156
- if @config.logger
157
- @config.logger.debug "API Response Received:\nData: #{data.inspect}\nStatus code: #{response.code}\nHeaders: #{response.headers}"
158
- end
159
-
160
- return Response.new(status=response.code, headers=response.headers, data=data)
161
- end
162
-
163
-
164
- # Builds the HTTP request
165
- #
166
- # @param [Symbol] http_method HTTP method/verb (e.g. :post, :get)
167
- # @param [String] path URL path (e.g. /account/new)
168
- # @param [String] endpoint URL of the endpoint
169
- # @option opts [Hash] :header_params Header parameters
170
- # @option opts [Hash] :query_params Query parameters
171
- # @option opts [Hash] :form_params Query parameters
172
- # @option opts [Object] :body HTTP body (JSON/XML)
173
- # @return [Typhoeus::Request] A Typhoeus Request
174
- def build_request(http_method, path, endpoint, opts = {})
175
- url = build_request_url(path, endpoint)
176
-
177
- header_params = @default_headers.merge(opts[:header_params] || {})
178
- query_params = opts[:query_params] || {}
179
- form_params = opts[:form_params] || {}
180
- body = opts[:body] || nil
181
-
182
- @signer.sign(http_method, ApiClient::append_query_params(url, query_params), header_params, body)
183
-
184
- req_opts = {
185
- :method => http_method,
186
- :headers => header_params,
187
- :params => query_params,
188
- :connecttimeout => @config.connection_timeout,
189
- :timeout => @config.timeout,
190
- :verbose => @config.log_requests
191
- }.merge(@request_option_overrides)
192
-
193
- if [:post, :patch, :put, :delete].include?(http_method)
194
- req_body = build_request_body(header_params, form_params, opts[:body])
195
- req_opts.update :body => req_body
196
- if @config.logger
197
- @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
198
- end
199
- end
200
-
201
- request = Typhoeus::Request.new(url, req_opts)
202
- request.options[:headers]['opc-client-info'] = build_user_info
203
- request.options[:headers]['opc-request-id'] ||= build_request_id
204
- request.options[:headers]['User-Agent'] = build_user_agent
205
-
206
- return request
207
- end
208
-
209
- def self.append_query_params(url, query_params)
210
- if query_params.empty?
211
- url
212
- else
213
- # This must mirror the logic in Typhoeus for building query strings.
214
- # Unfortunately, Typhoeus does not appear to expose this logic or the result,
215
- # so we have to replicate it here.
216
- url + '?' + query_params.map{|k,v| "#{k}=#{CGI.escape(v)}"}.join('&')
217
- end
218
- end
219
-
220
- # Check if the given MIME is a JSON MIME.
221
- # JSON MIME examples:
222
- # application/json
223
- # application/json; charset=UTF8
224
- # APPLICATION/JSON
225
- # @param [String] mime MIME
226
- # @return [Boolean] True if the MIME is applicaton/json
227
- def json_mime?(mime)
228
- !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
229
- end
230
-
231
- # Deserialize the response to the given return type.
232
- #
233
- # @param [Response] response HTTP response
234
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
235
- def deserialize(response, return_type)
236
- body = response.body
237
- return nil if body.nil? || body.empty?
238
-
239
- # return response body directly for String return type
240
- return body if return_type == 'String'
241
-
242
- # ensuring a default content type
243
- content_type = response.headers['content-type'] || 'application/json'
244
-
245
- fail "content-type is not supported: #{content_type}" unless json_mime?(content_type)
246
-
247
- begin
248
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
249
- rescue JSON::ParserError => e
250
- if %w(String Date DateTime).include?(return_type)
251
- data = body
252
- else
253
- raise e
254
- end
255
- end
256
-
257
- OracleBMC::Internal::Util.convert_to_type return_type, data
258
- end
259
-
260
- def build_request_url(path, endpoint)
261
- # Add leading and trailing slashes to path
262
- path = "/#{path}".gsub(/\/+/, '/')
263
- URI.encode(endpoint + path)
264
- end
265
-
266
- # Builds the HTTP request body
267
- #
268
- # @param [Hash] header_params Header parameters
269
- # @param [Hash] form_params Query parameters
270
- # @param [Object] body HTTP body (JSON/XML)
271
- # @return [String] HTTP body data in the form of string
272
- def build_request_body(header_params, form_params, body)
273
- # http form
274
- if header_params['content-type'] == 'application/x-www-form-urlencoded' ||
275
- header_params['content-type'] == 'multipart/form-data'
276
- data = {}
277
- form_params.each do |key, value|
278
- case value
279
- when File, Array, nil
280
- # let typhoeus handle File, Array and nil parameters
281
- data[key] = value
282
- else
283
- data[key] = value.to_s
284
- end
285
- end
286
- elsif body
287
- data = body.is_a?(String) ? body : body.to_json
288
- else
289
- data = nil
290
- end
291
- data
292
- end
293
-
294
- # Convert object(non-array) to hash.
295
- # @param [Object] obj object to be converted into JSON string
296
- # @return [String] JSON string representation of the object
297
- def object_to_hash(obj)
298
- if obj.respond_to?(:to_hash)
299
- obj.to_hash
300
- else
301
- obj
302
- end
303
- end
304
-
305
- end
306
- end
@@ -1,80 +0,0 @@
1
- # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2
-
3
- require 'uri'
4
-
5
- module OracleBMC
6
- class Config
7
-
8
- # OCID of the user to use for authentication.
9
- # Example: ocidv1:user:oc1:phx:1460406592659:aaaaaaaawcbqrkycbolrirg2n3xjl5fabc
10
- #
11
- # @return [String]
12
- attr_accessor :user
13
-
14
- # SSL Fingerprint to use for authentication.
15
- # Example: 20:3b:97:13:55:1c:1c:0d:d3:37:d8:50:4e:c5:3a:12
16
- #
17
- # @return [String]
18
- attr_accessor :fingerprint
19
-
20
- # OCID of the tenancy to use for authentication.
21
- # Example: ocid1.tenancy.oc1..aaaaaaaaba3pv6wkcr4jqae5f15p2b2m2yt2j6rx32uzr4h25vqstifsfdsq
22
- #
23
- # @return [String]
24
- attr_accessor :tenancy
25
-
26
- # Client private key file.
27
- # Example: ~/.ssh/bmc_key
28
- #
29
- # @return [String]
30
- attr_accessor :key_file
31
-
32
- # Pass phrase used for key file, if it is encrypted.
33
- #
34
- # @return [String]
35
- attr_accessor :pass_phrase
36
-
37
- # A region to use for APIs created with this Config.
38
- #
39
- # @return [OracleBMC::Regions::REGION_ENUM]
40
- attr_accessor :region
41
-
42
- # Defines the logger used for debugging.
43
- # For example, log to STDOUT by setting this to Logger.new(STDOUT).
44
- # This property cannot be set from a config file.
45
- #
46
- # @return [Logger]
47
- attr_accessor :logger
48
-
49
- # Whether to log detailed request and response
50
- # data. This will always write to STDOUT.
51
- # Defaults to false.
52
- #
53
- # @return [true, false]
54
- attr_accessor :log_requests
55
-
56
- # The time limit for HTTP request in seconds.
57
- # Defaults to 0 (never times out).
58
- #
59
- # @return [Integer]
60
- attr_accessor :timeout
61
-
62
- # The time limit for the connection phase in seconds.
63
- # Defaults to 10 seconds.
64
- #
65
- # @return [Integer]
66
- attr_accessor :connection_timeout
67
-
68
- # If set, then this string will be added to the
69
- # user agent sent with each request.
70
- #
71
- # @return [String]
72
- attr_accessor :additional_user_agent
73
-
74
- def initialize
75
- @timeout = 0
76
- @connection_timeout = 10
77
- @log_requests = false
78
- end
79
- end
80
- end
@@ -1,85 +0,0 @@
1
- # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2
-
3
- require 'inifile'
4
- require_relative 'config'
5
-
6
- module OracleBMC
7
-
8
- module ConfigFileLoader
9
-
10
- module Errors
11
- class ConfigFileNotFoundError < RuntimeError; end
12
- class ProfileNotFoundError < RuntimeError; end
13
- class DefaultProfileDoesNotExistError < RuntimeError; end
14
- end
15
-
16
- # Name of the default profile to load from a config file
17
- DEFAULT_PROFILE = 'DEFAULT'
18
-
19
- # Default config file name and location
20
- DEFAULT_CONFIG_FILE = '~/.oraclebmc/config'
21
-
22
- # Loads the a Config from the specified file and profile.
23
- #
24
- # @param [String] config_file_location Filename and path of the config file. Defaults to "~/.oraclebmc/config"
25
- # @param [String] profile_name Name of the profile from the file. Defaults to "DEFAULT".
26
- # @return [Config] A Config
27
- def self.load_config(config_file_location: DEFAULT_CONFIG_FILE, profile_name: DEFAULT_PROFILE)
28
- configs = load_configs(config_file_location)
29
-
30
- if configs && configs.key?(profile_name)
31
- return configs[profile_name]
32
- else
33
- raise Errors::ProfileNotFoundError.new("Profile not found in the given config file.")
34
- end
35
- end
36
-
37
- # Loads all of the Configs from the specified file.
38
- #
39
- # @param [String] config_file_location Filename and path of the config file.
40
- # @return [Array<Config>] An array containing all the configs found in the given file.
41
- def self.load_configs(config_file_location)
42
- config_file_location = File.expand_path(config_file_location)
43
-
44
- unless File.file?(config_file_location)
45
- raise Errors::ConfigFileNotFoundError.new("Config file does not exist.")
46
- end
47
-
48
- config_file = IniFile.load(config_file_location)
49
- configs = {}
50
-
51
- if config_file.nil? || !config_file.has_section?(DEFAULT_PROFILE)
52
- raise Errors::DefaultProfileDoesNotExistError.new("The DEFAULT profile does not exist.")
53
- end
54
-
55
- config_file.each_section do |section|
56
- config = Config.new
57
-
58
- unless section.equal? DEFAULT_PROFILE
59
- load_section(config_file[DEFAULT_PROFILE], config)
60
- end
61
- load_section(config_file[section], config)
62
-
63
- configs[section] = config
64
- end
65
-
66
- return configs
67
- end
68
-
69
- def self.load_section(section, config)
70
- section.each_key do |key|
71
- value = section[key]
72
-
73
- if key == "key_file"
74
- value = File.expand_path(value)
75
- end
76
-
77
- config.instance_variable_set("@" + key, value)
78
- end
79
- end
80
-
81
- private_class_method :load_section
82
-
83
- end
84
-
85
- end