aws-sdk 1.1.3 → 1.1.4

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.
Files changed (233) hide show
  1. data/ca-bundle.crt +2 -348
  2. data/lib/aws.rb +24 -49
  3. data/lib/aws/{common.rb → core.rb} +120 -9
  4. data/lib/aws/{api_config.rb → core/api_config.rb} +19 -20
  5. data/lib/aws/core/api_config_transform.rb +36 -0
  6. data/lib/aws/core/async_handle.rb +91 -0
  7. data/lib/aws/core/authorize_v2.rb +39 -0
  8. data/lib/aws/{authorize_v3.rb → core/authorize_v3.rb} +16 -15
  9. data/lib/aws/{api_config_transform.rb → core/authorize_with_session_token.rb} +9 -12
  10. data/lib/aws/core/autoloader.rb +64 -0
  11. data/lib/aws/core/cacheable.rb +78 -0
  12. data/lib/aws/core/client.rb +471 -0
  13. data/lib/aws/core/client_logging.rb +125 -0
  14. data/lib/aws/core/collections.rb +229 -0
  15. data/lib/aws/core/configuration.rb +358 -0
  16. data/lib/aws/core/configured_client_methods.rb +76 -0
  17. data/lib/aws/core/configured_grammars.rb +63 -0
  18. data/lib/aws/{configured_option_grammars.rb → core/configured_option_grammars.rb} +18 -20
  19. data/lib/aws/{configured_xml_grammars.rb → core/configured_xml_grammars.rb} +19 -21
  20. data/lib/aws/core/default_signer.rb +67 -0
  21. data/lib/aws/core/http/curb_handler.rb +129 -0
  22. data/lib/aws/core/http/handler.rb +77 -0
  23. data/lib/aws/core/http/httparty_handler.rb +113 -0
  24. data/lib/aws/core/http/net_http_handler.rb +124 -0
  25. data/lib/aws/core/http/request.rb +207 -0
  26. data/lib/aws/core/http/response.rb +73 -0
  27. data/lib/aws/{ignore_result_element.rb → core/ignore_result_element.rb} +14 -18
  28. data/lib/aws/core/indifferent_hash.rb +88 -0
  29. data/lib/aws/core/inflection.rb +47 -0
  30. data/lib/aws/core/lazy_error_classes.rb +62 -0
  31. data/lib/aws/{uri_escape.rb → core/meta_utils.rb} +24 -23
  32. data/lib/aws/core/model.rb +57 -0
  33. data/lib/aws/{authorize_with_session_token.rb → core/naming.rb} +9 -8
  34. data/lib/aws/core/option_grammar.rb +562 -0
  35. data/lib/aws/core/policy.rb +914 -0
  36. data/lib/aws/core/resource.rb +380 -0
  37. data/lib/aws/core/resource_cache.rb +40 -0
  38. data/lib/aws/core/response.rb +125 -0
  39. data/lib/aws/core/response_cache.rb +50 -0
  40. data/lib/aws/core/service_interface.rb +60 -0
  41. data/lib/aws/core/uri_escape.rb +46 -0
  42. data/lib/aws/core/xml_grammar.rb +926 -0
  43. data/lib/aws/ec2.rb +47 -16
  44. data/lib/aws/ec2/attachment.rb +0 -2
  45. data/lib/aws/ec2/attachment_collection.rb +1 -6
  46. data/lib/aws/ec2/availability_zone.rb +0 -2
  47. data/lib/aws/ec2/availability_zone_collection.rb +0 -3
  48. data/lib/aws/ec2/client.rb +6 -9
  49. data/lib/aws/ec2/client/xml.rb +3 -6
  50. data/lib/aws/ec2/collection.rb +1 -4
  51. data/lib/aws/ec2/config.rb +18 -0
  52. data/lib/aws/ec2/elastic_ip.rb +0 -2
  53. data/lib/aws/ec2/elastic_ip_collection.rb +0 -4
  54. data/lib/aws/ec2/errors.rb +1 -4
  55. data/lib/aws/ec2/has_permissions.rb +0 -2
  56. data/lib/aws/ec2/image.rb +0 -5
  57. data/lib/aws/ec2/image_collection.rb +0 -6
  58. data/lib/aws/ec2/instance.rb +23 -9
  59. data/lib/aws/ec2/instance_collection.rb +85 -22
  60. data/lib/aws/ec2/key_pair.rb +0 -2
  61. data/lib/aws/ec2/key_pair_collection.rb +1 -4
  62. data/lib/aws/ec2/permission_collection.rb +2 -5
  63. data/lib/aws/ec2/region.rb +0 -2
  64. data/lib/aws/ec2/region_collection.rb +0 -4
  65. data/lib/aws/ec2/request.rb +4 -9
  66. data/lib/aws/ec2/reserved_instances.rb +0 -3
  67. data/lib/aws/ec2/reserved_instances_collection.rb +0 -4
  68. data/lib/aws/ec2/reserved_instances_offering.rb +0 -3
  69. data/lib/aws/ec2/reserved_instances_offering_collection.rb +0 -4
  70. data/lib/aws/ec2/resource.rb +3 -5
  71. data/lib/aws/ec2/resource_tag_collection.rb +1 -6
  72. data/lib/aws/ec2/security_group.rb +204 -72
  73. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +53 -0
  74. data/lib/aws/ec2/security_group/ip_permission.rb +92 -10
  75. data/lib/aws/ec2/security_group/ip_permission_collection.rb +14 -15
  76. data/lib/aws/ec2/security_group_collection.rb +11 -8
  77. data/lib/aws/ec2/snapshot.rb +0 -4
  78. data/lib/aws/ec2/snapshot_collection.rb +0 -4
  79. data/lib/aws/ec2/tag.rb +0 -3
  80. data/lib/aws/ec2/tag_collection.rb +1 -8
  81. data/lib/aws/ec2/tagged_item.rb +1 -3
  82. data/lib/aws/ec2/volume.rb +0 -6
  83. data/lib/aws/ec2/volume_collection.rb +0 -4
  84. data/lib/aws/errors.rb +0 -3
  85. data/lib/aws/iam.rb +33 -12
  86. data/lib/aws/iam/access_key.rb +0 -3
  87. data/lib/aws/iam/access_key_collection.rb +0 -3
  88. data/lib/aws/iam/account_alias_collection.rb +0 -2
  89. data/lib/aws/iam/client.rb +6 -8
  90. data/lib/aws/iam/client/xml.rb +4 -8
  91. data/lib/aws/iam/collection.rb +2 -5
  92. data/lib/aws/iam/config.rb +18 -0
  93. data/lib/aws/iam/errors.rb +2 -4
  94. data/lib/aws/iam/group.rb +0 -5
  95. data/lib/aws/iam/group_collection.rb +0 -3
  96. data/lib/aws/iam/group_policy_collection.rb +0 -2
  97. data/lib/aws/iam/group_user_collection.rb +1 -4
  98. data/lib/aws/iam/login_profile.rb +0 -2
  99. data/lib/aws/iam/mfa_device.rb +1 -3
  100. data/lib/aws/iam/mfa_device_collection.rb +0 -3
  101. data/lib/aws/iam/policy.rb +2 -4
  102. data/lib/aws/iam/policy_collection.rb +0 -3
  103. data/lib/aws/iam/request.rb +3 -7
  104. data/lib/aws/iam/resource.rb +1 -4
  105. data/lib/aws/iam/server_certificate.rb +0 -2
  106. data/lib/aws/iam/server_certificate_collection.rb +0 -3
  107. data/lib/aws/iam/signing_certificate.rb +0 -2
  108. data/lib/aws/iam/signing_certificate_collection.rb +0 -3
  109. data/lib/aws/iam/user.rb +0 -7
  110. data/lib/aws/iam/user_collection.rb +0 -3
  111. data/lib/aws/iam/user_group_collection.rb +0 -3
  112. data/lib/aws/iam/user_policy.rb +0 -2
  113. data/lib/aws/iam/user_policy_collection.rb +0 -3
  114. data/lib/aws/rails.rb +5 -4
  115. data/lib/aws/record.rb +4 -1
  116. data/lib/aws/record/base.rb +3 -2
  117. data/lib/aws/record/errors.rb +1 -3
  118. data/lib/aws/s3.rb +31 -6
  119. data/lib/aws/s3/access_control_list.rb +0 -2
  120. data/lib/aws/s3/acl_object.rb +10 -12
  121. data/lib/aws/s3/bucket.rb +1 -9
  122. data/lib/aws/s3/bucket_collection.rb +2 -5
  123. data/lib/aws/s3/bucket_version_collection.rb +1 -5
  124. data/lib/aws/s3/client.rb +34 -37
  125. data/lib/aws/s3/client/xml.rb +11 -14
  126. data/lib/aws/{resource_cache.rb → s3/config.rb} +6 -20
  127. data/lib/aws/s3/errors.rb +6 -7
  128. data/lib/aws/s3/multipart_upload.rb +1 -4
  129. data/lib/aws/s3/multipart_upload_collection.rb +1 -6
  130. data/lib/aws/s3/object_collection.rb +1 -5
  131. data/lib/aws/s3/object_metadata.rb +1 -3
  132. data/lib/aws/s3/object_upload_collection.rb +1 -7
  133. data/lib/aws/s3/object_version.rb +1 -4
  134. data/lib/aws/s3/object_version_collection.rb +1 -4
  135. data/lib/aws/s3/policy.rb +3 -5
  136. data/lib/aws/s3/prefix_and_delimiter_collection.rb +0 -2
  137. data/lib/aws/s3/prefixed_collection.rb +0 -2
  138. data/lib/aws/s3/presigned_post.rb +1 -3
  139. data/lib/aws/s3/request.rb +2 -5
  140. data/lib/aws/s3/s3_object.rb +1 -8
  141. data/lib/aws/s3/tree.rb +8 -6
  142. data/lib/aws/s3/tree/branch_node.rb +0 -3
  143. data/lib/aws/s3/tree/child_collection.rb +1 -5
  144. data/lib/aws/s3/tree/leaf_node.rb +0 -5
  145. data/lib/aws/s3/tree/parent.rb +1 -4
  146. data/lib/aws/s3/uploaded_part.rb +1 -3
  147. data/lib/aws/s3/uploaded_part_collection.rb +1 -5
  148. data/lib/aws/simple_db.rb +21 -6
  149. data/lib/aws/simple_db/attribute.rb +1 -6
  150. data/lib/aws/simple_db/attribute_collection.rb +1 -7
  151. data/lib/aws/simple_db/client.rb +7 -9
  152. data/lib/aws/simple_db/client/options.rb +2 -4
  153. data/lib/aws/simple_db/client/xml.rb +5 -10
  154. data/lib/aws/{naming.rb → simple_db/config.rb} +3 -14
  155. data/lib/aws/simple_db/delete_attributes.rb +0 -2
  156. data/lib/aws/simple_db/domain.rb +1 -6
  157. data/lib/aws/simple_db/domain_collection.rb +1 -4
  158. data/lib/aws/simple_db/domain_metadata.rb +1 -3
  159. data/lib/aws/simple_db/errors.rb +1 -4
  160. data/lib/aws/simple_db/item.rb +1 -7
  161. data/lib/aws/simple_db/item_collection.rb +22 -23
  162. data/lib/aws/simple_db/put_attributes.rb +0 -2
  163. data/lib/aws/simple_db/request.rb +3 -7
  164. data/lib/aws/simple_email_service.rb +11 -6
  165. data/lib/aws/simple_email_service/client.rb +7 -9
  166. data/lib/aws/simple_email_service/client/options.rb +3 -6
  167. data/lib/aws/simple_email_service/client/xml.rb +4 -8
  168. data/lib/aws/simple_email_service/config.rb +19 -0
  169. data/lib/aws/simple_email_service/email_address_collection.rb +1 -3
  170. data/lib/aws/simple_email_service/errors.rb +1 -4
  171. data/lib/aws/simple_email_service/quotas.rb +1 -3
  172. data/lib/aws/simple_email_service/request.rb +3 -7
  173. data/lib/aws/sns.rb +15 -8
  174. data/lib/aws/sns/client.rb +7 -8
  175. data/lib/aws/sns/client/options.rb +3 -6
  176. data/lib/aws/sns/client/xml.rb +4 -8
  177. data/lib/aws/sns/config.rb +18 -0
  178. data/lib/aws/sns/errors.rb +1 -4
  179. data/lib/aws/sns/policy.rb +3 -5
  180. data/lib/aws/sns/request.rb +4 -9
  181. data/lib/aws/sns/subscription.rb +1 -5
  182. data/lib/aws/sns/subscription_collection.rb +1 -5
  183. data/lib/aws/sns/topic.rb +1 -6
  184. data/lib/aws/sns/topic_collection.rb +1 -4
  185. data/lib/aws/sns/topic_subscription_collection.rb +1 -4
  186. data/lib/aws/sqs.rb +14 -5
  187. data/lib/aws/sqs/client.rb +6 -9
  188. data/lib/aws/sqs/client/xml.rb +4 -7
  189. data/lib/aws/sqs/config.rb +18 -0
  190. data/lib/aws/sqs/errors.rb +1 -4
  191. data/lib/aws/sqs/policy.rb +3 -5
  192. data/lib/aws/sqs/queue.rb +2 -7
  193. data/lib/aws/sqs/queue_collection.rb +4 -5
  194. data/lib/aws/sqs/received_message.rb +1 -3
  195. data/lib/aws/sqs/received_sns_message.rb +2 -2
  196. data/lib/aws/sqs/request.rb +4 -7
  197. data/lib/aws/sts.rb +12 -6
  198. data/lib/aws/sts/client.rb +6 -8
  199. data/lib/aws/sts/client/xml.rb +4 -8
  200. data/lib/aws/sts/config.rb +18 -0
  201. data/lib/aws/sts/errors.rb +1 -4
  202. data/lib/aws/sts/federated_session.rb +0 -2
  203. data/lib/aws/sts/policy.rb +3 -5
  204. data/lib/aws/sts/request.rb +3 -7
  205. metadata +60 -50
  206. data/lib/aws/async_handle.rb +0 -90
  207. data/lib/aws/authorize_v2.rb +0 -37
  208. data/lib/aws/base_client.rb +0 -488
  209. data/lib/aws/cacheable.rb +0 -79
  210. data/lib/aws/client_logging.rb +0 -122
  211. data/lib/aws/collections.rb +0 -230
  212. data/lib/aws/configuration.rb +0 -357
  213. data/lib/aws/configured_client_methods.rb +0 -81
  214. data/lib/aws/configured_grammars.rb +0 -65
  215. data/lib/aws/default_signer.rb +0 -65
  216. data/lib/aws/http/curb_handler.rb +0 -127
  217. data/lib/aws/http/handler.rb +0 -77
  218. data/lib/aws/http/httparty_handler.rb +0 -103
  219. data/lib/aws/http/request.rb +0 -165
  220. data/lib/aws/http/request_param.rb +0 -64
  221. data/lib/aws/http/response.rb +0 -72
  222. data/lib/aws/indifferent_hash.rb +0 -86
  223. data/lib/aws/inflection.rb +0 -46
  224. data/lib/aws/lazy_error_classes.rb +0 -64
  225. data/lib/aws/meta_utils.rb +0 -43
  226. data/lib/aws/model.rb +0 -57
  227. data/lib/aws/option_grammar.rb +0 -565
  228. data/lib/aws/policy.rb +0 -914
  229. data/lib/aws/resource.rb +0 -381
  230. data/lib/aws/response.rb +0 -125
  231. data/lib/aws/response_cache.rb +0 -50
  232. data/lib/aws/service_interface.rb +0 -60
  233. data/lib/aws/xml_grammar.rb +0 -925
