aws_sdk 3.1.5

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 (390) hide show
  1. data/lib/aws-sdk.rb +14 -0
  2. data/lib/aws.rb +49 -0
  3. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +791 -0
  4. data/lib/aws/api_config/CloudFormation-2010-05-15.yml +303 -0
  5. data/lib/aws/api_config/DynamoDB-2011-12-05.yml +540 -0
  6. data/lib/aws/api_config/EC2-2011-12-15.yml +3638 -0
  7. data/lib/aws/api_config/EC2-2012-04-01.yml +3739 -0
  8. data/lib/aws/api_config/ELB-2011-08-15.yml +512 -0
  9. data/lib/aws/api_config/IAM-2010-05-08.yml +1221 -0
  10. data/lib/aws/api_config/SNS-2010-03-31.yml +248 -0
  11. data/lib/aws/api_config/SQS-2011-10-01.yml +314 -0
  12. data/lib/aws/api_config/STS-2011-06-15.yml +54 -0
  13. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +305 -0
  14. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +231 -0
  15. data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +721 -0
  16. data/lib/aws/auto_scaling.rb +162 -0
  17. data/lib/aws/auto_scaling/activity.rb +102 -0
  18. data/lib/aws/auto_scaling/activity_collection.rb +82 -0
  19. data/lib/aws/auto_scaling/client.rb +765 -0
  20. data/lib/aws/auto_scaling/config.rb +18 -0
  21. data/lib/aws/auto_scaling/errors.rb +22 -0
  22. data/lib/aws/auto_scaling/group.rb +420 -0
  23. data/lib/aws/auto_scaling/group_collection.rb +96 -0
  24. data/lib/aws/auto_scaling/group_options.rb +146 -0
  25. data/lib/aws/auto_scaling/instance.rb +192 -0
  26. data/lib/aws/auto_scaling/instance_collection.rb +63 -0
  27. data/lib/aws/auto_scaling/launch_configuration.rb +150 -0
  28. data/lib/aws/auto_scaling/launch_configuration_collection.rb +144 -0
  29. data/lib/aws/auto_scaling/notification_configuration.rb +89 -0
  30. data/lib/aws/auto_scaling/notification_configuration_collection.rb +184 -0
  31. data/lib/aws/auto_scaling/request.rb +23 -0
  32. data/lib/aws/auto_scaling/scaling_policy.rb +125 -0
  33. data/lib/aws/auto_scaling/scaling_policy_collection.rb +72 -0
  34. data/lib/aws/auto_scaling/scaling_policy_options.rb +61 -0
  35. data/lib/aws/auto_scaling/scheduled_action.rb +145 -0
  36. data/lib/aws/auto_scaling/scheduled_action_collection.rb +195 -0
  37. data/lib/aws/auto_scaling/tag.rb +59 -0
  38. data/lib/aws/auto_scaling/tag_collection.rb +112 -0
  39. data/lib/aws/cloud_formation.rb +270 -0
  40. data/lib/aws/cloud_formation/client.rb +339 -0
  41. data/lib/aws/cloud_formation/config.rb +18 -0
  42. data/lib/aws/cloud_formation/errors.rb +22 -0
  43. data/lib/aws/cloud_formation/request.rb +29 -0
  44. data/lib/aws/cloud_formation/stack.rb +256 -0
  45. data/lib/aws/cloud_formation/stack_collection.rb +206 -0
  46. data/lib/aws/cloud_formation/stack_event.rb +75 -0
  47. data/lib/aws/cloud_formation/stack_event_collection.rb +47 -0
  48. data/lib/aws/cloud_formation/stack_options.rb +72 -0
  49. data/lib/aws/cloud_formation/stack_output.rb +53 -0
  50. data/lib/aws/cloud_formation/stack_resource.rb +117 -0
  51. data/lib/aws/cloud_formation/stack_resource_collection.rb +84 -0
  52. data/lib/aws/cloud_formation/stack_resource_summary_collection.rb +72 -0
  53. data/lib/aws/cloud_formation/stack_summary.rb +71 -0
  54. data/lib/aws/cloud_formation/stack_summary_collection.rb +127 -0
  55. data/lib/aws/core.rb +474 -0
  56. data/lib/aws/core/async_handle.rb +90 -0
  57. data/lib/aws/core/autoloader.rb +64 -0
  58. data/lib/aws/core/cacheable.rb +78 -0
  59. data/lib/aws/core/client.rb +541 -0
  60. data/lib/aws/core/client/query_json.rb +110 -0
  61. data/lib/aws/core/client/query_xml.rb +122 -0
  62. data/lib/aws/core/collection.rb +234 -0
  63. data/lib/aws/core/collection/limitable.rb +99 -0
  64. data/lib/aws/core/collection/simple.rb +90 -0
  65. data/lib/aws/core/configuration.rb +445 -0
  66. data/lib/aws/core/data.rb +242 -0
  67. data/lib/aws/core/default_signer.rb +67 -0
  68. data/lib/aws/core/http/curb_handler.rb +136 -0
  69. data/lib/aws/core/http/handler.rb +77 -0
  70. data/lib/aws/core/http/httparty_handler.rb +114 -0
  71. data/lib/aws/core/http/net_http_handler.rb +85 -0
  72. data/lib/aws/core/http/request.rb +250 -0
  73. data/lib/aws/core/http/response.rb +74 -0
  74. data/lib/aws/core/indifferent_hash.rb +88 -0
  75. data/lib/aws/core/inflection.rb +47 -0
  76. data/lib/aws/core/lazy_error_classes.rb +90 -0
  77. data/lib/aws/core/log_formatter.rb +454 -0
  78. data/lib/aws/core/meta_utils.rb +45 -0
  79. data/lib/aws/core/model.rb +57 -0
  80. data/lib/aws/core/naming.rb +30 -0
  81. data/lib/aws/core/option_grammar.rb +700 -0
  82. data/lib/aws/core/page_result.rb +73 -0
  83. data/lib/aws/core/policy.rb +916 -0
  84. data/lib/aws/core/resource.rb +408 -0
  85. data/lib/aws/core/resource_cache.rb +40 -0
  86. data/lib/aws/core/response.rb +202 -0
  87. data/lib/aws/core/response_cache.rb +50 -0
  88. data/lib/aws/core/service_interface.rb +61 -0
  89. data/lib/aws/core/session_signer.rb +90 -0
  90. data/lib/aws/core/signature/version_2.rb +42 -0
  91. data/lib/aws/core/signature/version_3.rb +73 -0
  92. data/lib/aws/core/signature/version_3_http.rb +72 -0
  93. data/lib/aws/core/signature/version_4.rb +138 -0
  94. data/lib/aws/core/uri_escape.rb +42 -0
  95. data/lib/aws/core/xml/frame.rb +242 -0
  96. data/lib/aws/core/xml/frame_stack.rb +85 -0
  97. data/lib/aws/core/xml/grammar.rb +299 -0
  98. data/lib/aws/core/xml/parser.rb +70 -0
  99. data/lib/aws/core/xml/root_frame.rb +65 -0
  100. data/lib/aws/core/xml/sax_handlers/libxml.rb +47 -0
  101. data/lib/aws/core/xml/sax_handlers/nokogiri.rb +55 -0
  102. data/lib/aws/core/xml/sax_handlers/ox.rb +41 -0
  103. data/lib/aws/core/xml/sax_handlers/rexml.rb +43 -0
  104. data/lib/aws/core/xml/stub.rb +123 -0
  105. data/lib/aws/dynamo_db.rb +213 -0
  106. data/lib/aws/dynamo_db/attribute_collection.rb +460 -0
  107. data/lib/aws/dynamo_db/batch_get.rb +206 -0
  108. data/lib/aws/dynamo_db/batch_write.rb +251 -0
  109. data/lib/aws/dynamo_db/client.rb +888 -0
  110. data/lib/aws/dynamo_db/config.rb +20 -0
  111. data/lib/aws/dynamo_db/errors.rb +20 -0
  112. data/lib/aws/dynamo_db/expectations.rb +40 -0
  113. data/lib/aws/dynamo_db/item.rb +130 -0
  114. data/lib/aws/dynamo_db/item_collection.rb +852 -0
  115. data/lib/aws/dynamo_db/item_data.rb +31 -0
  116. data/lib/aws/dynamo_db/keys.rb +41 -0
  117. data/lib/aws/dynamo_db/primary_key_element.rb +47 -0
  118. data/lib/aws/dynamo_db/request.rb +28 -0
  119. data/lib/aws/dynamo_db/resource.rb +33 -0
  120. data/lib/aws/dynamo_db/table.rb +489 -0
  121. data/lib/aws/dynamo_db/table_collection.rb +165 -0
  122. data/lib/aws/dynamo_db/types.rb +86 -0
  123. data/lib/aws/ec2.rb +431 -0
  124. data/lib/aws/ec2/attachment.rb +140 -0
  125. data/lib/aws/ec2/attachment_collection.rb +54 -0
  126. data/lib/aws/ec2/availability_zone.rb +87 -0
  127. data/lib/aws/ec2/availability_zone_collection.rb +43 -0
  128. data/lib/aws/ec2/block_device_mappings.rb +53 -0
  129. data/lib/aws/ec2/client.rb +4121 -0
  130. data/lib/aws/ec2/collection.rb +36 -0
  131. data/lib/aws/ec2/config.rb +18 -0
  132. data/lib/aws/ec2/config_transform.rb +63 -0
  133. data/lib/aws/ec2/customer_gateway.rb +90 -0
  134. data/lib/aws/ec2/customer_gateway_collection.rb +73 -0
  135. data/lib/aws/ec2/dhcp_options.rb +106 -0
  136. data/lib/aws/ec2/dhcp_options_collection.rb +87 -0
  137. data/lib/aws/ec2/elastic_ip.rb +157 -0
  138. data/lib/aws/ec2/elastic_ip_collection.rb +97 -0
  139. data/lib/aws/ec2/errors.rb +32 -0
  140. data/lib/aws/ec2/filtered_collection.rb +90 -0
  141. data/lib/aws/ec2/has_permissions.rb +44 -0
  142. data/lib/aws/ec2/image.rb +254 -0
  143. data/lib/aws/ec2/image_collection.rb +228 -0
  144. data/lib/aws/ec2/instance.rb +669 -0
  145. data/lib/aws/ec2/instance_collection.rb +346 -0
  146. data/lib/aws/ec2/internet_gateway.rb +122 -0
  147. data/lib/aws/ec2/internet_gateway/attachment.rb +78 -0
  148. data/lib/aws/ec2/internet_gateway_collection.rb +54 -0
  149. data/lib/aws/ec2/key_pair.rb +82 -0
  150. data/lib/aws/ec2/key_pair_collection.rb +99 -0
  151. data/lib/aws/ec2/network_acl.rb +256 -0
  152. data/lib/aws/ec2/network_acl/association.rb +56 -0
  153. data/lib/aws/ec2/network_acl/entry.rb +147 -0
  154. data/lib/aws/ec2/network_acl_collection.rb +64 -0
  155. data/lib/aws/ec2/network_interface.rb +228 -0
  156. data/lib/aws/ec2/network_interface/attachment.rb +100 -0
  157. data/lib/aws/ec2/network_interface_collection.rb +103 -0
  158. data/lib/aws/ec2/permission_collection.rb +174 -0
  159. data/lib/aws/ec2/region.rb +97 -0
  160. data/lib/aws/ec2/region_collection.rb +51 -0
  161. data/lib/aws/ec2/request.rb +22 -0
  162. data/lib/aws/ec2/reserved_instances.rb +53 -0
  163. data/lib/aws/ec2/reserved_instances_collection.rb +40 -0
  164. data/lib/aws/ec2/reserved_instances_offering.rb +58 -0
  165. data/lib/aws/ec2/reserved_instances_offering_collection.rb +39 -0
  166. data/lib/aws/ec2/resource.rb +161 -0
  167. data/lib/aws/ec2/resource_tag_collection.rb +211 -0
  168. data/lib/aws/ec2/route_table.rb +205 -0
  169. data/lib/aws/ec2/route_table/association.rb +119 -0
  170. data/lib/aws/ec2/route_table/route.rb +113 -0
  171. data/lib/aws/ec2/route_table_collection.rb +72 -0
  172. data/lib/aws/ec2/security_group.rb +458 -0
  173. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +63 -0
  174. data/lib/aws/ec2/security_group/ingress_ip_permission_collection.rb +61 -0
  175. data/lib/aws/ec2/security_group/ip_permission.rb +128 -0
  176. data/lib/aws/ec2/security_group_collection.rb +135 -0
  177. data/lib/aws/ec2/snapshot.rb +143 -0
  178. data/lib/aws/ec2/snapshot_collection.rb +131 -0
  179. data/lib/aws/ec2/subnet.rb +161 -0
  180. data/lib/aws/ec2/subnet_collection.rb +115 -0
  181. data/lib/aws/ec2/tag.rb +81 -0
  182. data/lib/aws/ec2/tag_collection.rb +107 -0
  183. data/lib/aws/ec2/tagged_collection.rb +53 -0
  184. data/lib/aws/ec2/tagged_item.rb +85 -0
  185. data/lib/aws/ec2/volume.rb +170 -0
  186. data/lib/aws/ec2/volume_collection.rb +97 -0
  187. data/lib/aws/ec2/vpc.rb +166 -0
  188. data/lib/aws/ec2/vpc_collection.rb +70 -0
  189. data/lib/aws/ec2/vpn_connection.rb +99 -0
  190. data/lib/aws/ec2/vpn_connection/telemetry.rb +49 -0
  191. data/lib/aws/ec2/vpn_connection_collection.rb +96 -0
  192. data/lib/aws/ec2/vpn_gateway.rb +123 -0
  193. data/lib/aws/ec2/vpn_gateway/attachment.rb +45 -0
  194. data/lib/aws/ec2/vpn_gateway_collection.rb +77 -0
  195. data/lib/aws/elb.rb +65 -0
  196. data/lib/aws/elb/availability_zone_collection.rb +138 -0
  197. data/lib/aws/elb/backend_server_policy_collection.rb +140 -0
  198. data/lib/aws/elb/client.rb +539 -0
  199. data/lib/aws/elb/config.rb +18 -0
  200. data/lib/aws/elb/errors.rb +26 -0
  201. data/lib/aws/elb/instance_collection.rb +174 -0
  202. data/lib/aws/elb/listener.rb +189 -0
  203. data/lib/aws/elb/listener_collection.rb +119 -0
  204. data/lib/aws/elb/listener_opts.rb +45 -0
  205. data/lib/aws/elb/load_balancer.rb +253 -0
  206. data/lib/aws/elb/load_balancer_collection.rb +113 -0
  207. data/lib/aws/elb/load_balancer_policy.rb +93 -0
  208. data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
  209. data/lib/aws/elb/request.rb +23 -0
  210. data/lib/aws/errors.rb +122 -0
  211. data/lib/aws/iam.rb +418 -0
  212. data/lib/aws/iam/access_key.rb +180 -0
  213. data/lib/aws/iam/access_key_collection.rb +128 -0
  214. data/lib/aws/iam/account_alias_collection.rb +79 -0
  215. data/lib/aws/iam/client.rb +1609 -0
  216. data/lib/aws/iam/collection.rb +83 -0
  217. data/lib/aws/iam/config.rb +18 -0
  218. data/lib/aws/iam/errors.rb +22 -0
  219. data/lib/aws/iam/group.rb +111 -0
  220. data/lib/aws/iam/group_collection.rb +132 -0
  221. data/lib/aws/iam/group_policy_collection.rb +47 -0
  222. data/lib/aws/iam/group_user_collection.rb +84 -0
  223. data/lib/aws/iam/login_profile.rb +99 -0
  224. data/lib/aws/iam/mfa_device.rb +52 -0
  225. data/lib/aws/iam/mfa_device_collection.rb +127 -0
  226. data/lib/aws/iam/policy.rb +46 -0
  227. data/lib/aws/iam/policy_collection.rb +188 -0
  228. data/lib/aws/iam/request.rb +29 -0
  229. data/lib/aws/iam/resource.rb +71 -0
  230. data/lib/aws/iam/server_certificate.rb +141 -0
  231. data/lib/aws/iam/server_certificate_collection.rb +138 -0
  232. data/lib/aws/iam/signing_certificate.rb +169 -0
  233. data/lib/aws/iam/signing_certificate_collection.rb +131 -0
  234. data/lib/aws/iam/user.rb +205 -0
  235. data/lib/aws/iam/user_collection.rb +133 -0
  236. data/lib/aws/iam/user_group_collection.rb +98 -0
  237. data/lib/aws/iam/user_policy.rb +90 -0
  238. data/lib/aws/iam/user_policy_collection.rb +45 -0
  239. data/lib/aws/iam/virtual_mfa_device.rb +139 -0
  240. data/lib/aws/iam/virtual_mfa_device_collection.rb +73 -0
  241. data/lib/aws/rails.rb +195 -0
  242. data/lib/aws/record.rb +116 -0
  243. data/lib/aws/record/abstract_base.rb +645 -0
  244. data/lib/aws/record/attributes.rb +384 -0
  245. data/lib/aws/record/conversion.rb +38 -0
  246. data/lib/aws/record/dirty_tracking.rb +285 -0
  247. data/lib/aws/record/errors.rb +143 -0
  248. data/lib/aws/record/exceptions.rb +48 -0
  249. data/lib/aws/record/hash_model.rb +161 -0
  250. data/lib/aws/record/hash_model/attributes.rb +182 -0
  251. data/lib/aws/record/hash_model/finder_methods.rb +172 -0
  252. data/lib/aws/record/hash_model/scope.rb +108 -0
  253. data/lib/aws/record/model.rb +427 -0
  254. data/lib/aws/record/model/attributes.rb +379 -0
  255. data/lib/aws/record/model/finder_methods.rb +232 -0
  256. data/lib/aws/record/model/scope.rb +213 -0
  257. data/lib/aws/record/naming.rb +31 -0
  258. data/lib/aws/record/scope.rb +199 -0
  259. data/lib/aws/record/validations.rb +694 -0
  260. data/lib/aws/record/validator.rb +237 -0
  261. data/lib/aws/record/validators/acceptance.rb +51 -0
  262. data/lib/aws/record/validators/block.rb +38 -0
  263. data/lib/aws/record/validators/confirmation.rb +43 -0
  264. data/lib/aws/record/validators/count.rb +108 -0
  265. data/lib/aws/record/validators/exclusion.rb +43 -0
  266. data/lib/aws/record/validators/format.rb +57 -0
  267. data/lib/aws/record/validators/inclusion.rb +56 -0
  268. data/lib/aws/record/validators/length.rb +107 -0
  269. data/lib/aws/record/validators/method.rb +33 -0
  270. data/lib/aws/record/validators/numericality.rb +138 -0
  271. data/lib/aws/record/validators/presence.rb +45 -0
  272. data/lib/aws/s3.rb +135 -0
  273. data/lib/aws/s3/access_control_list.rb +250 -0
  274. data/lib/aws/s3/acl_object.rb +264 -0
  275. data/lib/aws/s3/bucket.rb +393 -0
  276. data/lib/aws/s3/bucket_collection.rb +143 -0
  277. data/lib/aws/s3/bucket_lifecycle_configuration.rb +360 -0
  278. data/lib/aws/s3/bucket_version_collection.rb +77 -0
  279. data/lib/aws/s3/client.rb +1184 -0
  280. data/lib/aws/s3/client/xml.rb +177 -0
  281. data/lib/aws/s3/config.rb +26 -0
  282. data/lib/aws/s3/data_options.rb +100 -0
  283. data/lib/aws/s3/errors.rb +81 -0
  284. data/lib/aws/s3/multipart_upload.rb +317 -0
  285. data/lib/aws/s3/multipart_upload_collection.rb +68 -0
  286. data/lib/aws/s3/object_collection.rb +337 -0
  287. data/lib/aws/s3/object_metadata.rb +96 -0
  288. data/lib/aws/s3/object_upload_collection.rb +77 -0
  289. data/lib/aws/s3/object_version.rb +143 -0
  290. data/lib/aws/s3/object_version_collection.rb +89 -0
  291. data/lib/aws/s3/paginated_collection.rb +75 -0
  292. data/lib/aws/s3/policy.rb +74 -0
  293. data/lib/aws/s3/prefix_and_delimiter_collection.rb +47 -0
  294. data/lib/aws/s3/prefixed_collection.rb +81 -0
  295. data/lib/aws/s3/presigned_post.rb +553 -0
  296. data/lib/aws/s3/request.rb +201 -0
  297. data/lib/aws/s3/s3_object.rb +1037 -0
  298. data/lib/aws/s3/tree.rb +118 -0
  299. data/lib/aws/s3/tree/branch_node.rb +68 -0
  300. data/lib/aws/s3/tree/child_collection.rb +104 -0
  301. data/lib/aws/s3/tree/leaf_node.rb +94 -0
  302. data/lib/aws/s3/tree/node.rb +22 -0
  303. data/lib/aws/s3/tree/parent.rb +87 -0
  304. data/lib/aws/s3/uploaded_part.rb +80 -0
  305. data/lib/aws/s3/uploaded_part_collection.rb +84 -0
  306. data/lib/aws/simple_db.rb +217 -0
  307. data/lib/aws/simple_db/attribute.rb +154 -0
  308. data/lib/aws/simple_db/attribute_collection.rb +231 -0
  309. data/lib/aws/simple_db/client.rb +349 -0
  310. data/lib/aws/simple_db/config.rb +20 -0
  311. data/lib/aws/simple_db/consistent_read_option.rb +42 -0
  312. data/lib/aws/simple_db/delete_attributes.rb +62 -0
  313. data/lib/aws/simple_db/domain.rb +121 -0
  314. data/lib/aws/simple_db/domain_collection.rb +113 -0
  315. data/lib/aws/simple_db/domain_metadata.rb +110 -0
  316. data/lib/aws/simple_db/errors.rb +55 -0
  317. data/lib/aws/simple_db/expect_condition_option.rb +45 -0
  318. data/lib/aws/simple_db/item.rb +93 -0
  319. data/lib/aws/simple_db/item_collection.rb +649 -0
  320. data/lib/aws/simple_db/item_data.rb +73 -0
  321. data/lib/aws/simple_db/put_attributes.rb +60 -0
  322. data/lib/aws/simple_db/request.rb +23 -0
  323. data/lib/aws/simple_email_service.rb +426 -0
  324. data/lib/aws/simple_email_service/client.rb +286 -0
  325. data/lib/aws/simple_email_service/config.rb +19 -0
  326. data/lib/aws/simple_email_service/email_address_collection.rb +69 -0
  327. data/lib/aws/simple_email_service/errors.rb +22 -0
  328. data/lib/aws/simple_email_service/identity.rb +91 -0
  329. data/lib/aws/simple_email_service/identity_collection.rb +81 -0
  330. data/lib/aws/simple_email_service/quotas.rb +64 -0
  331. data/lib/aws/simple_email_service/request.rb +29 -0
  332. data/lib/aws/simple_workflow.rb +226 -0
  333. data/lib/aws/simple_workflow/activity_task.rb +173 -0
  334. data/lib/aws/simple_workflow/activity_task_collection.rb +123 -0
  335. data/lib/aws/simple_workflow/activity_type.rb +131 -0
  336. data/lib/aws/simple_workflow/activity_type_collection.rb +93 -0
  337. data/lib/aws/simple_workflow/client.rb +1434 -0
  338. data/lib/aws/simple_workflow/config.rb +18 -0
  339. data/lib/aws/simple_workflow/count.rb +49 -0
  340. data/lib/aws/simple_workflow/decision_task.rb +601 -0
  341. data/lib/aws/simple_workflow/decision_task_collection.rb +225 -0
  342. data/lib/aws/simple_workflow/domain.rb +122 -0
  343. data/lib/aws/simple_workflow/domain_collection.rb +169 -0
  344. data/lib/aws/simple_workflow/errors.rb +20 -0
  345. data/lib/aws/simple_workflow/history_event.rb +276 -0
  346. data/lib/aws/simple_workflow/history_event_collection.rb +76 -0
  347. data/lib/aws/simple_workflow/option_formatters.rb +82 -0
  348. data/lib/aws/simple_workflow/request.rb +36 -0
  349. data/lib/aws/simple_workflow/resource.rb +94 -0
  350. data/lib/aws/simple_workflow/type.rb +89 -0
  351. data/lib/aws/simple_workflow/type_collection.rb +140 -0
  352. data/lib/aws/simple_workflow/workflow_execution.rb +386 -0
  353. data/lib/aws/simple_workflow/workflow_execution_collection.rb +617 -0
  354. data/lib/aws/simple_workflow/workflow_type.rb +177 -0
  355. data/lib/aws/simple_workflow/workflow_type_collection.rb +91 -0
  356. data/lib/aws/sns.rb +74 -0
  357. data/lib/aws/sns/client.rb +371 -0
  358. data/lib/aws/sns/config.rb +18 -0
  359. data/lib/aws/sns/errors.rb +22 -0
  360. data/lib/aws/sns/has_delivery_policy.rb +68 -0
  361. data/lib/aws/sns/policy.rb +47 -0
  362. data/lib/aws/sns/request.rb +23 -0
  363. data/lib/aws/sns/subscription.rb +144 -0
  364. data/lib/aws/sns/subscription_collection.rb +80 -0
  365. data/lib/aws/sns/topic.rb +403 -0
  366. data/lib/aws/sns/topic_collection.rb +67 -0
  367. data/lib/aws/sns/topic_subscription_collection.rb +55 -0
  368. data/lib/aws/sqs.rb +79 -0
  369. data/lib/aws/sqs/client.rb +360 -0
  370. data/lib/aws/sqs/config.rb +18 -0
  371. data/lib/aws/sqs/errors.rb +101 -0
  372. data/lib/aws/sqs/policy.rb +48 -0
  373. data/lib/aws/sqs/queue.rb +725 -0
  374. data/lib/aws/sqs/queue_collection.rb +170 -0
  375. data/lib/aws/sqs/received_message.rb +181 -0
  376. data/lib/aws/sqs/received_sns_message.rb +112 -0
  377. data/lib/aws/sqs/request.rb +43 -0
  378. data/lib/aws/sts.rb +152 -0
  379. data/lib/aws/sts/client.rb +105 -0
  380. data/lib/aws/sts/config.rb +18 -0
  381. data/lib/aws/sts/errors.rb +22 -0
  382. data/lib/aws/sts/federated_session.rb +56 -0
  383. data/lib/aws/sts/policy.rb +30 -0
  384. data/lib/aws/sts/request.rb +29 -0
  385. data/lib/aws/sts/session.rb +48 -0
  386. data/lib/net/http/connection_pool.rb +210 -0
  387. data/lib/net/http/connection_pool/connection.rb +132 -0
  388. data/lib/net/http/connection_pool/session.rb +93 -0
  389. data/lib/user.rb +49 -0
  390. metadata +433 -0
