oci 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +82 -0
- data/README.md +262 -0
- data/lib/oci.rb +25 -0
- data/lib/oci/api_client.rb +389 -0
- data/lib/oci/config.rb +118 -0
- data/lib/oci/config_file_loader.rb +96 -0
- data/lib/oci/core/blockstorage_client.rb +462 -0
- data/lib/oci/core/compute_client.rb +1415 -0
- data/lib/oci/core/core.rb +114 -0
- data/lib/oci/core/models/attach_i_scsi_volume_details.rb +137 -0
- data/lib/oci/core/models/attach_vnic_details.rb +144 -0
- data/lib/oci/core/models/attach_volume_details.rb +165 -0
- data/lib/oci/core/models/capture_console_history_details.rb +120 -0
- data/lib/oci/core/models/console_history.rb +213 -0
- data/lib/oci/core/models/cpe.rb +169 -0
- data/lib/oci/core/models/create_cpe_details.rb +145 -0
- data/lib/oci/core/models/create_cross_connect_details.rb +204 -0
- data/lib/oci/core/models/create_cross_connect_group_details.rb +133 -0
- data/lib/oci/core/models/create_dhcp_details.rb +153 -0
- data/lib/oci/core/models/create_drg_attachment_details.rb +142 -0
- data/lib/oci/core/models/create_drg_details.rb +131 -0
- data/lib/oci/core/models/create_image_details.rb +159 -0
- data/lib/oci/core/models/create_instance_console_connection_details.rb +131 -0
- data/lib/oci/core/models/create_internet_gateway_details.rb +153 -0
- data/lib/oci/core/models/create_ip_sec_connection_details.rb +168 -0
- data/lib/oci/core/models/create_private_ip_details.rb +173 -0
- data/lib/oci/core/models/create_route_table_details.rb +153 -0
- data/lib/oci/core/models/create_security_list_details.rb +164 -0
- data/lib/oci/core/models/create_subnet_details.rb +257 -0
- data/lib/oci/core/models/create_vcn_details.rb +171 -0
- data/lib/oci/core/models/create_virtual_circuit_details.rb +260 -0
- data/lib/oci/core/models/create_vnic_details.rb +214 -0
- data/lib/oci/core/models/create_volume_backup_details.rb +133 -0
- data/lib/oci/core/models/create_volume_details.rb +170 -0
- data/lib/oci/core/models/cross_connect.rb +235 -0
- data/lib/oci/core/models/cross_connect_group.rb +187 -0
- data/lib/oci/core/models/cross_connect_location.rb +134 -0
- data/lib/oci/core/models/cross_connect_mapping.rb +190 -0
- data/lib/oci/core/models/cross_connect_port_speed_shape.rb +137 -0
- data/lib/oci/core/models/cross_connect_status.rb +200 -0
- data/lib/oci/core/models/dhcp_dns_option.rb +171 -0
- data/lib/oci/core/models/dhcp_option.rb +135 -0
- data/lib/oci/core/models/dhcp_options.rb +208 -0
- data/lib/oci/core/models/dhcp_search_domain_option.rb +141 -0
- data/lib/oci/core/models/drg.rb +186 -0
- data/lib/oci/core/models/drg_attachment.rb +208 -0
- data/lib/oci/core/models/egress_security_rule.rb +198 -0
- data/lib/oci/core/models/export_image_details.rb +134 -0
- data/lib/oci/core/models/export_image_via_object_storage_tuple_details.rb +150 -0
- data/lib/oci/core/models/export_image_via_object_storage_uri_details.rb +130 -0
- data/lib/oci/core/models/fast_connect_provider_service.rb +145 -0
- data/lib/oci/core/models/i_scsi_volume_attachment.rb +212 -0
- data/lib/oci/core/models/icmp_options.rb +131 -0
- data/lib/oci/core/models/image.rb +245 -0
- data/lib/oci/core/models/image_source_details.rb +134 -0
- data/lib/oci/core/models/image_source_via_object_storage_tuple_details.rb +150 -0
- data/lib/oci/core/models/image_source_via_object_storage_uri_details.rb +128 -0
- data/lib/oci/core/models/ingress_security_rule.rb +198 -0
- data/lib/oci/core/models/instance.rb +307 -0
- data/lib/oci/core/models/instance_console_connection.rb +193 -0
- data/lib/oci/core/models/instance_credentials.rb +131 -0
- data/lib/oci/core/models/internet_gateway.rb +210 -0
- data/lib/oci/core/models/ip_sec_connection.rb +223 -0
- data/lib/oci/core/models/ip_sec_connection_device_config.rb +153 -0
- data/lib/oci/core/models/ip_sec_connection_device_status.rb +156 -0
- data/lib/oci/core/models/launch_instance_details.rb +336 -0
- data/lib/oci/core/models/letter_of_authority.rb +194 -0
- data/lib/oci/core/models/port_range.rb +133 -0
- data/lib/oci/core/models/private_ip.rb +248 -0
- data/lib/oci/core/models/route_rule.rb +135 -0
- data/lib/oci/core/models/route_table.rb +208 -0
- data/lib/oci/core/models/security_list.rb +219 -0
- data/lib/oci/core/models/shape.rb +122 -0
- data/lib/oci/core/models/subnet.rb +351 -0
- data/lib/oci/core/models/tcp_options.rb +135 -0
- data/lib/oci/core/models/tunnel_config.rb +151 -0
- data/lib/oci/core/models/tunnel_status.rb +178 -0
- data/lib/oci/core/models/udp_options.rb +135 -0
- data/lib/oci/core/models/update_cpe_details.rb +122 -0
- data/lib/oci/core/models/update_cross_connect_details.rb +138 -0
- data/lib/oci/core/models/update_cross_connect_group_details.rb +122 -0
- data/lib/oci/core/models/update_dhcp_details.rb +132 -0
- data/lib/oci/core/models/update_drg_attachment_details.rb +122 -0
- data/lib/oci/core/models/update_drg_details.rb +122 -0
- data/lib/oci/core/models/update_image_details.rb +124 -0
- data/lib/oci/core/models/update_instance_details.rb +124 -0
- data/lib/oci/core/models/update_internet_gateway_details.rb +133 -0
- data/lib/oci/core/models/update_ip_sec_connection_details.rb +122 -0
- data/lib/oci/core/models/update_private_ip_details.rb +157 -0
- data/lib/oci/core/models/update_route_table_details.rb +133 -0
- data/lib/oci/core/models/update_security_list_details.rb +144 -0
- data/lib/oci/core/models/update_subnet_details.rb +122 -0
- data/lib/oci/core/models/update_vcn_details.rb +122 -0
- data/lib/oci/core/models/update_virtual_circuit_details.rb +240 -0
- data/lib/oci/core/models/update_vnic_details.rb +144 -0
- data/lib/oci/core/models/update_volume_backup_details.rb +122 -0
- data/lib/oci/core/models/update_volume_details.rb +122 -0
- data/lib/oci/core/models/vcn.rb +276 -0
- data/lib/oci/core/models/virtual_circuit.rb +395 -0
- data/lib/oci/core/models/virtual_circuit_bandwidth_shape.rb +137 -0
- data/lib/oci/core/models/vnic.rb +287 -0
- data/lib/oci/core/models/vnic_attachment.rb +250 -0
- data/lib/oci/core/models/volume.rb +210 -0
- data/lib/oci/core/models/volume_attachment.rb +246 -0
- data/lib/oci/core/models/volume_backup.rb +235 -0
- data/lib/oci/core/util.rb +1 -0
- data/lib/oci/core/virtual_network_client.rb +3421 -0
- data/lib/oci/errors.rb +78 -0
- data/lib/oci/global_context.rb +20 -0
- data/lib/oci/identity/identity.rb +55 -0
- data/lib/oci/identity/identity_client.rb +2148 -0
- data/lib/oci/identity/models/add_user_to_group_details.rb +131 -0
- data/lib/oci/identity/models/api_key.rb +211 -0
- data/lib/oci/identity/models/availability_domain.rb +131 -0
- data/lib/oci/identity/models/compartment.rb +211 -0
- data/lib/oci/identity/models/create_api_key_details.rb +120 -0
- data/lib/oci/identity/models/create_compartment_details.rb +145 -0
- data/lib/oci/identity/models/create_customer_secret_key_details.rb +121 -0
- data/lib/oci/identity/models/create_group_details.rb +144 -0
- data/lib/oci/identity/models/create_identity_provider_details.rb +215 -0
- data/lib/oci/identity/models/create_idp_group_mapping_details.rb +133 -0
- data/lib/oci/identity/models/create_policy_details.rb +173 -0
- data/lib/oci/identity/models/create_region_subscription_details.rb +128 -0
- data/lib/oci/identity/models/create_saml2_identity_provider_details.rb +154 -0
- data/lib/oci/identity/models/create_swift_password_details.rb +121 -0
- data/lib/oci/identity/models/create_user_details.rb +144 -0
- data/lib/oci/identity/models/customer_secret_key.rb +225 -0
- data/lib/oci/identity/models/customer_secret_key_summary.rb +213 -0
- data/lib/oci/identity/models/group.rb +211 -0
- data/lib/oci/identity/models/identity_provider.rb +261 -0
- data/lib/oci/identity/models/idp_group_mapping.rb +220 -0
- data/lib/oci/identity/models/policy.rb +237 -0
- data/lib/oci/identity/models/region.rb +143 -0
- data/lib/oci/identity/models/region_subscription.rb +180 -0
- data/lib/oci/identity/models/saml2_identity_provider.rb +180 -0
- data/lib/oci/identity/models/swift_password.rb +226 -0
- data/lib/oci/identity/models/tenancy.rb +159 -0
- data/lib/oci/identity/models/ui_password.rb +187 -0
- data/lib/oci/identity/models/update_compartment_details.rb +132 -0
- data/lib/oci/identity/models/update_customer_secret_key_details.rb +120 -0
- data/lib/oci/identity/models/update_group_details.rb +120 -0
- data/lib/oci/identity/models/update_identity_provider_details.rb +160 -0
- data/lib/oci/identity/models/update_idp_group_mapping_details.rb +131 -0
- data/lib/oci/identity/models/update_policy_details.rb +148 -0
- data/lib/oci/identity/models/update_saml2_identity_provider_details.rb +145 -0
- data/lib/oci/identity/models/update_state_details.rb +121 -0
- data/lib/oci/identity/models/update_swift_password_details.rb +120 -0
- data/lib/oci/identity/models/update_user_details.rb +120 -0
- data/lib/oci/identity/models/user.rb +217 -0
- data/lib/oci/identity/models/user_group_membership.rb +209 -0
- data/lib/oci/identity/util.rb +1 -0
- data/lib/oci/internal/internal.rb +10 -0
- data/lib/oci/internal/util.rb +69 -0
- data/lib/oci/load_balancer/load_balancer.rb +51 -0
- data/lib/oci/load_balancer/load_balancer_client.rb +1449 -0
- data/lib/oci/load_balancer/models/backend.rb +220 -0
- data/lib/oci/load_balancer/models/backend_details.rb +206 -0
- data/lib/oci/load_balancer/models/backend_health.rb +158 -0
- data/lib/oci/load_balancer/models/backend_set.rb +182 -0
- data/lib/oci/load_balancer/models/backend_set_details.rb +165 -0
- data/lib/oci/load_balancer/models/backend_set_health.rb +207 -0
- data/lib/oci/load_balancer/models/certificate.rb +169 -0
- data/lib/oci/load_balancer/models/certificate_details.rb +205 -0
- data/lib/oci/load_balancer/models/create_backend_details.rb +206 -0
- data/lib/oci/load_balancer/models/create_backend_set_details.rb +181 -0
- data/lib/oci/load_balancer/models/create_certificate_details.rb +205 -0
- data/lib/oci/load_balancer/models/create_listener_details.rb +175 -0
- data/lib/oci/load_balancer/models/create_load_balancer_details.rb +220 -0
- data/lib/oci/load_balancer/models/health_check_result.rb +183 -0
- data/lib/oci/load_balancer/models/health_checker.rb +224 -0
- data/lib/oci/load_balancer/models/health_checker_details.rb +223 -0
- data/lib/oci/load_balancer/models/ip_address.rb +139 -0
- data/lib/oci/load_balancer/models/listener.rb +174 -0
- data/lib/oci/load_balancer/models/listener_details.rb +160 -0
- data/lib/oci/load_balancer/models/load_balancer.rb +280 -0
- data/lib/oci/load_balancer/models/load_balancer_health.rb +215 -0
- data/lib/oci/load_balancer/models/load_balancer_health_summary.rb +168 -0
- data/lib/oci/load_balancer/models/load_balancer_policy.rb +120 -0
- data/lib/oci/load_balancer/models/load_balancer_protocol.rb +120 -0
- data/lib/oci/load_balancer/models/load_balancer_shape.rb +120 -0
- data/lib/oci/load_balancer/models/session_persistence_configuration_details.rb +141 -0
- data/lib/oci/load_balancer/models/ssl_configuration.rb +155 -0
- data/lib/oci/load_balancer/models/ssl_configuration_details.rb +155 -0
- data/lib/oci/load_balancer/models/update_backend_details.rb +178 -0
- data/lib/oci/load_balancer/models/update_backend_set_details.rb +165 -0
- data/lib/oci/load_balancer/models/update_health_checker_details.rb +222 -0
- data/lib/oci/load_balancer/models/update_listener_details.rb +160 -0
- data/lib/oci/load_balancer/models/update_load_balancer_details.rb +124 -0
- data/lib/oci/load_balancer/models/work_request.rb +229 -0
- data/lib/oci/load_balancer/models/work_request_error.rb +145 -0
- data/lib/oci/load_balancer/util.rb +58 -0
- data/lib/oci/object_storage/models/bucket.rb +216 -0
- data/lib/oci/object_storage/models/bucket_summary.rb +175 -0
- data/lib/oci/object_storage/models/commit_multipart_upload_details.rb +133 -0
- data/lib/oci/object_storage/models/commit_multipart_upload_part_details.rb +131 -0
- data/lib/oci/object_storage/models/create_bucket_details.rb +173 -0
- data/lib/oci/object_storage/models/create_multipart_upload_details.rb +166 -0
- data/lib/oci/object_storage/models/create_preauthenticated_request_details.rb +171 -0
- data/lib/oci/object_storage/models/list_objects.rb +146 -0
- data/lib/oci/object_storage/models/multipart_upload.rb +164 -0
- data/lib/oci/object_storage/models/multipart_upload_part_summary.rb +153 -0
- data/lib/oci/object_storage/models/object_summary.rb +153 -0
- data/lib/oci/object_storage/models/preauthenticated_request.rb +207 -0
- data/lib/oci/object_storage/models/preauthenticated_request_summary.rb +196 -0
- data/lib/oci/object_storage/models/update_bucket_details.rb +171 -0
- data/lib/oci/object_storage/object_storage.rb +30 -0
- data/lib/oci/object_storage/object_storage_client.rb +1185 -0
- data/lib/oci/object_storage/util.rb +1 -0
- data/lib/oci/regions.rb +43 -0
- data/lib/oci/response.rb +80 -0
- data/lib/oci/response_headers.rb +144 -0
- data/lib/oci/signer.rb +157 -0
- data/lib/oci/version.rb +5 -0
- data/lib/oci/waiter.rb +101 -0
- data/lib/oraclebmc.rb +3 -0
- metadata +375 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
data/lib/oci/regions.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
module OCI
|
|
4
|
+
# Module defining available regions and helper methods to get value service endpoints
|
|
5
|
+
module Regions
|
|
6
|
+
REGION_ENUM = [
|
|
7
|
+
REGION_US_PHOENIX_1 = 'us-phoenix-1'.freeze,
|
|
8
|
+
REGION_US_ASHBURN_1 = 'us-ashburn-1'.freeze
|
|
9
|
+
].freeze
|
|
10
|
+
|
|
11
|
+
SERVICE_ENDPOINT_PREFIX_MAPPING = {
|
|
12
|
+
BlockstorageClient: 'iaas',
|
|
13
|
+
ComputeClient: 'iaas',
|
|
14
|
+
VirtualNetworkClient: 'iaas',
|
|
15
|
+
IdentityClient: 'identity',
|
|
16
|
+
LoadBalancerClient: 'iaas',
|
|
17
|
+
ObjectStorageClient: 'objectstorage'
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
# Returns an endpoint for the given region and service.
|
|
21
|
+
#
|
|
22
|
+
# @param [String] region A region used to determine the service endpoint. This will usually
|
|
23
|
+
# correspond to a value in {OCI::Regions::REGION_ENUM}, but may be an arbitrary string.
|
|
24
|
+
# @param [Symbol] service A symbol representing a service client class (e.g. :IdentityClient)
|
|
25
|
+
#
|
|
26
|
+
# @return [String] A fully qualified endpoint
|
|
27
|
+
def self.get_service_endpoint(region, service)
|
|
28
|
+
prefix = SERVICE_ENDPOINT_PREFIX_MAPPING[service]
|
|
29
|
+
raise "Service '#{service}' is not supported." unless prefix
|
|
30
|
+
format_endpoint(prefix, region)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Boolean] Returns true if the given string corresponds to a known region, as defined in
|
|
34
|
+
# {OCI::Regions::REGION_ENUM}.
|
|
35
|
+
def self.valid_region?(region)
|
|
36
|
+
REGION_ENUM.include? region
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.format_endpoint(prefix, region)
|
|
40
|
+
"https://#{prefix}.#{region}.oraclecloud.com"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/oci/response.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
module OCI
|
|
4
|
+
# A response, which represents all successful API calls.
|
|
5
|
+
class Response
|
|
6
|
+
# The HTTP status, such as 200, 401, etc
|
|
7
|
+
#
|
|
8
|
+
# @return [Integer]
|
|
9
|
+
attr_reader :status
|
|
10
|
+
|
|
11
|
+
# A ResponseHeaders object containing all response headers
|
|
12
|
+
#
|
|
13
|
+
# @return [ResponseHeaders]
|
|
14
|
+
attr_reader :headers
|
|
15
|
+
|
|
16
|
+
# The body of the response. For example, this
|
|
17
|
+
# may contain a User object, or a list of Users.
|
|
18
|
+
attr_reader :data
|
|
19
|
+
|
|
20
|
+
# The value of the next page token, if available,
|
|
21
|
+
# taken from the opc-next-page header.
|
|
22
|
+
#
|
|
23
|
+
# @return [String]
|
|
24
|
+
attr_reader :next_page
|
|
25
|
+
|
|
26
|
+
# The request ID, taken from the opc-request-id header.
|
|
27
|
+
#
|
|
28
|
+
# @return [String]
|
|
29
|
+
attr_reader :request_id
|
|
30
|
+
|
|
31
|
+
attr_writer :api_call
|
|
32
|
+
|
|
33
|
+
def initialize(status, headers, data)
|
|
34
|
+
@status = status
|
|
35
|
+
@headers = OCI::ResponseHeaders.new(headers)
|
|
36
|
+
@data = data
|
|
37
|
+
|
|
38
|
+
@next_page = @headers['opc-next-page'] if headers
|
|
39
|
+
@request_id = @headers['opc-request-id'] if headers
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Returns true if there is another page available.
|
|
43
|
+
def has_next_page?
|
|
44
|
+
!next_page.nil?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
include Enumerable
|
|
48
|
+
|
|
49
|
+
# For paged responses, yields each page until the last page is reached.
|
|
50
|
+
# For example:
|
|
51
|
+
#
|
|
52
|
+
# OCI::Identity::IdentityClient.new.list_users(compartment, limit:'3').each { |r| r.data.each { |user| puts user.name }}
|
|
53
|
+
#
|
|
54
|
+
# The first response yielded is always the response that 'each' is being
|
|
55
|
+
# called on.
|
|
56
|
+
#
|
|
57
|
+
# If any of the requests result in an error, that error will be thrown
|
|
58
|
+
# as normal, which will abort the enumeration.
|
|
59
|
+
#
|
|
60
|
+
# While this can be called on non-paged responses, it will simply result
|
|
61
|
+
# in the response itself being yielded.
|
|
62
|
+
#
|
|
63
|
+
# @yieldparam [Response] response A response object for each page, starting with the response used to call 'each'.
|
|
64
|
+
def each
|
|
65
|
+
yield self
|
|
66
|
+
page = @next_page
|
|
67
|
+
|
|
68
|
+
while @api_call && page
|
|
69
|
+
next_response = @api_call.call(page)
|
|
70
|
+
|
|
71
|
+
if page == next_response.next_page
|
|
72
|
+
raise 'Paging failure: Two consecutive responses had the same next page token.'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
page = next_response.next_page
|
|
76
|
+
yield next_response
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
module OCI
|
|
4
|
+
# A readonly, case-insensitive http response header collection
|
|
5
|
+
class ResponseHeaders
|
|
6
|
+
|
|
7
|
+
# Initialize the readonly and case-insensitive http response headers with hash object.
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] headers the hash object contains http response headers.
|
|
10
|
+
def initialize(headers)
|
|
11
|
+
@headers = {}
|
|
12
|
+
return if headers.nil?
|
|
13
|
+
headers.each do |key, value|
|
|
14
|
+
key = key.downcase if key.is_a? String
|
|
15
|
+
@headers[key] = value.is_a?(Array) && value.length == 1 ? value[0] : value
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Element Reference-Retrieves the value object corresponding to the key object.
|
|
20
|
+
# If not found, returns nil.
|
|
21
|
+
#
|
|
22
|
+
# @param [Object] key the key object. It is case-insensitive if it is a String object.
|
|
23
|
+
def [](key)
|
|
24
|
+
key = key.downcase if key.is_a? String
|
|
25
|
+
@headers[key] || nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Calls block once for each key in hsh, passing the key-value pair as parameters.
|
|
29
|
+
# If no block is given, an enumerator is returned instead.
|
|
30
|
+
#
|
|
31
|
+
# @param [Block] block the callback block
|
|
32
|
+
def each(&block)
|
|
33
|
+
@headers.each(&block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Calls block once for each key in hsh, passing the key as a parameter.
|
|
37
|
+
# If no block is given, an enumerator is returned instead.
|
|
38
|
+
#
|
|
39
|
+
# @param [Block] block the callback block
|
|
40
|
+
def each_key(&block)
|
|
41
|
+
@headers.each_key(&block)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Alias for: each
|
|
45
|
+
alias each_pair each
|
|
46
|
+
|
|
47
|
+
# Calls block once for each key in hsh, passing the value as a parameter.
|
|
48
|
+
# If no block is given, an enumerator is returned instead.
|
|
49
|
+
#
|
|
50
|
+
# @param [Block] block the callback block
|
|
51
|
+
def each_value(&block)
|
|
52
|
+
@headers.each_value(&block)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns true if hsh contains no key-value pairs.
|
|
56
|
+
def empty?
|
|
57
|
+
@headers.empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Returns true if hash and other are both hashes with the same content.
|
|
61
|
+
def eql?(other)
|
|
62
|
+
@headers.eql?(other)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns a value from the hash for the given key. If the key cannot be found, there are several options: With no
|
|
66
|
+
# other arguments, it will raise an KeyError exception; if default is given, then that will be returned; if the
|
|
67
|
+
# optional code block is specified, then that will be run and its result returned.
|
|
68
|
+
def fetch(key, *args, &block)
|
|
69
|
+
key = key.downcase if key.is_a? String
|
|
70
|
+
@headers.fetch(key, *args, &block)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Returns true if the given key is present in hsh.
|
|
74
|
+
#
|
|
75
|
+
# @param [Object] key to check. It is case-insensitive if it is a String object.
|
|
76
|
+
def key?(key)
|
|
77
|
+
key = key.downcase if key.is_a? String
|
|
78
|
+
@headers.key?(key)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Alias for: key?
|
|
82
|
+
alias has_key? key?
|
|
83
|
+
|
|
84
|
+
# Returns true if the given value is present for some key in hsh.
|
|
85
|
+
#
|
|
86
|
+
# @param [Object] value to check.
|
|
87
|
+
def value?(value)
|
|
88
|
+
@headers.value?(value)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Alias for: value?
|
|
92
|
+
alias has_value? value?
|
|
93
|
+
|
|
94
|
+
# Compute a hash-code for this hash. Two hashes with the same content will have the same hash code
|
|
95
|
+
# (and will compare using eql?).
|
|
96
|
+
def hash
|
|
97
|
+
@headers.hash
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Alias for: key?
|
|
101
|
+
alias include? key?
|
|
102
|
+
|
|
103
|
+
# Return the contents of this hash as a string.
|
|
104
|
+
def to_s
|
|
105
|
+
@headers.to_s
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Alias for: to_s
|
|
109
|
+
alias inspect to_s
|
|
110
|
+
|
|
111
|
+
# Returns the key of an occurrence of a given value. If the value is not found, returns nil.
|
|
112
|
+
#
|
|
113
|
+
# @param [Object] value to check.
|
|
114
|
+
def key(value)
|
|
115
|
+
@headers.key(value)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Returns a new array populated with the keys from this hash.
|
|
119
|
+
def keys
|
|
120
|
+
@headers.keys
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Returns the number of key-value pairs in the hash.
|
|
124
|
+
def size
|
|
125
|
+
@headers.size
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Alias for: size
|
|
129
|
+
alias length size
|
|
130
|
+
|
|
131
|
+
# Alias for: key?
|
|
132
|
+
alias member? key?
|
|
133
|
+
|
|
134
|
+
# Returns the hash object.
|
|
135
|
+
def to_hash
|
|
136
|
+
@headers
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Returns a new array populated with the values from hsh.
|
|
140
|
+
def values
|
|
141
|
+
@headers.values
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
data/lib/oci/signer.rb
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'digest'
|
|
5
|
+
require 'openssl'
|
|
6
|
+
require 'securerandom'
|
|
7
|
+
require 'time'
|
|
8
|
+
require 'uri'
|
|
9
|
+
require 'cgi'
|
|
10
|
+
|
|
11
|
+
module OCI
|
|
12
|
+
|
|
13
|
+
# Used to sign HTTP requests as required by Oracle Cloud Infrastructure.
|
|
14
|
+
class Signer
|
|
15
|
+
# enum to define the signing strategy
|
|
16
|
+
SIGNING_STRATEGY_ENUM = [STANDARD = 'standard', OBJECT_STORAGE = 'object_storage']
|
|
17
|
+
|
|
18
|
+
# The Oracle Cloud Infrastructure API signature version
|
|
19
|
+
SIGNATURE_VERSION = "1"
|
|
20
|
+
|
|
21
|
+
# Creates a Signer
|
|
22
|
+
#
|
|
23
|
+
# @param [String] user OCID of the user to be used for authentication, for example "ocidv1:user:oc1:phx:1460406592659:aaaaaaaawcbqrkycbolrirg2n3xjl5fyxe".
|
|
24
|
+
# @param [String] fingerprint Fingerprint of the key used for authentication, for example "20:3b:97:13:55:1c:5b:0d:d3:37:d8:50:4e:c5:3a:34"
|
|
25
|
+
# @param [String] tenancy OCID of the tenancy
|
|
26
|
+
# @param [String] private_key_file It can be nil if private_key_content is provided. Full path and filename of the unencrypted PEM file, for example "/Users/bgustafs/.ssh/id_rsa.pem"
|
|
27
|
+
# @param [String] pass_phrase Optional pass phrase used to encrypt the private key
|
|
28
|
+
# @param [String] private_key_content Optional if private_key_file is provided. The value should be the content of the unencrypted PEM file.
|
|
29
|
+
# @param [SIGNING_STRATEGY_ENUM] signing_strategy Optional signing for standard service or object storage service
|
|
30
|
+
def initialize(user, fingerprint, tenancy, private_key_file, pass_phrase:nil, private_key_content:nil, signing_strategy:STANDARD)
|
|
31
|
+
fail 'Missing required parameter user.' unless user
|
|
32
|
+
fail 'Missing required parameter fingerprint.' unless fingerprint
|
|
33
|
+
fail 'Missing required parameter tenancy.' unless tenancy
|
|
34
|
+
fail 'Missing required parameter private_key_file or private_key_content.' unless private_key_file || private_key_content
|
|
35
|
+
|
|
36
|
+
@key_id = tenancy + "/" + user + "/" + fingerprint
|
|
37
|
+
@private_key_file = private_key_file
|
|
38
|
+
@private_key_content = private_key_content
|
|
39
|
+
@pass_phrase = pass_phrase
|
|
40
|
+
@signing_strategy = signing_strategy
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Generates the correct signature and adds it to the
|
|
44
|
+
# headers that are passed in. Also injects any required
|
|
45
|
+
# headers that might be missing.
|
|
46
|
+
#
|
|
47
|
+
# @param [Symbol] method The HTTP method, such as :get or :post.
|
|
48
|
+
# @param [String] uri The URI, such as 'https://iaas.us-phoenix-1.oraclecloud.com/20160918/volumeAttachments/'
|
|
49
|
+
# @param [Hash] headers A hash of headers
|
|
50
|
+
# @param [String] body The request body
|
|
51
|
+
def sign(method, uri, headers, body)
|
|
52
|
+
method = method.to_sym.downcase
|
|
53
|
+
uri = URI(uri)
|
|
54
|
+
path = uri.query.nil? ? uri.path : "#{uri.path}?#{uri.query}"
|
|
55
|
+
inject_missing_headers(method, headers, body, uri)
|
|
56
|
+
signature = compute_signature(headers, method, path)
|
|
57
|
+
unless signature.nil?
|
|
58
|
+
inject_authorization_header(headers, method, signature)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
GENERIC_HEADERS = [:"date", :"(request-target)", :"host"]
|
|
65
|
+
BODY_HEADERS = [:"content-length", :"content-type", :"x-content-sha256"]
|
|
66
|
+
|
|
67
|
+
OPERATION_HEADER_MAPPING = {
|
|
68
|
+
options: [],
|
|
69
|
+
get: GENERIC_HEADERS,
|
|
70
|
+
head: GENERIC_HEADERS,
|
|
71
|
+
delete: GENERIC_HEADERS,
|
|
72
|
+
put: GENERIC_HEADERS + BODY_HEADERS,
|
|
73
|
+
post: GENERIC_HEADERS + BODY_HEADERS
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
def inject_missing_headers(method, headers, body, uri)
|
|
77
|
+
|
|
78
|
+
headers["date"] ||= Time.now.utc.httpdate
|
|
79
|
+
headers["accept"] ||= "*/*"
|
|
80
|
+
headers["host"] ||= uri.host
|
|
81
|
+
|
|
82
|
+
# For object storage service's put method, we don't need to set content type
|
|
83
|
+
if method != :put || @signing_strategy != OBJECT_STORAGE
|
|
84
|
+
headers["content-type"] ||= "application/json"
|
|
85
|
+
else
|
|
86
|
+
headers[:'Content-Type'] ||= 'application/octet-stream'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
if method == :put || method == :post
|
|
90
|
+
body ||= ''
|
|
91
|
+
|
|
92
|
+
# For object storage service's put method, we don't need to set content length and x-content sha256
|
|
93
|
+
if method != :put || @signing_strategy != OBJECT_STORAGE
|
|
94
|
+
headers["content-length"] ||= body.length.to_s
|
|
95
|
+
headers["x-content-sha256"] ||= Digest::SHA256.base64digest(body)
|
|
96
|
+
else
|
|
97
|
+
if body.respond_to?(:read) && body.respond_to?(:write)
|
|
98
|
+
headers['Content-Length'] ||= body.respond_to?('size') ? body.size : body.stat.size
|
|
99
|
+
else
|
|
100
|
+
headers['Content-Length'] ||= body.length.to_s
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def inject_authorization_header(headers, method, signature)
|
|
107
|
+
|
|
108
|
+
if method == :put && @signing_strategy == OBJECT_STORAGE
|
|
109
|
+
header_mapping = GENERIC_HEADERS
|
|
110
|
+
else
|
|
111
|
+
header_mapping = OPERATION_HEADER_MAPPING[method]
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
signed_headers = header_mapping.map(&:to_s).join(" ")
|
|
115
|
+
headers["authorization"] = [
|
|
116
|
+
%(Signature headers="#{signed_headers}"),
|
|
117
|
+
%(keyId="#{@key_id}"),
|
|
118
|
+
%(algorithm="rsa-sha256"),
|
|
119
|
+
%(signature="#{signature}"),
|
|
120
|
+
%(version="#{SIGNATURE_VERSION}")
|
|
121
|
+
].join(",")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def compute_signature(headers, method, path)
|
|
125
|
+
if method == :put && @signing_strategy == OBJECT_STORAGE
|
|
126
|
+
header_mapping = GENERIC_HEADERS
|
|
127
|
+
else
|
|
128
|
+
header_mapping = OPERATION_HEADER_MAPPING[method]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
return if header_mapping.empty?
|
|
132
|
+
signing_string = header_mapping.map do |header|
|
|
133
|
+
if header == :"(request-target)"
|
|
134
|
+
"#{header}: #{method.downcase} #{path}"
|
|
135
|
+
else
|
|
136
|
+
"#{header}: #{headers[header.to_s]}"
|
|
137
|
+
end
|
|
138
|
+
end.join("\n")
|
|
139
|
+
|
|
140
|
+
signature = private_key.sign(OpenSSL::Digest::SHA256.new, signing_string.encode("ascii"))
|
|
141
|
+
Base64.strict_encode64(signature)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def private_key
|
|
145
|
+
# If a pass_phase was not provided and the key is in fact encrypted, then passing in
|
|
146
|
+
# nil for the passphrase here will show a user prompt and block until there is a response.
|
|
147
|
+
# Passing in an empty string will work for some versions of Ruby's openssl wrapper, but
|
|
148
|
+
# other versions will enforce the 4 character password minimum at this point. Passing in
|
|
149
|
+
# a dummy password that's greater than 4 characters avoids both problems, and will
|
|
150
|
+
# always succeed if the file is not encrypted.
|
|
151
|
+
@private_key ||= OpenSSL::PKey::RSA.new(
|
|
152
|
+
@private_key_content.nil? ? File.read(@private_key_file) : @private_key_content,
|
|
153
|
+
@pass_phrase || SecureRandom.uuid)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
data/lib/oci/version.rb
ADDED
data/lib/oci/waiter.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
2
|
+
|
|
3
|
+
module OCI
|
|
4
|
+
module Waiter
|
|
5
|
+
module Errors
|
|
6
|
+
# Raised when a call to wait_until reaches the maximum wait time.
|
|
7
|
+
class MaximumWaitTimeExceededError < RuntimeError; end
|
|
8
|
+
|
|
9
|
+
# Raised when wait_until is called on a response that does not
|
|
10
|
+
# support waiters. Typically, waiters are only supported for
|
|
11
|
+
# get operations.
|
|
12
|
+
class WaitUntilNotSupportedError < RuntimeError; end
|
|
13
|
+
|
|
14
|
+
# If thrown from the yield statement of a waiter, it will cause the
|
|
15
|
+
# waiter to fail with this exception.
|
|
16
|
+
class WaiterFailedError < RuntimeError; end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Adds to the Response class in lib/oci/response.rb to define wait behavior
|
|
21
|
+
class Response
|
|
22
|
+
# Wait until the value of the given property in the response data has
|
|
23
|
+
# the given value. This will block the current thread until the
|
|
24
|
+
# the desired state is reached, the maximum wait time is reached, or the
|
|
25
|
+
# optional yield block throws :stop_succeed or :stop_fail. This is only
|
|
26
|
+
# supported for responses resulting from GET operations. A typical use
|
|
27
|
+
# case is to wait on an instance until it is in a running state:
|
|
28
|
+
#
|
|
29
|
+
# compute_client.get_instance(@instance_id).wait_until(:lifecycle_state, OCI::Core::Models::Instance::LIFECYCLE_STATE_RUNNING)
|
|
30
|
+
#
|
|
31
|
+
# Although this can be run on any property of the data resulting from any
|
|
32
|
+
# GET operation, the most common use case is to check state properties on
|
|
33
|
+
# operations that GET a single object.
|
|
34
|
+
#
|
|
35
|
+
# The wait will poll at an increasing interval up to 'max_interval_seconds'
|
|
36
|
+
# for a maximum total time of 'max_wait_seconds'. If the maximum time
|
|
37
|
+
# is exceeded, then it will raise a {OCI::Waiter::Errors::MaximumWaitTimeExceededError}.
|
|
38
|
+
#
|
|
39
|
+
# On successful completion the final Response object will be returned. The
|
|
40
|
+
# original Response object will not be altered.
|
|
41
|
+
#
|
|
42
|
+
# If any responses result in an error, then the error will be thrown as normal
|
|
43
|
+
# resulting in the wait being aborted.
|
|
44
|
+
#
|
|
45
|
+
# @param [Symbol] property The property of the response data to evaluate. For example, :lifecycle_state.
|
|
46
|
+
# @param state The value of the property that will indicate successful completion of the wait.
|
|
47
|
+
# @param [Integer] max_interval_seconds The maximum interval between queries, in seconds.
|
|
48
|
+
# @param [Integer] max_wait_seconds The maximum time to wait, in seconds.
|
|
49
|
+
# @yieldparam [Response] response A response object for every additional successful call to the get request.
|
|
50
|
+
# Throw :stop_succeed from the yield to stop the waiter and return the current response.
|
|
51
|
+
# Throw :stop_fail from the yield to stop the waiter and throw a WaiterFailedError.
|
|
52
|
+
# @return [Response] The final response, which will contain the property in the specified state.
|
|
53
|
+
def wait_until(property, state, max_interval_seconds: 30, max_wait_seconds: 1200)
|
|
54
|
+
raise 'Cannot wait on a response without data.' unless data
|
|
55
|
+
raise 'Response data does not contain the given property.' unless data.methods.include? property
|
|
56
|
+
|
|
57
|
+
raise Waiter::Errors::WaitUntilNotSupportedError, 'wait_until is not supported by this response.' unless @api_call
|
|
58
|
+
|
|
59
|
+
response = self
|
|
60
|
+
interval_seconds = 1
|
|
61
|
+
start_time = Time.now
|
|
62
|
+
|
|
63
|
+
loop do
|
|
64
|
+
return response if response.data.send(property) == state
|
|
65
|
+
|
|
66
|
+
elapsed_seconds = (Time.now - start_time).to_i
|
|
67
|
+
|
|
68
|
+
if elapsed_seconds + interval_seconds > max_wait_seconds
|
|
69
|
+
raise Waiter::Errors::MaximumWaitTimeExceededError, 'Maximum wait time has been exceeded.' \
|
|
70
|
+
unless max_wait_seconds > elapsed_seconds
|
|
71
|
+
|
|
72
|
+
# Make one last request right at the maximum wait time.
|
|
73
|
+
interval_seconds = max_wait_seconds - elapsed_seconds
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
sleep(interval_seconds)
|
|
77
|
+
|
|
78
|
+
interval_seconds *= 2
|
|
79
|
+
if interval_seconds > max_interval_seconds
|
|
80
|
+
interval_seconds = max_interval_seconds
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
response = @api_call.call(nil)
|
|
84
|
+
|
|
85
|
+
next unless block_given?
|
|
86
|
+
|
|
87
|
+
continue = false
|
|
88
|
+
catch(:stop_fail) do
|
|
89
|
+
catch(:stop_succeed) do
|
|
90
|
+
yield response
|
|
91
|
+
continue = true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
return response unless continue
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
raise Waiter::Errors::WaiterFailedError unless continue
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|