@@ -1,81 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'aws/api_config'
15
- require 'aws/inflection'
16
- require 'aws/configured_xml_grammars'
17
- require 'aws/configured_option_grammars'
18
-
19
- module AWS
20
-
21
- # @private
22
- module ConfiguredClientMethods
23
-
24
- # @private
25
- module ClassMethods
26
-
27
- include ApiConfig
28
-
29
- def configure_client
30
-
31
- super
32
-
33
- unless self::XML.include?(ConfiguredXmlGrammars)
34
- self::XML.module_eval do
35
- include(ConfiguredXmlGrammars)
36
- define_configured_grammars
37
- end
38
- end
39
-
40
- unless self::Options.include?(ConfiguredOptionGrammars)
41
- self::Options.module_eval do
42
- include(ConfiguredOptionGrammars)
43
- define_configured_grammars
44
- end
45
- end
46
-
47
- api_config[:operations].each do |name, customizations|
48
- option_grammar = self::Options.operation_grammar(name)
49
- add_client_request_method(Inflection.ruby_name(name).to_sym,
50
- :xml_grammar =>
51
- self::XML.operation_grammar(name)) do
52
- configure_request do |request, options|
53
- request.add_param("Action", name)
54
- option_grammar.request_params(options).each do |param|
55
- request.add_param(param)
56
- end
57
- end
58
- end
59
- end
60
-
61
- end
62
-
63
- def operation_xml_grammar(name)
64
- customized_name = "Customized#{name}"
65
- if self::XML.const_defined?(customized_name)
66
- self::XML.const_get(customized_name)
67
- else
68
- self::XML.const_get(name)
69
- end
70
- end
71
-
72
- end
73
-
74
- def self.included(mod)
75
- mod.extend(ClassMethods)
76
- end
77
-
78
- end
79
-
80
- end
81
-
@@ -1,65 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'aws/api_config'
15
- require 'aws/xml_grammar'
16
-
17
- module AWS
18
-
19
- # @private
20
- module ConfiguredGrammars
21
-
22
- # @private
23
- module ClassMethods
24
-
25
- include ApiConfig
26
-
27
- def base_grammar
28
- raise NotImplementedError
29
- end
30
-
31
- def operation_grammar(name)
32
- customized_name = "Customized#{name}"
33
- if const_defined?(customized_name)
34
- const_get(customized_name)
35
- else
36
- const_get(name)
37
- end
38
- end
39
-
40
- def input_or_output
41
- raise NotImplementedError
42
- end
43
-
44
- def process_customizations(name, customizations)
45
- customizations
46
- end
47
-
48
- def define_configured_grammars
49
- api_config[:operations].each do |name, data|
50
- customizations = process_customizations(name,
51
- data[input_or_output])
52
- const_set(name,
53
- base_grammar.customize(customizations))
54
- # BaseResponse.customize([{
55
- # "#{name}Result" =>
56
- # [:ignore, *data[:output]]
57
- # }]))
58
- end
59
- end
60
-
61
- end
62
-
63
- end
64
-
65
- end
@@ -1,65 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'base64'
15
- require 'openssl'
16
-
17
- module AWS
18
-
19
- # Computes signatures using credentials that are stored in memory.
20
- class DefaultSigner
21
-
22
- # @return [String] The Access Key ID used to sign requests.
23
- attr_reader :access_key_id
24
-
25
- # @return [String] The Secret Access Key used to sign requests.
26
- attr_reader :secret_access_key
27
-
28
- # @return [String] The Session Token used to sign requests.
29
- attr_reader :session_token
30
-
31
- # @param [String] access_key_id The Access Key ID used to sign
32
- # requests.
33
- #
34
- # @param [String] secret_access_key The Secret Access Key used to
35
- # sign requests.
36
- #
37
- # @param [String] session_token The Session Token used to sign
38
- # requests. You can get credentials that include a session
39
- # token using the {STS} class.
40
- def initialize(access_key_id, secret_access_key, session_token = nil)
41
-
42
- @access_key_id = access_key_id
43
- @secret_access_key = secret_access_key
44
- @session_token = session_token
45
-
46
- raise "Missing credentials" unless access_key_id and secret_access_key
47
-
48
- end
49
-
50
- # Signs a string using the credentials stored in memory.
51
- #
52
- # @param [String] string_to_sign The string to sign.
53
- #
54
- # @param [String] digest_method The digest method to use when
55
- # computing the HMAC digest.
56
- def sign(string_to_sign, digest_method = 'sha256')
57
- Base64.encode64(
58
- OpenSSL::HMAC.digest(
59
- OpenSSL::Digest::Digest.new(digest_method),
60
- secret_access_key,
61
- string_to_sign)).strip
62
- end
63
-
64
- end
65
- end
@@ -1,127 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'thread'
15
-
16
- module AWS
17
- module Http
18
-
19
- # @private
20
- class CurbHandler
21
-
22
- def initialize
23
- @q = []
24
- @sem = Mutex.new
25
- @multi = Curl::Multi.new
26
-
27
- start_processor
28
- end
29
-
30
- def handle request, response
31
- raise "unsupport http reqest method: #{request.http_method}" unless
32
- ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'].include? request.http_method
33
- @sem.synchronize do
34
- @q << [request, response, Thread.current]
35
- @processor.wakeup
36
- end
37
- Thread.stop
38
- nil
39
- end
40
-
41
- # fills the Curl::Multi handle with the given array of queue
42
- # items, calling make_easy_handle on each one first
43
- private
44
- def fill_multi(items)
45
- items.each do |item|
46
- c = make_easy_handle(*item)
47
- @multi.add(c)
48
- end
49
- end
50
-
51
- # starts a background thread that waits for new items and
52
- # sends them through the Curl::Multi handle
53
- private
54
- def start_processor
55
- @processor = Thread.new do
56
- loop do
57
- items = nil
58
- @sem.synchronize do
59
- items = @q.slice!(0..-1)
60
- end
61
- unless items.empty?
62
- fill_multi(items)
63
- @multi.perform do
64
- # curl is idle, so process more items if we can get them
65
- # without blocking
66
- if !@q.empty? && @sem.try_lock
67
- begin
68
- fill_multi(@q.slice!(0..-1))
69
- ensure
70
- @sem.unlock
71
- end
72
- end
73
- end
74
- end
75
-
76
- # wait for a new item to show up before continuing
77
- Thread.stop if @q.empty?
78
- end
79
- end
80
- end
81
-
82
- private
83
- def make_easy_handle request, response, thread = nil
84
-
85
- url = request.use_ssl? ?
86
- "https://#{request.host}:443#{request.uri}" :
87
- "http://#{request.host}#{request.uri}"
88
-
89
- curl = Curl::Easy.new(url)
90
- curl.headers = request.headers
91
-
92
- if proxy = request.proxy_uri
93
- curl.proxy_url = proxy.to_s
94
- curl.proxy_port = proxy.port
95
- end
96
-
97
- curl.on_header {|header_data|
98
- name, value = header_data.strip.split(/:\s+/, 2)
99
- response.headers[name] = value
100
- header_data.length
101
- }
102
-
103
- case request.http_method
104
- when 'GET'
105
- # ....
106
- when 'HEAD'
107
- curl.head = true
108
- when 'PUT'
109
- curl.put_data = request.body
110
- when 'POST'
111
- curl.post_body = request.body
112
- when 'DELETE'
113
- curl.delete = true
114
- end
115
-
116
- curl.on_complete do
117
- response.body = curl.body_str
118
- response.status = curl.response_code
119
- thread.run if thread
120
- end
121
-
122
- curl
123
- end
124
-
125
- end
126
- end
127
- end
@@ -1,77 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'aws/meta_utils'
15
-
16
- module AWS
17
- module Http
18
-
19
- # @private
20
- class Handler
21
-
22
- attr_reader :base
23
-
24
- def initialize(base, &block)
25
- @base = base
26
- if base.respond_to?(:handle)
27
-
28
- unless block.arity == 2
29
- raise ArgumentError, 'passed block must accept 2 arguments'
30
- end
31
- MetaUtils.extend_method(self, :handle, &block)
32
-
33
- elsif base.respond_to?(:handle_async)
34
-
35
- unless block.arity == 3
36
- raise ArgumentError, 'passed block must accept 3 arguments'
37
- end
38
-
39
- MetaUtils.extend_method(self, :handle_async) do |req, resp, handle|
40
- @base.handle_async(req, resp, handle)
41
- end
42
- MetaUtils.extend(self) do
43
- define_method(:handle) do |req, resp|
44
- raise "attempted to call #handle on an async handler"
45
- end
46
- define_method(:handle_async, &block)
47
- end
48
-
49
- else
50
- raise ArgumentError, 'base must respond to #handle or #handle_async'
51
- end
52
- end
53
-
54
- def handle(request, http_response)
55
- @base.handle(request, http_response)
56
- end
57
-
58
- def handle_async(request, http_response, handle)
59
- Thread.new do
60
- begin
61
- self.handle(request, http_response)
62
- rescue => e
63
- handle.signal_failure
64
- else
65
- handle.signal_success
66
- end
67
- end
68
- end
69
-
70
- def sleep_with_callback seconds, &block
71
- Kernel.sleep(seconds)
72
- yield
73
- end
74
-
75
- end
76
- end
77
- end
@@ -1,103 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'httparty'
15
-
16
- module AWS
17
- module Http
18
-
19
- # Makes HTTP requests using HTTParty. This is the default
20
- # handler, so you don't need to do anything special to configure
21
- # it. However, you can directly instantiate this class in order
22
- # to send extra options to HTTParty, for example to enable an HTTP
23
- # proxy:
24
- #
25
- # AWS.config(
26
- # :http_handler => AWS::Http::HTTPartyHandler.new(
27
- # :http_proxyaddr => "http://myproxy.com",
28
- # :http_proxyport => 80
29
- # )
30
- # )
31
- #
32
- class HTTPartyHandler
33
-
34
- # @return [Hash] The default options to send to HTTParty on each
35
- # request.
36
- attr_reader :default_request_options
37
-
38
- # Constructs a new HTTP handler using HTTParty.
39
- #
40
- # @param [Hash] options Default options to send to HTTParty on
41
- # each request. These options will be sent to +get+, +post+,
42
- # +head+, +put+, or +delete+ when a request is made. Note
43
- # that +:body+, +:headers+, +:parser+, and +:ssl_ca_file+ are
44
- # ignored. If you need to set the CA file, you should use the
45
- # +:ssl_ca_file+ option to {AWS.config} or
46
- # {AWS::Configuration} instead.
47
- def initialize options = {}
48
- @default_request_options = options
49
- end
50
-
51
- include HTTParty
52
-
53
- class NoOpParser < HTTParty::Parser
54
- SupportedFormats = {}
55
- end
56
-
57
- def handle(request, response)
58
-
59
- opts = default_request_options.merge({
60
- :body => request.body,
61
- :parser => NoOpParser
62
- })
63
-
64
- if request.proxy_uri
65
- opts[:http_proxyaddr] = request.proxy_uri.host
66
- opts[:http_proxyport] = request.proxy_uri.port
67
- end
68
-
69
- if request.use_ssl?
70
- url = "https://#{request.host}:443#{request.uri}"
71
- opts[:ssl_ca_file] = request.ssl_ca_file if
72
- request.ssl_verify_peer?
73
- else
74
- url = "http://#{request.host}#{request.uri}"
75
- end
76
-
77
- # get, post, put, delete, head
78
- method = request.http_method.downcase
79
-
80
- # Net::HTTP adds this header for us when the body is
81
- # provided, but it messes up signing
82
- headers = { 'content-type' => '' }
83
-
84
- # headers must have string values (net http calls .strip on them)
85
- request.headers.each_pair do |key,value|
86
- headers[key] = value.to_s
87
- end
88
-
89
- opts[:headers] = headers
90
-
91
- begin
92
- http_response = self.class.send(method, url, opts)
93
- rescue Timeout::Error, Errno::ETIMEDOUT => e
94
- response.timeout = true
95
- else
96
- response.body = http_response.body
97
- response.status = http_response.code.to_i
98
- response.headers = http_response.to_hash
99
- end
100
- end
101
- end
102
- end
103
- end