@@ -0,0 +1,201 @@
1
+ # Copyright 2011-2012 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 'uri'
15
+ require 'time'
16
+
17
+ module AWS
18
+ class S3
19
+
20
+ # @private
21
+ class Request < Core::Http::Request
22
+
23
+ include Core::UriEscape
24
+
25
+ # @return [bucket] S3 bucket name
26
+ attr_accessor :bucket
27
+
28
+ # @return [String] S3 object key
29
+ attr_accessor :key
30
+
31
+ # @private
32
+ attr_accessor :body_stream
33
+
34
+ def metadata= metadata
35
+ Array(metadata).each do |name, value|
36
+ headers["x-amz-meta-#{name}"] = value
37
+ end
38
+ end
39
+
40
+ def canned_acl= acl
41
+ if acl.kind_of?(Symbol)
42
+ headers["x-amz-acl"] = acl.to_s.gsub("_", "-")
43
+ elsif acl
44
+ headers["x-amz-acl"] = acl
45
+ end
46
+ end
47
+
48
+ def storage_class= storage_class
49
+ if storage_class.kind_of?(Symbol)
50
+ headers["x-amz-storage-class"] = storage_class.to_s.upcase
51
+ elsif storage_class
52
+ headers["x-amz-storage-class"] = storage_class
53
+ end
54
+ end
55
+
56
+ def host
57
+ Client.path_style_bucket_name?(bucket) ? @host : "#{bucket}.#{@host}"
58
+ end
59
+
60
+ def path
61
+ parts = []
62
+ parts << bucket if bucket and Client.path_style_bucket_name?(bucket)
63
+ parts << escape_path(key) if key
64
+ "/#{parts.join('/')}"
65
+ end
66
+
67
+ def querystring
68
+ url_encoded_params
69
+ end
70
+
71
+ # @param [String, IO] body The http request body. This can be a string or
72
+ # any object that responds to #read and #eof? (like an IO object).
73
+ def body= body
74
+ @body_stream = StringIO.new(body)
75
+ end
76
+
77
+ # @return [String, nil] The http request body.
78
+ def body
79
+ if @body_stream
80
+ string = @body_stream.read
81
+ @body_stream.rewind
82
+ string
83
+ else
84
+ nil
85
+ end
86
+ end
87
+
88
+ # From the S3 developer guide:
89
+ #
90
+ # StringToSign =
91
+ # HTTP-Verb + "\n" +
92
+ # content-md5 + "\n" +
93
+ # content-type + "\n" +
94
+ # date + "\n" +
95
+ # CanonicalizedAmzHeaders + CanonicalizedResource;
96
+ #
97
+ def string_to_sign
98
+ [
99
+ http_method,
100
+ headers.values_at('content-md5', 'content-type').join("\n"),
101
+ signing_string_date,
102
+ canonicalized_headers,
103
+ canonicalized_resource,
104
+ ].flatten.compact.join("\n")
105
+ end
106
+
107
+ def signing_string_date
108
+ # if a date is provided via x-amz-date then we should omit the
109
+ # Date header from the signing string (should appear as a blank line)
110
+ if headers.detect{|k,v| k.to_s =~ /^x-amz-date$/i }
111
+ ''
112
+ else
113
+ headers['date'] ||= Time.now.rfc822
114
+ end
115
+ end
116
+
117
+ # From the S3 developer guide
118
+ #
119
+ # CanonicalizedResource =
120
+ # [ "/" + Bucket ] +
121
+ # <HTTP-Request-URI, from the protocol name up to the querystring> +
122
+ # [ sub-resource, if present. e.g. "?acl", "?location",
123
+ # "?logging", or "?torrent"];
124
+ #
125
+ def canonicalized_resource
126
+
127
+ parts = []
128
+
129
+ # virtual hosted-style requests require the hostname to appear
130
+ # in the canonicalized resource prefixed by a forward slash.
131
+ if
132
+ Client.dns_compatible_bucket_name?(bucket) and
133
+ !Client.path_style_bucket_name?(bucket)
134
+ then
135
+ parts << "/#{bucket}"
136
+ end
137
+
138
+ # all requests require the portion of the un-decoded uri up to
139
+ # but not including the query string
140
+ parts << path
141
+
142
+ # lastly any sub resource querystring params need to be appened
143
+ # in lexigraphical ordered joined by '&' and prefixed by '?'
144
+ params = (sub_resource_params + query_parameters_for_signature)
145
+ unless params.empty?
146
+ parts << '?'
147
+ parts << params.sort.collect{|p| p.to_s }.join('&')
148
+ end
149
+
150
+ parts.join
151
+ end
152
+
153
+ # CanonicalizedAmzHeaders
154
+ #
155
+ # See the developer guide for more information on how this element
156
+ # is generated.
157
+ #
158
+ def canonicalized_headers
159
+ x_amz = headers.select{|name, value| name.to_s =~ /^x-amz-/i }
160
+ x_amz = x_amz.collect{|name, value| [name.downcase, value] }
161
+ x_amz = x_amz.sort_by{|name, value| name }
162
+ x_amz = x_amz.collect{|name, value| "#{name}:#{value}" }.join("\n")
163
+ x_amz == '' ? nil : x_amz
164
+ end
165
+
166
+ def sub_resource_params
167
+ params.select{|p| self.class.sub_resources.include?(p.name) }
168
+ end
169
+
170
+ def query_parameters_for_signature
171
+ params.select { |p| self.class.query_parameters.include?(p.name) }
172
+ end
173
+
174
+ def add_authorization!(signer)
175
+ if signer.respond_to?(:session_token) and
176
+ token = signer.session_token
177
+ headers["x-amz-security-token"] = token
178
+ end
179
+ signature = URI.escape(signer.sign(string_to_sign, 'sha1'))
180
+ headers["authorization"] = "AWS #{signer.access_key_id}:#{signature}"
181
+ end
182
+
183
+ class << self
184
+
185
+ def sub_resources
186
+ %w(acl location logging notification partNumber policy
187
+ requestPayment torrent uploadId uploads versionId
188
+ versioning versions delete lifecycle)
189
+ end
190
+
191
+ def query_parameters
192
+ %w(response-content-type response-content-language
193
+ response-expires response-cache-control
194
+ response-content-disposition response-content-encoding)
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,1037 @@
1
+ # Copyright 2011-2012 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 'uri'
15
+
16
+ module AWS
17
+ class S3
18
+
19
+ # Represents an object in S3 identified by a key.
20
+ #
21
+ # object = bucket.objects["key-to-my-object"]
22
+ # object.key #=> 'key-to-my-object'
23
+ #
24
+ # See {ObjectCollection} for more information on finding objects.
25
+ #
26
+ # == Writing and Reading S3Objects
27
+ #
28
+ # obj = bucket.objects["my-text-object"]
29
+ #
30
+ # obj.write("MY TEXT")
31
+ # obj.read
32
+ # #=> "MY TEXT"
33
+ #
34
+ # obj.write(File.new("README.txt"))
35
+ # obj.read
36
+ # # should equal File.read("README.txt")
37
+ #
38
+ class S3Object
39
+
40
+ include Core::Model
41
+ include DataOptions
42
+
43
+ # @param [Bucket] bucket The bucket this object belongs to.
44
+ # @param [String] key The object's key.
45
+ def initialize(bucket, key, opts = {})
46
+ super
47
+ @key = key
48
+ @bucket = bucket
49
+ end
50
+
51
+ # @return [String] The objects unique key
52
+ attr_reader :key
53
+
54
+ # @return [Bucket] The bucket this object is in.
55
+ attr_reader :bucket
56
+
57
+ # @private
58
+ def inspect
59
+ "<#{self.class}:#{bucket.name}/#{key}>"
60
+ end
61
+
62
+ # @return [Boolean] Returns true if the other object belongs to the
63
+ # same bucket and has the same key.
64
+ def ==(other)
65
+ other.kind_of?(S3Object) and other.bucket == bucket and other.key == key
66
+ end
67
+
68
+ alias_method :eql?, :==
69
+
70
+ def exists?
71
+ head
72
+ rescue Errors::NoSuchKey => e
73
+ false
74
+ else
75
+ true
76
+ end
77
+
78
+ # Performs a HEAD request against this object and returns an object
79
+ # with useful information about the object, including:
80
+ #
81
+ # * metadata (hash of user-supplied key-value pairs)
82
+ # * content_length (integer, number of bytes)
83
+ # * content_type (as sent to S3 when uploading the object)
84
+ # * etag (typically the object's MD5)
85
+ # * server_side_encryption (the algorithm used to encrypt the
86
+ # object on the server side, e.g. +:aes256+)
87
+ #
88
+ # @param [Hash] options
89
+ # @option options [String] :version_id Which version of this object
90
+ # to make a HEAD request against.
91
+ # @return A head object response with metatadata,
92
+ # content_length, content_type, etag and server_side_encryption.
93
+ def head options = {}
94
+ client.head_object(options.merge(
95
+ :bucket_name => bucket.name, :key => key))
96
+ end
97
+
98
+ # Returns the object's ETag.
99
+ #
100
+ # Generally the ETAG is the MD5 of the object. If the object was
101
+ # uploaded using multipart upload then this is the MD5 all of the
102
+ # upload-part-md5s.
103
+ #
104
+ # @return [String] Returns the object's ETag
105
+ def etag
106
+ head.etag
107
+ end
108
+
109
+ # Returns the object's last modified time.
110
+ #
111
+ # @return [Time] Returns the object's last modified time.
112
+ def last_modified
113
+ head.last_modified
114
+ end
115
+
116
+ # @return [Integer] Size of the object in bytes.
117
+ def content_length
118
+ head.content_length
119
+ end
120
+
121
+ # @note S3 does not compute content-type. It reports the content-type
122
+ # as was reported during the file upload.
123
+ # @return [String] Returns the content type as reported by S3,
124
+ # defaults to an empty string when not provided during upload.
125
+ def content_type
126
+ head.content_type
127
+ end
128
+
129
+ # @return [DateTime,nil]
130
+ def expiration_date
131
+ head.expiration_date
132
+ end
133
+
134
+ # @return [String,nil]
135
+ def expiration_rule_id
136
+ head.expiration_date
137
+ end
138
+
139
+ # @return [Symbol, nil] Returns the algorithm used to encrypt
140
+ # the object on the server side, or +nil+ if SSE was not used
141
+ # when storing the object.
142
+ def server_side_encryption
143
+ head.server_side_encryption
144
+ end
145
+
146
+ # @return [true, false] Returns true if the object was stored
147
+ # using server side encryption.
148
+ def server_side_encryption?
149
+ !server_side_encryption.nil?
150
+ end
151
+
152
+ # Deletes the object from its S3 bucket.
153
+ #
154
+ # @param [Hash] options
155
+ # @option [String] :version_id (nil) If present the specified version
156
+ # of this object will be deleted. Only works for buckets that have
157
+ # had versioning enabled.
158
+ # @return [nil]
159
+ def delete options = {}
160
+ options[:bucket_name] = bucket.name
161
+ options[:key] = key
162
+ client.delete_object(options)
163
+ nil
164
+ end
165
+
166
+ # @option [String] :version_id (nil) If present the metadata object
167
+ # will be for the specified version.
168
+ # @return [ObjectMetadata] Returns an instance of ObjectMetadata
169
+ # representing the metadata for this object.
170
+ def metadata options = {}
171
+ options[:config] = config
172
+ ObjectMetadata.new(self, options)
173
+ end
174
+
175
+ # Returns a colletion representing all the object versions
176
+ # for this object.
177
+ #
178
+ # bucket.versioning_enabled? # => true
179
+ # version = bucket.objects["mykey"].versions.latest
180
+ #
181
+ # @return [ObjectVersionCollection]
182
+ def versions
183
+ ObjectVersionCollection.new(self)
184
+ end
185
+
186
+ # Writes data to the object in S3. This method will attempt
187
+ # to intelligently choose between uploading in one request and
188
+ # using {#multipart_upload}.
189
+ #
190
+ # Unless versioning is enabled, any data currently in S3 at {#key}
191
+ # will be replaced.
192
+ #
193
+ # You can pass +:data+ or +:file+ as the first argument or as
194
+ # options. Example usage:
195
+ #
196
+ # obj = s3.buckets.mybucket.objects.mykey
197
+ # obj.write("HELLO")
198
+ # obj.write(:data => "HELLO")
199
+ # obj.write(Pathname.new("myfile"))
200
+ # obj.write(:file => "myfile")
201
+ #
202
+ # # writes zero-length data
203
+ # obj.write(:metadata => { "avg-rating" => "5 stars" })
204
+ #
205
+ # @overload write(options = {})
206
+ # @overload write(data, options = {})
207
+ # @param data The data to upload (see the +:data+ option).
208
+ #
209
+ # @param options [Hash] Additional upload options.
210
+ #
211
+ # @option options :data The data to upload. Valid values include:
212
+ #
213
+ # * A string
214
+ # * A Pathname object
215
+ # * Any object responding to +read+ and +eof?+; the object
216
+ # must support the following access methods:
217
+ # read # all at once
218
+ # read(length) until eof? # in chunks
219
+ #
220
+ # If you specify data this way, you must also include the
221
+ # +:content_length+ option.
222
+ #
223
+ # @option options [String] :file Can be specified instead of +:data+;
224
+ # its value specifies the path of a file to upload.
225
+ #
226
+ # @option options [Boolean] :single_request If this option is
227
+ # true, the method will always generate exactly one request
228
+ # to S3 regardless of how much data is being uploaded.
229
+ #
230
+ # @option options [Integer] :content_length If provided, this
231
+ # option must match the total number of bytes written to S3
232
+ # during the operation. This option is required if +:data+
233
+ # is an IO-like object without a +size+ method.
234
+ #
235
+ # @option options [Integer] :multipart_threshold Specifies the
236
+ # maximum size in bytes of a single-request upload. If the
237
+ # data being uploaded is larger than this threshold, it will
238
+ # be uploaded using {#multipart_upload}.
239
+ #
240
+ # @option options [Integer] :multipart_min_part_size The
241
+ # minimum size of a part if a multi-part upload is used. S3
242
+ # will reject non-final parts smaller than 5MB, and the
243
+ # default for this option is 5MB.
244
+ #
245
+ # @option options [Hash] :metadata A hash of metadata to be
246
+ # included with the object. These will be sent to S3 as
247
+ # headers prefixed with +x-amz-meta+. Each name, value pair
248
+ # must conform to US-ASCII.
249
+ #
250
+ # @option options [Symbol] :acl (private) A canned access
251
+ # control policy. Valid values are:
252
+ #
253
+ # * +:private+
254
+ # * +:public_read+
255
+ # * +:public_read_write+
256
+ # * +:authenticated_read+
257
+ # * +:bucket_owner_read+
258
+ # * +:bucket_owner_full_control+
259
+ #
260
+ # @option options [Symbol] :storage_class Controls whether
261
+ # Reduced Redundancy Storage is enabled for the object.
262
+ # Valid values are +:standard+ (the default) or
263
+ # +:reduced_redundancy+.
264
+ #
265
+ # @option options :cache_control [String] Can be used to specify
266
+ # caching behavior. See
267
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
268
+ #
269
+ # @option options :content_disposition [String] Specifies
270
+ # presentational information for the object. See
271
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec19.5.1
272
+ #
273
+ # @option options :content_encoding [String] Specifies what
274
+ # content encodings have been applied to the object and thus
275
+ # what decoding mechanisms must be applied to obtain the
276
+ # media-type referenced by the +Content-Type+ header field.
277
+ # See
278
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
279
+ #
280
+ # @option options :content_type A standard MIME type
281
+ # describing the format of the object data.
282
+ #
283
+ # @option options [Symbol] :server_side_encryption (nil) If this
284
+ # option is set, the object will be stored using server side
285
+ # encryption. The only valid value is +:aes256+, which
286
+ # specifies that the object should be stored using the AES
287
+ # encryption algorithm with 256 bit keys. By default, this
288
+ # option uses the value of the +:s3_server_side_encryption+
289
+ # option in the current configuration; for more information,
290
+ # see {AWS.config}.
291
+ #
292
+ # @return [S3Object, ObjectVersion] If the bucket has versioning
293
+ # enabled, returns the {ObjectVersion} representing the
294
+ # version that was uploaded. If versioning is disabled,
295
+ # returns self.
296
+ def write(options_or_data = nil, options = nil)
297
+
298
+ (data_options, put_options) =
299
+ compute_put_options(options_or_data, options)
300
+
301
+ add_configured_write_options(put_options)
302
+
303
+ if use_multipart?(data_options, put_options)
304
+ put_options.delete(:multipart_threshold)
305
+ multipart_upload(put_options) do |upload|
306
+ each_part(data_options, put_options) do |part|
307
+ upload.add_part(part)
308
+ end
309
+ end
310
+ else
311
+ opts = { :bucket_name => bucket.name, :key => key }
312
+ resp = client.put_object(opts.merge(put_options).merge(data_options))
313
+ if resp.version_id
314
+ ObjectVersion.new(self, resp.version_id)
315
+ else
316
+ self
317
+ end
318
+ end
319
+ end
320
+
321
+ # Performs a multipart upload. Use this if you have specific
322
+ # needs for how the upload is split into parts, or if you want
323
+ # to have more control over how the failure of an individual
324
+ # part upload is handled. Otherwise, {#write} is much simpler
325
+ # to use.
326
+ #
327
+ # @example Uploading an object in two parts
328
+ # bucket.objects.myobject.multipart_upload do |upload|
329
+ # upload.add_part("a" * 5242880)
330
+ # upload.add_part("b" * 2097152)
331
+ # end
332
+ #
333
+ # @example Uploading parts out of order
334
+ # bucket.objects.myobject.multipart_upload do |upload|
335
+ # upload.add_part("b" * 2097152, :part_number => 2)
336
+ # upload.add_part("a" * 5242880, :part_number => 1)
337
+ # end
338
+ #
339
+ # @example Aborting an upload after parts have been added
340
+ # bucket.objects.myobject.multipart_upload do |upload|
341
+ # upload.add_part("b" * 2097152, :part_number => 2)
342
+ # upload.abort
343
+ # end
344
+ #
345
+ # @example Starting an upload and completing it later by ID
346
+ # upload = bucket.objects.myobject.multipart_upload
347
+ # upload.add_part("a" * 5242880)
348
+ # upload.add_part("b" * 2097152)
349
+ # id = upload.id
350
+ #
351
+ # # later or in a different process
352
+ # upload = bucket.objects.myobject.multipart_uploads[id]
353
+ # upload.complete(:remote_parts)
354
+ #
355
+ # @yieldparam [MultipartUpload] upload A handle to the upload.
356
+ # {MultipartUpload#close} is called in an +ensure+ clause so
357
+ # that the upload will always be either completed or
358
+ # aborted.
359
+ #
360
+ # @param [Hash] options Options for the upload.
361
+ #
362
+ # @option options [Hash] :metadata A hash of metadata to be
363
+ # included with the object. These will be sent to S3 as
364
+ # headers prefixed with +x-amz-meta+. Each name, value pair
365
+ # must conform to US-ASCII.
366
+ #
367
+ # @option options [Symbol] :acl (private) A canned access
368
+ # control policy. Valid values are:
369
+ #
370
+ # * +:private+
371
+ # * +:public_read+
372
+ # * +:public_read_write+
373
+ # * +:authenticated_read+
374
+ # * +:bucket_owner_read+
375
+ # * +:bucket_owner_full_control+
376
+ #
377
+ # @option options [Boolean] :reduced_redundancy (false) If true,
378
+ # Reduced Redundancy Storage will be enabled for the uploaded
379
+ # object.
380
+ #
381
+ # @option options :cache_control [String] Can be used to specify
382
+ # caching behavior. See
383
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
384
+ #
385
+ # @option options :content_disposition [String] Specifies
386
+ # presentational information for the object. See
387
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec19.5.1
388
+ #
389
+ # @option options :content_encoding [String] Specifies what
390
+ # content encodings have been applied to the object and thus
391
+ # what decoding mechanisms must be applied to obtain the
392
+ # media-type referenced by the +Content-Type+ header field.
393
+ # See
394
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
395
+ #
396
+ # @option options :content_type A standard MIME type
397
+ # describing the format of the object data.
398
+ #
399
+ # @option options [Symbol] :server_side_encryption (nil) If this
400
+ # option is set, the object will be stored using server side
401
+ # encryption. The only valid value is +:aes256+, which
402
+ # specifies that the object should be stored using the AES
403
+ # encryption algorithm with 256 bit keys. By default, this
404
+ # option uses the value of the +:s3_server_side_encryption+
405
+ # option in the current configuration; for more information,
406
+ # see {AWS.config}.
407
+ #
408
+ # @return [S3Object, ObjectVersion] If the bucket has versioning
409
+ # enabled, returns the {ObjectVersion} representing the
410
+ # version that was uploaded. If versioning is disabled,
411
+ # returns self.
412
+ def multipart_upload(options = {})
413
+
414
+ options = options.dup
415
+ add_configured_write_options(options)
416
+
417
+ upload = multipart_uploads.create(options)
418
+
419
+ if block_given?
420
+ begin
421
+ yield(upload)
422
+ upload.close
423
+ rescue
424
+ upload.abort
425
+ end
426
+ else
427
+ upload
428
+ end
429
+ end
430
+
431
+ # @example Abort any in-progress uploads for the object:
432
+ #
433
+ # object.multipart_uploads.each(&:abort)
434
+ #
435
+ # @return [ObjectUploadCollection] Returns an object representing the
436
+ # collection of uploads that are in progress for this object.
437
+ def multipart_uploads
438
+ ObjectUploadCollection.new(self)
439
+ end
440
+
441
+ # Moves an object to a new key.
442
+ #
443
+ # This works by copying the object to a new key and then
444
+ # deleting the old object. This function returns the
445
+ # new object once this is done.
446
+ #
447
+ # bucket = s3.buckets['old-bucket']
448
+ # old_obj = bucket.objects['old-key']
449
+ #
450
+ # # renaming an object returns a new object
451
+ # new_obj = old_obj.move_to('new-key')
452
+ #
453
+ # old_obj.key #=> 'old-key'
454
+ # old_obj.exists? #=> false
455
+ #
456
+ # new_obj.key #=> 'new-key'
457
+ # new_obj.exists? #=> true
458
+ #
459
+ # If you need to move an object to a different bucket, pass
460
+ # +:bucket+ or +:bucket_name+.
461
+ #
462
+ # obj = s3.buckets['old-bucket'].objects['old-key]
463
+ # obj.move_to('new-key', :bucket_name => 'new_bucket')
464
+ #
465
+ # If the copy succeeds, but the then the delete fails, an error
466
+ # will be raised.
467
+ #
468
+ # @param [String] target The key to move this object to.
469
+ #
470
+ # @param [Hash] options
471
+ #
472
+ # @option (see #copy_to)
473
+ #
474
+ # @return [S3Object] Returns a new object with the new key.
475
+ #
476
+ def move_to target, options = {}
477
+ copy = copy_to(target, options)
478
+ delete
479
+ copy
480
+ end
481
+ alias_method :rename_to, :move_to
482
+
483
+ # Copies data from one S3 object to another.
484
+ #
485
+ # S3 handles the copy so the clients does not need to fetch the data
486
+ # and upload it again. You can also change the storage class and
487
+ # metadata of the object when copying.
488
+ #
489
+ # @note This operation does not copy the ACL, storage class
490
+ # (standard vs. reduced redundancy) or server side encryption
491
+ # setting from the source object. If you don't specify any of
492
+ # these options when copying, the object will have the default
493
+ # values as described below.
494
+ #
495
+ # @param [Mixed] source
496
+ #
497
+ # @param [Hash] options
498
+ #
499
+ # @option options [String] :bucket_name The name of the bucket
500
+ # the source object can be found in. Defaults to the current
501
+ # object's bucket.
502
+ #
503
+ # @option options [Bucket] :bucket The bucket the source object
504
+ # can be found in. Defaults to the current object's bucket.
505
+ #
506
+ # @option options [Hash] :metadata A hash of metadata to save
507
+ # with the copied object. Each name, value pair must conform
508
+ # to US-ASCII. When blank, the sources metadata is copied.
509
+ #
510
+ # @option options [String] :content_type The content type of
511
+ # the copied object. Defaults to the source object's content
512
+ # type.
513
+ #
514
+ # @option options [Boolean] :reduced_redundancy (false) If true the
515
+ # object is stored with reduced redundancy in S3 for a lower cost.
516
+ #
517
+ # @option options [String] :version_id (nil) Causes the copy to
518
+ # read a specific version of the source object.
519
+ #
520
+ # @option options [Symbol] :acl (private) A canned access
521
+ # control policy. Valid values are:
522
+ #
523
+ # * +:private+
524
+ # * +:public_read+
525
+ # * +:public_read_write+
526
+ # * +:authenticated_read+
527
+ # * +:bucket_owner_read+
528
+ # * +:bucket_owner_full_control+
529
+ #
530
+ # @option options [Symbol] :server_side_encryption (nil) If this
531
+ # option is set, the object will be stored using server side
532
+ # encryption. The only valid value is +:aes256+, which
533
+ # specifies that the object should be stored using the AES
534
+ # encryption algorithm with 256 bit keys. By default, this
535
+ # option uses the value of the +:s3_server_side_encryption+
536
+ # option in the current configuration; for more information,
537
+ # see {AWS.config}.
538
+ #
539
+ # @option options :cache_control [String] Can be used to specify
540
+ # caching behavior. See
541
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
542
+ #
543
+ # @return [nil]
544
+ def copy_from source, options = {}
545
+
546
+ copy_opts = { :bucket_name => bucket.name, :key => key }
547
+
548
+ copy_opts[:copy_source] = case source
549
+ when S3Object
550
+ "#{source.bucket.name}/#{source.key}"
551
+ when ObjectVersion
552
+ copy_opts[:version_id] = source.version_id
553
+ "#{source.object.bucket.name}/#{source.object.key}"
554
+ else
555
+ case
556
+ when options[:bucket] then "#{options[:bucket].name}/#{source}"
557
+ when options[:bucket_name] then "#{options[:bucket_name]}/#{source}"
558
+ else "#{self.bucket.name}/#{source}"
559
+ end
560
+ end
561
+
562
+ copy_opts[:metadata_directive] = 'COPY'
563
+
564
+ if options[:metadata]
565
+ copy_opts[:metadata] = options[:metadata]
566
+ copy_opts[:metadata_directive] = 'REPLACE'
567
+ end
568
+
569
+ if options[:content_type]
570
+ copy_opts[:content_type] = options[:content_type]
571
+ copy_opts[:metadata_directive] = "REPLACE"
572
+ end
573
+
574
+ copy_opts[:acl] = options[:acl] if options[:acl]
575
+ copy_opts[:version_id] = options[:version_id] if options[:version_id]
576
+ copy_opts[:server_side_encryption] =
577
+ options[:server_side_encryption] if
578
+ options.key?(:server_side_encryption)
579
+ copy_opts[:cache_control] = options[:cache_control] if
580
+ options[:cache_control]
581
+ add_configured_write_options(copy_opts)
582
+
583
+ if options[:reduced_redundancy]
584
+ copy_opts[:storage_class] = 'REDUCED_REDUNDANCY'
585
+ else
586
+ copy_opts[:storage_class] = 'STANDARD'
587
+ end
588
+
589
+ client.copy_object(copy_opts)
590
+
591
+ nil
592
+
593
+ end
594
+
595
+ # Copies data from the current object to another object in S3.
596
+ #
597
+ # S3 handles the copy so the client does not need to fetch the data
598
+ # and upload it again. You can also change the storage class and
599
+ # metadata of the object when copying.
600
+ #
601
+ # @note This operation does not copy the ACL, storage class
602
+ # (standard vs. reduced redundancy) or server side encryption
603
+ # setting from this object to the new object. If you don't
604
+ # specify any of these options when copying, the new object
605
+ # will have the default values as described below.
606
+ #
607
+ # @param [S3Object,String] target An S3Object, or a string key of
608
+ # and object to copy to.
609
+ #
610
+ # @param [Hash] options
611
+ #
612
+ # @option options [String] :bucket_name The name of the bucket
613
+ # the object should be copied into. Defaults to the current object's
614
+ # bucket.
615
+ #
616
+ # @option options [Bucket] :bucket The bucket the target object
617
+ # should be copied into. Defaults to the current object's bucket.
618
+ #
619
+ # @option options [Hash] :metadata A hash of metadata to save
620
+ # with the copied object. Each name, value pair must conform
621
+ # to US-ASCII. When blank, the sources metadata is copied.
622
+ #
623
+ # @option options [Boolean] :reduced_redundancy (false) If true
624
+ # the object is stored with reduced redundancy in S3 for a
625
+ # lower cost.
626
+ #
627
+ # @option options [Symbol] :acl (private) A canned access
628
+ # control policy. Valid values are:
629
+ #
630
+ # * +:private+
631
+ # * +:public_read+
632
+ # * +:public_read_write+
633
+ # * +:authenticated_read+
634
+ # * +:bucket_owner_read+
635
+ # * +:bucket_owner_full_control+
636
+ #
637
+ # @option options [Symbol] :server_side_encryption (nil) If this
638
+ # option is set, the object will be stored using server side
639
+ # encryption. The only valid value is +:aes256+, which
640
+ # specifies that the object should be stored using the AES
641
+ # encryption algorithm with 256 bit keys. By default, this
642
+ # option uses the value of the +:s3_server_side_encryption+
643
+ # option in the current configuration; for more information,
644
+ # see {AWS.config}.
645
+ #
646
+ # @return [S3Object] Returns the copy (target) object.
647
+ #
648
+ def copy_to target, options = {}
649
+
650
+ unless target.is_a?(S3Object)
651
+
652
+ bucket = case
653
+ when options[:bucket] then options[:bucket]
654
+ when options[:bucket_name]
655
+ Bucket.new(options[:bucket_name], :config => config)
656
+ else self.bucket
657
+ end
658
+
659
+ target = S3Object.new(bucket, target)
660
+ end
661
+
662
+ copy_opts = options.dup
663
+ copy_opts.delete(:bucket)
664
+ copy_opts.delete(:bucket_name)
665
+
666
+ target.copy_from(self, copy_opts)
667
+ target
668
+
669
+ end
670
+
671
+ # Fetches the object data from S3.
672
+ #
673
+ # @example Reading data as a string
674
+ # object.write('some data')
675
+ # object.read
676
+ # #=> 'some data'
677
+ #
678
+ # @param [Hash] options
679
+ # @option options [String] :version_id Reads data from a
680
+ # specific version of this object.
681
+ #
682
+ # @option options [Time] :if_unmodified_since If specified, the
683
+ # method will raise
684
+ # <tt>AWS::S3::Errors::PreconditionFailed</tt> unless the
685
+ # object has not been modified since the given time.
686
+ #
687
+ # @option options [Time] :if_modified_since If specified, the
688
+ # method will raise <tt>AWS::S3::Errors::NotModified</tt> if
689
+ # the object has not been modified since the given time.
690
+ #
691
+ # @option options [String] :if_match If specified, the method
692
+ # will raise <tt>AWS::S3::Errors::PreconditionFailed</tt>
693
+ # unless the object ETag matches the provided value.
694
+ #
695
+ # @option options [String] :if_none_match If specified, the
696
+ # method will raise <tt>AWS::S3::Errors::NotModified</tt> if
697
+ # the object ETag matches the provided value.
698
+ #
699
+ # @option options [Range] :range A byte range to read data from
700
+ #
701
+ def read(options = {}, &blk)
702
+ options[:bucket_name] = bucket.name
703
+ options[:key] = key
704
+ client.get_object(options).data[:data]
705
+ end
706
+
707
+ # @private
708
+ module ACLProxy
709
+
710
+ attr_accessor :object
711
+
712
+ def change
713
+ yield(self)
714
+ object.acl = self
715
+ end
716
+
717
+ end
718
+
719
+ # Returns the object's access control list. This will be an
720
+ # instance of AccessControlList, plus an additional +change+
721
+ # method:
722
+ #
723
+ # object.acl.change do |acl|
724
+ # # remove any grants to someone other than the bucket owner
725
+ # owner_id = object.bucket.owner.id
726
+ # acl.grants.reject! do |g|
727
+ # g.grantee.canonical_user_id != owner_id
728
+ # end
729
+ # end
730
+ #
731
+ # Note that changing the ACL is not an atomic operation; it
732
+ # fetches the current ACL, yields it to the block, and then
733
+ # sets it again. Therefore, it's possible that you may
734
+ # overwrite a concurrent update to the ACL using this
735
+ # method.
736
+ #
737
+ # @return [AccessControlList]
738
+ #
739
+ def acl
740
+
741
+ resp = client.get_object_acl(:bucket_name => bucket.name, :key => key)
742
+
743
+ acl = AccessControlList.new(resp.data)
744
+ acl.extend ACLProxy
745
+ acl.object = self
746
+ acl
747
+
748
+ end
749
+
750
+ # Sets the object's access control list. +acl+ can be:
751
+ # * An XML policy as a string (which is passed to S3 uninterpreted)
752
+ # * An AccessControlList object
753
+ # * Any object that responds to +to_xml+
754
+ # * Any Hash that is acceptable as an argument to
755
+ # AccessControlList#initialize.
756
+ #
757
+ # @param (see Bucket#acl=)
758
+ # @return [nil]
759
+ def acl=(acl)
760
+ client.set_object_acl(
761
+ :bucket_name => bucket.name,
762
+ :key => key,
763
+ :acl => acl)
764
+ nil
765
+ end
766
+
767
+ # @private
768
+ REQUEST_PARAMETERS = Request.query_parameters.map do |p|
769
+ p.tr("-","_").to_sym
770
+ end
771
+
772
+ # Generates a presigned URL for an operation on this object.
773
+ # This URL can be used by a regular HTTP client to perform the
774
+ # desired operation without credentials and without changing
775
+ # the permissions of the object.
776
+ #
777
+ # @example Generate a url to read an object
778
+ # bucket.objects.myobject.url_for(:read)
779
+ #
780
+ # @example Generate a url to delete an object
781
+ # bucket.objects.myobject.url_for(:delete)
782
+ #
783
+ # @example Override response headers for reading an object
784
+ # object = bucket.objects.myobject
785
+ # url = object.url_for(:read, :response_content_type => "application/json")
786
+ #
787
+ # @example Generate a url that expires in 10 minutes
788
+ # bucket.objects.myobject.url_for(:read, :expires => 10*60)
789
+ #
790
+ # @param [Symbol, String] method The HTTP verb or object
791
+ # method for which the returned URL will be valid. Valid
792
+ # values:
793
+ #
794
+ # * +:get+ or +:read+
795
+ # * +:put+ or +:write+
796
+ # * +:delete+
797
+ #
798
+ # @param [Hash] options Additional options for generating the URL.
799
+ #
800
+ # @option options :expires Sets the expiration time of the
801
+ # URL; after this time S3 will return an error if the URL is
802
+ # used. This can be an integer (to specify the number of
803
+ # seconds after the current time), a string (which is parsed
804
+ # as a date using Time#parse), a Time, or a DateTime object.
805
+ # This option defaults to one hour after the current time.
806
+ #
807
+ # @option options [Boolean] :secure (true) Whether to generate a
808
+ # secure (HTTPS) URL or a plain HTTP url.
809
+ #
810
+ # @option options [String] :response_content_type Sets the
811
+ # Content-Type header of the response when performing an
812
+ # HTTP GET on the returned URL.
813
+ #
814
+ # @option options [String] :response_content_language Sets the
815
+ # Content-Language header of the response when performing an
816
+ # HTTP GET on the returned URL.
817
+ #
818
+ # @option options [String] :response_expires Sets the Expires
819
+ # header of the response when performing an HTTP GET on the
820
+ # returned URL.
821
+ #
822
+ # @option options [String] :response_cache_control Sets the
823
+ # Cache-Control header of the response when performing an
824
+ # HTTP GET on the returned URL.
825
+ #
826
+ # @option options [String] :response_content_disposition Sets
827
+ # the Content-Disposition header of the response when
828
+ # performing an HTTP GET on the returned URL.
829
+ #
830
+ # @option options [String] :response_content_encoding Sets the
831
+ # Content-Encoding header of the response when performing an
832
+ # HTTP GET on the returned URL.
833
+ # @return [URI::HTTP, URI::HTTPS]
834
+ def url_for(method, options = {})
835
+ req = request_for_signing(options)
836
+
837
+ method = http_method(method)
838
+ expires = expiration_timestamp(options[:expires])
839
+ req.add_param("AWSAccessKeyId", config.signer.access_key_id)
840
+ req.add_param("versionId", options[:version_id]) if options[:version_id]
841
+ req.add_param("Signature", signature(method, expires, req))
842
+ req.add_param("Expires", expires)
843
+ req.add_param("x-amz-security-token", config.signer.session_token) if
844
+ config.signer.session_token
845
+
846
+ build_uri(options[:secure] != false, req)
847
+ end
848
+
849
+ # Generates a public (not authenticated) URL for the object.
850
+ #
851
+ # @param [Hash] options Options for generating the URL.
852
+ #
853
+ # @option options [Boolean] :secure Whether to generate a
854
+ # secure (HTTPS) URL or a plain HTTP url.
855
+ #
856
+ # @return [URI::HTTP, URI::HTTPS]
857
+ #
858
+ def public_url(options = {})
859
+ req = request_for_signing(options)
860
+ build_uri(options[:secure] != false, req)
861
+ end
862
+
863
+ # Generates fields for a presigned POST to this object. This
864
+ # method adds a constraint that the key must match the key of
865
+ # this object. All options are sent to the PresignedPost
866
+ # constructor.
867
+ #
868
+ # @see PresignedPost
869
+ # @return [PresignedPost]
870
+ def presigned_post(options = {})
871
+ PresignedPost.new(bucket, options.merge(:key => key))
872
+ end
873
+
874
+ # @note Changing the storage class of an object incurs a COPY
875
+ # operation.
876
+ #
877
+ # Changes the storage class of the object to enable or disable
878
+ # Reduced Redundancy Storage (RRS).
879
+ #
880
+ # @param [true,false] value If this is true, the object will be
881
+ # copied in place and stored with reduced redundancy at a
882
+ # lower cost. Otherwise, the object will be copied and stored
883
+ # with the standard storage class.
884
+ #
885
+ # @return [true,false] The +value+ parameter.
886
+ def reduced_redundancy= value
887
+ copy_from(key, :reduced_redundancy => value)
888
+ value
889
+ end
890
+
891
+ # @private
892
+ private
893
+ def build_uri(secure, request)
894
+ uri_class = secure ? URI::HTTPS : URI::HTTP
895
+ uri_class.build(:host => request.host,
896
+ :path => request.path,
897
+ :query => request.querystring)
898
+ end
899
+
900
+ # @private
901
+ private
902
+ def signature(method, expires, request)
903
+
904
+ parts = []
905
+ parts << method
906
+ parts << ""
907
+ parts << ""
908
+ parts << expires
909
+ parts << "x-amz-security-token:#{config.signer.session_token}" if
910
+ config.signer.session_token
911
+ parts << request.canonicalized_resource
912
+
913
+ string_to_sign = parts.join("\n")
914
+
915
+ config.signer.sign(string_to_sign, "sha1")
916
+
917
+ end
918
+
919
+ # @private
920
+ private
921
+ def expiration_timestamp(input)
922
+ case input
923
+ when Time
924
+ expires = input.to_i
925
+ when DateTime
926
+ expires = Time.parse(input.to_s).to_i
927
+ when Integer
928
+ expires = (Time.now + input).to_i
929
+ when String
930
+ expires = Time.parse(input).to_i
931
+ else
932
+ expires = (Time.now + 60*60).to_i
933
+ end
934
+ end
935
+
936
+ # @private
937
+ private
938
+ def http_method(input)
939
+ symbol = case input
940
+ when :read then :get
941
+ when :write then :put
942
+ else
943
+ input
944
+ end
945
+ symbol.to_s.upcase
946
+ end
947
+
948
+ # @private
949
+ private
950
+ def request_for_signing(options)
951
+ req = Request.new
952
+
953
+ req.bucket = bucket.name
954
+ req.key = key
955
+ req.host = config.s3_endpoint
956
+
957
+ REQUEST_PARAMETERS.each do |param|
958
+ req.add_param(param.to_s.tr("_","-"),
959
+ options[param]) if options.key?(param)
960
+ end
961
+
962
+ req
963
+ end
964
+
965
+ # @private
966
+ private
967
+ def compute_put_options(options_or_data, options)
968
+ put_opts = {}
969
+
970
+ if options
971
+
972
+ raise ArgumentError.new("Object data passed twice (argument and file path)") if
973
+ options[:file]
974
+
975
+ raise ArgumentError.new("Object data passed twice (argument and option)") if
976
+ options[:data]
977
+
978
+ [{ :data => options_or_data }, options]
979
+ elsif options_or_data.kind_of?(Hash)
980
+ if file = options_or_data[:file]
981
+ data_options = { :file => file }
982
+ else
983
+ data_options = { :data => options_or_data[:data] || "" }
984
+ end
985
+
986
+ [data_options, options_or_data]
987
+ else
988
+ [{ :data => options_or_data || "" }, {}]
989
+ end
990
+ end
991
+
992
+ private
993
+ def add_configured_write_options(options)
994
+ options[:server_side_encryption] =
995
+ config.s3_server_side_encryption unless
996
+ options.key?(:server_side_encryption)
997
+ options.delete(:server_side_encryption) if
998
+ options[:server_side_encryption] == nil
999
+ end
1000
+
1001
+ # @private
1002
+ private
1003
+ def use_multipart?(data_options, options)
1004
+ threshold = options[:multipart_threshold] ||
1005
+ config.s3_multipart_threshold
1006
+
1007
+ !options[:single_request] and
1008
+ size = content_length_from(data_options.merge(options)) and
1009
+ size > threshold
1010
+ end
1011
+
1012
+ # @private
1013
+ private
1014
+ def each_part(data_options, options)
1015
+ total_size = content_length_from(data_options.merge(options))
1016
+ part_size = optimal_part_size(total_size, options)
1017
+ stream = data_stream_from(data_options.merge(options))
1018
+ while !stream.eof?
1019
+ yield(stream.read(part_size))
1020
+ end
1021
+ end
1022
+
1023
+ # @private
1024
+ private
1025
+ def optimal_part_size(total_size, options)
1026
+ maximum_parts = config.s3_multipart_max_parts
1027
+ min_size = options[:multipart_min_part_size] ||
1028
+ config.s3_multipart_min_part_size
1029
+
1030
+ [(total_size.to_f / maximum_parts.to_f).ceil,
1031
+ min_size].max.to_i
1032
+ end
1033
+
1034
+ end
1035
+
1036
+ end
1037
+ end