aws-sdk-v1-reinteractive 1.67.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (569) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/LICENSE.txt +12 -0
  4. data/README.md +364 -0
  5. data/bin/aws-rb +179 -0
  6. data/ca-bundle.crt +3554 -0
  7. data/endpoints.json +1838 -0
  8. data/lib/aws-sdk-v1.rb +2 -0
  9. data/lib/aws.rb +14 -0
  10. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +1083 -0
  11. data/lib/aws/api_config/CloudFormation-2010-05-15.yml +372 -0
  12. data/lib/aws/api_config/CloudFront-2013-05-12.yml +2448 -0
  13. data/lib/aws/api_config/CloudFront-2013-08-26.yml +2599 -0
  14. data/lib/aws/api_config/CloudFront-2013-09-27.yml +2765 -0
  15. data/lib/aws/api_config/CloudFront-2013-11-11.yml +2886 -0
  16. data/lib/aws/api_config/CloudFront-2013-11-22.yml +2918 -0
  17. data/lib/aws/api_config/CloudFront-2014-01-31.yml +2934 -0
  18. data/lib/aws/api_config/CloudFront-2014-05-31.yml +3100 -0
  19. data/lib/aws/api_config/CloudFront-2014-10-21.yml +3290 -0
  20. data/lib/aws/api_config/CloudFront-2014-11-06.yml +3547 -0
  21. data/lib/aws/api_config/CloudSearch-2011-02-01.yml +681 -0
  22. data/lib/aws/api_config/CloudSearch-2013-01-01.yml +1184 -0
  23. data/lib/aws/api_config/CloudTrail-2013-11-01.yml +130 -0
  24. data/lib/aws/api_config/CloudWatch-2010-08-01.yml +433 -0
  25. data/lib/aws/api_config/DataPipeline-2012-10-29.yml +422 -0
  26. data/lib/aws/api_config/DirectConnect-2012-10-25.yml +735 -0
  27. data/lib/aws/api_config/DynamoDB-2011-12-05.yml +1168 -0
  28. data/lib/aws/api_config/DynamoDB-2012-08-10.yml +2105 -0
  29. data/lib/aws/api_config/EC2-2013-08-15.yml +4708 -0
  30. data/lib/aws/api_config/EC2-2013-10-01.yml +4726 -0
  31. data/lib/aws/api_config/EC2-2013-10-15.yml +4651 -0
  32. data/lib/aws/api_config/EC2-2014-02-01.yml +4755 -0
  33. data/lib/aws/api_config/EC2-2014-05-01.yml +4812 -0
  34. data/lib/aws/api_config/EC2-2014-09-01.yml +4826 -0
  35. data/lib/aws/api_config/EC2-2014-10-01.yml +4969 -0
  36. data/lib/aws/api_config/ELB-2012-06-01.yml +785 -0
  37. data/lib/aws/api_config/EMR-2009-03-31.yml +972 -0
  38. data/lib/aws/api_config/ElastiCache-2013-06-15.yml +1188 -0
  39. data/lib/aws/api_config/ElastiCache-2014-03-24.yml +1375 -0
  40. data/lib/aws/api_config/ElastiCache-2014-07-15.yml +1385 -0
  41. data/lib/aws/api_config/ElastiCache-2014-09-30.yml +1426 -0
  42. data/lib/aws/api_config/ElasticBeanstalk-2010-12-01.yml +854 -0
  43. data/lib/aws/api_config/ElasticTranscoder-2012-09-25.yml +4179 -0
  44. data/lib/aws/api_config/Glacier-2012-06-01.yml +649 -0
  45. data/lib/aws/api_config/IAM-2010-05-08.yml +1912 -0
  46. data/lib/aws/api_config/ImportExport-2010-06-01.yml +109 -0
  47. data/lib/aws/api_config/Kinesis-2013-12-02.yml +275 -0
  48. data/lib/aws/api_config/OpsWorks-2013-02-18.yml +2324 -0
  49. data/lib/aws/api_config/RDS-2013-05-15.yml +2464 -0
  50. data/lib/aws/api_config/RDS-2013-09-09.yml +2640 -0
  51. data/lib/aws/api_config/RDS-2014-09-01.yml +2796 -0
  52. data/lib/aws/api_config/Redshift-2012-12-01.yml +2577 -0
  53. data/lib/aws/api_config/Route53-2012-12-12.yml +547 -0
  54. data/lib/aws/api_config/Route53-2013-04-01.yml +1093 -0
  55. data/lib/aws/api_config/SNS-2010-03-31.yml +448 -0
  56. data/lib/aws/api_config/SQS-2012-11-05.yml +404 -0
  57. data/lib/aws/api_config/STS-2011-06-15.yml +151 -0
  58. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +306 -0
  59. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +346 -0
  60. data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +2426 -0
  61. data/lib/aws/api_config/StorageGateway-2012-06-30.yml +748 -0
  62. data/lib/aws/api_config/StorageGateway-2013-06-30.yml +1025 -0
  63. data/lib/aws/api_config/Support-2013-04-15.yml +489 -0
  64. data/lib/aws/auto_scaling.rb +163 -0
  65. data/lib/aws/auto_scaling/activity.rb +102 -0
  66. data/lib/aws/auto_scaling/activity_collection.rb +81 -0
  67. data/lib/aws/auto_scaling/client.rb +48 -0
  68. data/lib/aws/auto_scaling/config.rb +18 -0
  69. data/lib/aws/auto_scaling/errors.rb +22 -0
  70. data/lib/aws/auto_scaling/group.rb +421 -0
  71. data/lib/aws/auto_scaling/group_collection.rb +96 -0
  72. data/lib/aws/auto_scaling/group_options.rb +155 -0
  73. data/lib/aws/auto_scaling/instance.rb +192 -0
  74. data/lib/aws/auto_scaling/instance_collection.rb +63 -0
  75. data/lib/aws/auto_scaling/launch_configuration.rb +179 -0
  76. data/lib/aws/auto_scaling/launch_configuration_collection.rb +177 -0
  77. data/lib/aws/auto_scaling/notification_configuration.rb +89 -0
  78. data/lib/aws/auto_scaling/notification_configuration_collection.rb +183 -0
  79. data/lib/aws/auto_scaling/scaling_policy.rb +142 -0
  80. data/lib/aws/auto_scaling/scaling_policy_collection.rb +72 -0
  81. data/lib/aws/auto_scaling/scaling_policy_options.rb +65 -0
  82. data/lib/aws/auto_scaling/scheduled_action.rb +141 -0
  83. data/lib/aws/auto_scaling/scheduled_action_collection.rb +202 -0
  84. data/lib/aws/auto_scaling/tag.rb +59 -0
  85. data/lib/aws/auto_scaling/tag_collection.rb +114 -0
  86. data/lib/aws/cloud_formation.rb +272 -0
  87. data/lib/aws/cloud_formation/client.rb +48 -0
  88. data/lib/aws/cloud_formation/config.rb +18 -0
  89. data/lib/aws/cloud_formation/errors.rb +22 -0
  90. data/lib/aws/cloud_formation/stack.rb +266 -0
  91. data/lib/aws/cloud_formation/stack_collection.rb +232 -0
  92. data/lib/aws/cloud_formation/stack_event.rb +73 -0
  93. data/lib/aws/cloud_formation/stack_event_collection.rb +47 -0
  94. data/lib/aws/cloud_formation/stack_options.rb +72 -0
  95. data/lib/aws/cloud_formation/stack_output.rb +53 -0
  96. data/lib/aws/cloud_formation/stack_resource.rb +117 -0
  97. data/lib/aws/cloud_formation/stack_resource_collection.rb +83 -0
  98. data/lib/aws/cloud_formation/stack_resource_summary_collection.rb +64 -0
  99. data/lib/aws/cloud_formation/stack_summary_collection.rb +123 -0
  100. data/lib/aws/cloud_front.rb +72 -0
  101. data/lib/aws/cloud_front/client.rb +65 -0
  102. data/lib/aws/cloud_front/config.rb +18 -0
  103. data/lib/aws/cloud_front/errors.rb +22 -0
  104. data/lib/aws/cloud_search.rb +73 -0
  105. data/lib/aws/cloud_search/client.rb +40 -0
  106. data/lib/aws/cloud_search/config.rb +18 -0
  107. data/lib/aws/cloud_search/errors.rb +22 -0
  108. data/lib/aws/cloud_trail.rb +72 -0
  109. data/lib/aws/cloud_trail/client.rb +35 -0
  110. data/lib/aws/cloud_trail/config.rb +18 -0
  111. data/lib/aws/cloud_trail/errors.rb +22 -0
  112. data/lib/aws/cloud_watch.rb +118 -0
  113. data/lib/aws/cloud_watch/alarm.rb +293 -0
  114. data/lib/aws/cloud_watch/alarm_collection.rb +153 -0
  115. data/lib/aws/cloud_watch/alarm_history_item.rb +50 -0
  116. data/lib/aws/cloud_watch/alarm_history_item_collection.rb +84 -0
  117. data/lib/aws/cloud_watch/client.rb +40 -0
  118. data/lib/aws/cloud_watch/config.rb +18 -0
  119. data/lib/aws/cloud_watch/errors.rb +22 -0
  120. data/lib/aws/cloud_watch/metric.rb +135 -0
  121. data/lib/aws/cloud_watch/metric_alarm_collection.rb +160 -0
  122. data/lib/aws/cloud_watch/metric_collection.rb +129 -0
  123. data/lib/aws/cloud_watch/metric_statistics.rb +69 -0
  124. data/lib/aws/core.rb +698 -0
  125. data/lib/aws/core/async_handle.rb +90 -0
  126. data/lib/aws/core/cacheable.rb +77 -0
  127. data/lib/aws/core/client.rb +787 -0
  128. data/lib/aws/core/collection.rb +263 -0
  129. data/lib/aws/core/collection/simple.rb +82 -0
  130. data/lib/aws/core/collection/with_limit_and_next_token.rb +71 -0
  131. data/lib/aws/core/collection/with_next_token.rb +97 -0
  132. data/lib/aws/core/configuration.rb +528 -0
  133. data/lib/aws/core/credential_providers.rb +662 -0
  134. data/lib/aws/core/data.rb +252 -0
  135. data/lib/aws/core/deprecations.rb +84 -0
  136. data/lib/aws/core/endpoints.rb +37 -0
  137. data/lib/aws/core/http/connection_pool.rb +375 -0
  138. data/lib/aws/core/http/curb_handler.rb +151 -0
  139. data/lib/aws/core/http/handler.rb +89 -0
  140. data/lib/aws/core/http/net_http_handler.rb +145 -0
  141. data/lib/aws/core/http/patch.rb +98 -0
  142. data/lib/aws/core/http/request.rb +259 -0
  143. data/lib/aws/core/http/response.rb +81 -0
  144. data/lib/aws/core/indifferent_hash.rb +88 -0
  145. data/lib/aws/core/inflection.rb +56 -0
  146. data/lib/aws/core/ini_parser.rb +42 -0
  147. data/lib/aws/core/json_client.rb +47 -0
  148. data/lib/aws/core/json_parser.rb +76 -0
  149. data/lib/aws/core/json_request_builder.rb +35 -0
  150. data/lib/aws/core/json_response_parser.rb +79 -0
  151. data/lib/aws/core/lazy_error_classes.rb +108 -0
  152. data/lib/aws/core/log_formatter.rb +428 -0
  153. data/lib/aws/core/managed_file.rb +32 -0
  154. data/lib/aws/core/meta_utils.rb +45 -0
  155. data/lib/aws/core/model.rb +62 -0
  156. data/lib/aws/core/naming.rb +30 -0
  157. data/lib/aws/core/option_grammar.rb +738 -0
  158. data/lib/aws/core/options/json_serializer.rb +82 -0
  159. data/lib/aws/core/options/validator.rb +155 -0
  160. data/lib/aws/core/options/xml_serializer.rb +118 -0
  161. data/lib/aws/core/page_result.rb +75 -0
  162. data/lib/aws/core/policy.rb +941 -0
  163. data/lib/aws/core/query_client.rb +41 -0
  164. data/lib/aws/core/query_error_parser.rb +24 -0
  165. data/lib/aws/core/query_request_builder.rb +47 -0
  166. data/lib/aws/core/query_response_parser.rb +35 -0
  167. data/lib/aws/core/region.rb +85 -0
  168. data/lib/aws/core/region_collection.rb +80 -0
  169. data/lib/aws/core/resource.rb +413 -0
  170. data/lib/aws/core/resource_cache.rb +40 -0
  171. data/lib/aws/core/response.rb +215 -0
  172. data/lib/aws/core/response_cache.rb +50 -0
  173. data/lib/aws/core/rest_error_parser.rb +24 -0
  174. data/lib/aws/core/rest_json_client.rb +40 -0
  175. data/lib/aws/core/rest_request_builder.rb +154 -0
  176. data/lib/aws/core/rest_response_parser.rb +66 -0
  177. data/lib/aws/core/rest_xml_client.rb +47 -0
  178. data/lib/aws/core/service_interface.rb +83 -0
  179. data/lib/aws/core/signers/base.rb +46 -0
  180. data/lib/aws/core/signers/cloud_front.rb +56 -0
  181. data/lib/aws/core/signers/s3.rb +159 -0
  182. data/lib/aws/core/signers/version_2.rb +72 -0
  183. data/lib/aws/core/signers/version_3.rb +86 -0
  184. data/lib/aws/core/signers/version_3_https.rb +61 -0
  185. data/lib/aws/core/signers/version_4.rb +228 -0
  186. data/lib/aws/core/signers/version_4/chunk_signed_stream.rb +191 -0
  187. data/lib/aws/core/uri_escape.rb +44 -0
  188. data/lib/aws/core/xml/frame.rb +246 -0
  189. data/lib/aws/core/xml/frame_stack.rb +85 -0
  190. data/lib/aws/core/xml/grammar.rb +307 -0
  191. data/lib/aws/core/xml/parser.rb +70 -0
  192. data/lib/aws/core/xml/root_frame.rb +65 -0
  193. data/lib/aws/core/xml/sax_handlers/libxml.rb +47 -0
  194. data/lib/aws/core/xml/sax_handlers/nokogiri.rb +56 -0
  195. data/lib/aws/core/xml/sax_handlers/ox.rb +41 -0
  196. data/lib/aws/core/xml/sax_handlers/rexml.rb +47 -0
  197. data/lib/aws/core/xml/stub.rb +123 -0
  198. data/lib/aws/data_pipeline.rb +72 -0
  199. data/lib/aws/data_pipeline/client.rb +36 -0
  200. data/lib/aws/data_pipeline/config.rb +18 -0
  201. data/lib/aws/data_pipeline/errors.rb +20 -0
  202. data/lib/aws/direct_connect.rb +73 -0
  203. data/lib/aws/direct_connect/client.rb +36 -0
  204. data/lib/aws/direct_connect/config.rb +18 -0
  205. data/lib/aws/direct_connect/errors.rb +22 -0
  206. data/lib/aws/dynamo_db.rb +230 -0
  207. data/lib/aws/dynamo_db/attribute_collection.rb +456 -0
  208. data/lib/aws/dynamo_db/batch_get.rb +213 -0
  209. data/lib/aws/dynamo_db/batch_write.rb +254 -0
  210. data/lib/aws/dynamo_db/binary.rb +35 -0
  211. data/lib/aws/dynamo_db/client.rb +129 -0
  212. data/lib/aws/dynamo_db/client/v20111205.rb +1266 -0
  213. data/lib/aws/dynamo_db/client/v20120810.rb +1409 -0
  214. data/lib/aws/dynamo_db/client_v2.rb +44 -0
  215. data/lib/aws/dynamo_db/config.rb +24 -0
  216. data/lib/aws/dynamo_db/errors.rb +20 -0
  217. data/lib/aws/dynamo_db/expectations.rb +40 -0
  218. data/lib/aws/dynamo_db/item.rb +133 -0
  219. data/lib/aws/dynamo_db/item_collection.rb +856 -0
  220. data/lib/aws/dynamo_db/item_data.rb +31 -0
  221. data/lib/aws/dynamo_db/keys.rb +41 -0
  222. data/lib/aws/dynamo_db/primary_key_element.rb +48 -0
  223. data/lib/aws/dynamo_db/resource.rb +33 -0
  224. data/lib/aws/dynamo_db/table.rb +492 -0
  225. data/lib/aws/dynamo_db/table_collection.rb +165 -0
  226. data/lib/aws/dynamo_db/types.rb +111 -0
  227. data/lib/aws/ec2.rb +428 -0
  228. data/lib/aws/ec2/attachment.rb +135 -0
  229. data/lib/aws/ec2/attachment_collection.rb +54 -0
  230. data/lib/aws/ec2/availability_zone.rb +86 -0
  231. data/lib/aws/ec2/availability_zone_collection.rb +43 -0
  232. data/lib/aws/ec2/block_device_mappings.rb +53 -0
  233. data/lib/aws/ec2/client.rb +162 -0
  234. data/lib/aws/ec2/collection.rb +36 -0
  235. data/lib/aws/ec2/config.rb +21 -0
  236. data/lib/aws/ec2/customer_gateway.rb +90 -0
  237. data/lib/aws/ec2/customer_gateway_collection.rb +73 -0
  238. data/lib/aws/ec2/dhcp_options.rb +106 -0
  239. data/lib/aws/ec2/dhcp_options_collection.rb +87 -0
  240. data/lib/aws/ec2/elastic_ip.rb +209 -0
  241. data/lib/aws/ec2/elastic_ip_collection.rb +93 -0
  242. data/lib/aws/ec2/errors.rb +32 -0
  243. data/lib/aws/ec2/export_task.rb +120 -0
  244. data/lib/aws/ec2/export_task_collection.rb +67 -0
  245. data/lib/aws/ec2/filtered_collection.rb +87 -0
  246. data/lib/aws/ec2/has_permissions.rb +44 -0
  247. data/lib/aws/ec2/image.rb +274 -0
  248. data/lib/aws/ec2/image_collection.rb +219 -0
  249. data/lib/aws/ec2/instance.rb +803 -0
  250. data/lib/aws/ec2/instance_collection.rb +403 -0
  251. data/lib/aws/ec2/internet_gateway.rb +122 -0
  252. data/lib/aws/ec2/internet_gateway/attachment.rb +78 -0
  253. data/lib/aws/ec2/internet_gateway_collection.rb +54 -0
  254. data/lib/aws/ec2/key_pair.rb +82 -0
  255. data/lib/aws/ec2/key_pair_collection.rb +99 -0
  256. data/lib/aws/ec2/network_acl.rb +256 -0
  257. data/lib/aws/ec2/network_acl/association.rb +56 -0
  258. data/lib/aws/ec2/network_acl/entry.rb +147 -0
  259. data/lib/aws/ec2/network_acl_collection.rb +64 -0
  260. data/lib/aws/ec2/network_interface.rb +237 -0
  261. data/lib/aws/ec2/network_interface/attachment.rb +100 -0
  262. data/lib/aws/ec2/network_interface_collection.rb +103 -0
  263. data/lib/aws/ec2/permission_collection.rb +174 -0
  264. data/lib/aws/ec2/region.rb +106 -0
  265. data/lib/aws/ec2/region_collection.rb +51 -0
  266. data/lib/aws/ec2/reserved_instances.rb +57 -0
  267. data/lib/aws/ec2/reserved_instances_collection.rb +40 -0
  268. data/lib/aws/ec2/reserved_instances_offering.rb +60 -0
  269. data/lib/aws/ec2/reserved_instances_offering_collection.rb +45 -0
  270. data/lib/aws/ec2/resource.rb +161 -0
  271. data/lib/aws/ec2/resource_tag_collection.rb +211 -0
  272. data/lib/aws/ec2/route_table.rb +210 -0
  273. data/lib/aws/ec2/route_table/association.rb +119 -0
  274. data/lib/aws/ec2/route_table/route.rb +121 -0
  275. data/lib/aws/ec2/route_table_collection.rb +72 -0
  276. data/lib/aws/ec2/security_group.rb +482 -0
  277. data/lib/aws/ec2/security_group/ip_permission.rb +135 -0
  278. data/lib/aws/ec2/security_group/ip_permission_collection.rb +82 -0
  279. data/lib/aws/ec2/security_group_collection.rb +133 -0
  280. data/lib/aws/ec2/snapshot.rb +143 -0
  281. data/lib/aws/ec2/snapshot_collection.rb +131 -0
  282. data/lib/aws/ec2/subnet.rb +161 -0
  283. data/lib/aws/ec2/subnet_collection.rb +119 -0
  284. data/lib/aws/ec2/tag.rb +81 -0
  285. data/lib/aws/ec2/tag_collection.rb +107 -0
  286. data/lib/aws/ec2/tagged_collection.rb +67 -0
  287. data/lib/aws/ec2/tagged_item.rb +85 -0
  288. data/lib/aws/ec2/volume.rb +185 -0
  289. data/lib/aws/ec2/volume_collection.rb +102 -0
  290. data/lib/aws/ec2/vpc.rb +224 -0
  291. data/lib/aws/ec2/vpc_collection.rb +70 -0
  292. data/lib/aws/ec2/vpc_peering_connection.rb +47 -0
  293. data/lib/aws/ec2/vpc_peering_connection_collection.rb +57 -0
  294. data/lib/aws/ec2/vpn_connection.rb +99 -0
  295. data/lib/aws/ec2/vpn_connection/telemetry.rb +49 -0
  296. data/lib/aws/ec2/vpn_connection_collection.rb +96 -0
  297. data/lib/aws/ec2/vpn_gateway.rb +123 -0
  298. data/lib/aws/ec2/vpn_gateway/attachment.rb +45 -0
  299. data/lib/aws/ec2/vpn_gateway_collection.rb +77 -0
  300. data/lib/aws/elastic_beanstalk.rb +49 -0
  301. data/lib/aws/elastic_beanstalk/client.rb +36 -0
  302. data/lib/aws/elastic_beanstalk/config.rb +18 -0
  303. data/lib/aws/elastic_beanstalk/errors.rb +22 -0
  304. data/lib/aws/elastic_transcoder.rb +29 -0
  305. data/lib/aws/elastic_transcoder/client.rb +48 -0
  306. data/lib/aws/elastic_transcoder/config.rb +18 -0
  307. data/lib/aws/elastic_transcoder/errors.rb +23 -0
  308. data/lib/aws/elasticache.rb +49 -0
  309. data/lib/aws/elasticache/client.rb +45 -0
  310. data/lib/aws/elasticache/config.rb +18 -0
  311. data/lib/aws/elasticache/errors.rb +22 -0
  312. data/lib/aws/elb.rb +66 -0
  313. data/lib/aws/elb/availability_zone_collection.rb +138 -0
  314. data/lib/aws/elb/backend_server_policy_collection.rb +139 -0
  315. data/lib/aws/elb/client.rb +35 -0
  316. data/lib/aws/elb/config.rb +18 -0
  317. data/lib/aws/elb/errors.rb +26 -0
  318. data/lib/aws/elb/instance_collection.rb +168 -0
  319. data/lib/aws/elb/listener.rb +190 -0
  320. data/lib/aws/elb/listener_collection.rb +113 -0
  321. data/lib/aws/elb/listener_opts.rb +45 -0
  322. data/lib/aws/elb/load_balancer.rb +280 -0
  323. data/lib/aws/elb/load_balancer_collection.rb +148 -0
  324. data/lib/aws/elb/load_balancer_policy.rb +93 -0
  325. data/lib/aws/elb/load_balancer_policy_collection.rb +208 -0
  326. data/lib/aws/emr.rb +87 -0
  327. data/lib/aws/emr/client.rb +35 -0
  328. data/lib/aws/emr/config.rb +18 -0
  329. data/lib/aws/emr/errors.rb +22 -0
  330. data/lib/aws/emr/instance_group.rb +138 -0
  331. data/lib/aws/emr/instance_group_collection.rb +82 -0
  332. data/lib/aws/emr/job_flow.rb +307 -0
  333. data/lib/aws/emr/job_flow_collection.rb +183 -0
  334. data/lib/aws/errors.rb +162 -0
  335. data/lib/aws/glacier.rb +79 -0
  336. data/lib/aws/glacier/archive.rb +56 -0
  337. data/lib/aws/glacier/archive_collection.rb +146 -0
  338. data/lib/aws/glacier/client.rb +49 -0
  339. data/lib/aws/glacier/config.rb +19 -0
  340. data/lib/aws/glacier/errors.rb +22 -0
  341. data/lib/aws/glacier/resource.rb +30 -0
  342. data/lib/aws/glacier/vault.rb +145 -0
  343. data/lib/aws/glacier/vault_collection.rb +75 -0
  344. data/lib/aws/glacier/vault_notification_configuration.rb +29 -0
  345. data/lib/aws/iam.rb +408 -0
  346. data/lib/aws/iam/access_key.rb +185 -0
  347. data/lib/aws/iam/access_key_collection.rb +128 -0
  348. data/lib/aws/iam/account_alias_collection.rb +79 -0
  349. data/lib/aws/iam/client.rb +49 -0
  350. data/lib/aws/iam/collection.rb +83 -0
  351. data/lib/aws/iam/config.rb +18 -0
  352. data/lib/aws/iam/errors.rb +22 -0
  353. data/lib/aws/iam/group.rb +111 -0
  354. data/lib/aws/iam/group_collection.rb +132 -0
  355. data/lib/aws/iam/group_policy_collection.rb +47 -0
  356. data/lib/aws/iam/group_user_collection.rb +84 -0
  357. data/lib/aws/iam/login_profile.rb +111 -0
  358. data/lib/aws/iam/mfa_device.rb +52 -0
  359. data/lib/aws/iam/mfa_device_collection.rb +127 -0
  360. data/lib/aws/iam/policy.rb +46 -0
  361. data/lib/aws/iam/policy_collection.rb +188 -0
  362. data/lib/aws/iam/resource.rb +62 -0
  363. data/lib/aws/iam/server_certificate.rb +148 -0
  364. data/lib/aws/iam/server_certificate_collection.rb +138 -0
  365. data/lib/aws/iam/signing_certificate.rb +186 -0
  366. data/lib/aws/iam/signing_certificate_collection.rb +131 -0
  367. data/lib/aws/iam/user.rb +200 -0
  368. data/lib/aws/iam/user_collection.rb +133 -0
  369. data/lib/aws/iam/user_group_collection.rb +98 -0
  370. data/lib/aws/iam/user_policy.rb +90 -0
  371. data/lib/aws/iam/user_policy_collection.rb +45 -0
  372. data/lib/aws/iam/virtual_mfa_device.rb +139 -0
  373. data/lib/aws/iam/virtual_mfa_device_collection.rb +73 -0
  374. data/lib/aws/import_export.rb +73 -0
  375. data/lib/aws/import_export/client.rb +35 -0
  376. data/lib/aws/import_export/config.rb +19 -0
  377. data/lib/aws/import_export/errors.rb +22 -0
  378. data/lib/aws/kinesis.rb +53 -0
  379. data/lib/aws/kinesis/client.rb +35 -0
  380. data/lib/aws/kinesis/config.rb +18 -0
  381. data/lib/aws/kinesis/errors.rb +20 -0
  382. data/lib/aws/ops_works.rb +29 -0
  383. data/lib/aws/ops_works/client.rb +35 -0
  384. data/lib/aws/ops_works/config.rb +18 -0
  385. data/lib/aws/ops_works/errors.rb +20 -0
  386. data/lib/aws/rails.rb +195 -0
  387. data/lib/aws/rds.rb +70 -0
  388. data/lib/aws/rds/client.rb +48 -0
  389. data/lib/aws/rds/config.rb +18 -0
  390. data/lib/aws/rds/db_instance.rb +215 -0
  391. data/lib/aws/rds/db_instance_collection.rb +75 -0
  392. data/lib/aws/rds/db_snapshot.rb +163 -0
  393. data/lib/aws/rds/db_snapshot_collection.rb +89 -0
  394. data/lib/aws/rds/errors.rb +22 -0
  395. data/lib/aws/record.rb +139 -0
  396. data/lib/aws/record/abstract_base.rb +689 -0
  397. data/lib/aws/record/attributes.rb +388 -0
  398. data/lib/aws/record/conversion.rb +38 -0
  399. data/lib/aws/record/dirty_tracking.rb +287 -0
  400. data/lib/aws/record/errors.rb +143 -0
  401. data/lib/aws/record/exceptions.rb +51 -0
  402. data/lib/aws/record/hash_model.rb +204 -0
  403. data/lib/aws/record/hash_model/attributes.rb +195 -0
  404. data/lib/aws/record/hash_model/finder_methods.rb +172 -0
  405. data/lib/aws/record/hash_model/scope.rb +108 -0
  406. data/lib/aws/record/model.rb +453 -0
  407. data/lib/aws/record/model/attributes.rb +377 -0
  408. data/lib/aws/record/model/finder_methods.rb +232 -0
  409. data/lib/aws/record/model/scope.rb +212 -0
  410. data/lib/aws/record/naming.rb +31 -0
  411. data/lib/aws/record/scope.rb +203 -0
  412. data/lib/aws/record/validations.rb +694 -0
  413. data/lib/aws/record/validator.rb +246 -0
  414. data/lib/aws/record/validators/acceptance.rb +49 -0
  415. data/lib/aws/record/validators/block.rb +36 -0
  416. data/lib/aws/record/validators/confirmation.rb +41 -0
  417. data/lib/aws/record/validators/count.rb +106 -0
  418. data/lib/aws/record/validators/exclusion.rb +41 -0
  419. data/lib/aws/record/validators/format.rb +55 -0
  420. data/lib/aws/record/validators/inclusion.rb +54 -0
  421. data/lib/aws/record/validators/length.rb +105 -0
  422. data/lib/aws/record/validators/method.rb +31 -0
  423. data/lib/aws/record/validators/numericality.rb +136 -0
  424. data/lib/aws/record/validators/presence.rb +43 -0
  425. data/lib/aws/redshift.rb +51 -0
  426. data/lib/aws/redshift/client.rb +35 -0
  427. data/lib/aws/redshift/config.rb +18 -0
  428. data/lib/aws/redshift/errors.rb +22 -0
  429. data/lib/aws/route_53.rb +86 -0
  430. data/lib/aws/route_53/change_batch.rb +162 -0
  431. data/lib/aws/route_53/change_info.rb +72 -0
  432. data/lib/aws/route_53/client.rb +38 -0
  433. data/lib/aws/route_53/config.rb +18 -0
  434. data/lib/aws/route_53/errors.rb +22 -0
  435. data/lib/aws/route_53/hosted_zone.rb +159 -0
  436. data/lib/aws/route_53/hosted_zone_collection.rb +101 -0
  437. data/lib/aws/route_53/resource_record_set.rb +258 -0
  438. data/lib/aws/route_53/resource_record_set_collection.rb +110 -0
  439. data/lib/aws/s3.rb +160 -0
  440. data/lib/aws/s3/access_control_list.rb +265 -0
  441. data/lib/aws/s3/acl_object.rb +264 -0
  442. data/lib/aws/s3/acl_options.rb +204 -0
  443. data/lib/aws/s3/bucket.rb +743 -0
  444. data/lib/aws/s3/bucket_collection.rb +162 -0
  445. data/lib/aws/s3/bucket_lifecycle_configuration.rb +473 -0
  446. data/lib/aws/s3/bucket_region_cache.rb +51 -0
  447. data/lib/aws/s3/bucket_tag_collection.rb +111 -0
  448. data/lib/aws/s3/bucket_version_collection.rb +79 -0
  449. data/lib/aws/s3/cipher_io.rb +120 -0
  450. data/lib/aws/s3/client.rb +2089 -0
  451. data/lib/aws/s3/client/xml.rb +266 -0
  452. data/lib/aws/s3/config.rb +61 -0
  453. data/lib/aws/s3/cors_rule.rb +108 -0
  454. data/lib/aws/s3/cors_rule_collection.rb +194 -0
  455. data/lib/aws/s3/data_options.rb +191 -0
  456. data/lib/aws/s3/encryption_utils.rb +146 -0
  457. data/lib/aws/s3/errors.rb +94 -0
  458. data/lib/aws/s3/multipart_upload.rb +353 -0
  459. data/lib/aws/s3/multipart_upload_collection.rb +76 -0
  460. data/lib/aws/s3/object_collection.rb +356 -0
  461. data/lib/aws/s3/object_metadata.rb +103 -0
  462. data/lib/aws/s3/object_upload_collection.rb +77 -0
  463. data/lib/aws/s3/object_version.rb +154 -0
  464. data/lib/aws/s3/object_version_collection.rb +89 -0
  465. data/lib/aws/s3/paginated_collection.rb +75 -0
  466. data/lib/aws/s3/policy.rb +74 -0
  467. data/lib/aws/s3/prefix_and_delimiter_collection.rb +47 -0
  468. data/lib/aws/s3/prefixed_collection.rb +85 -0
  469. data/lib/aws/s3/presign_v4.rb +136 -0
  470. data/lib/aws/s3/presigned_post.rb +554 -0
  471. data/lib/aws/s3/region_detection.rb +75 -0
  472. data/lib/aws/s3/request.rb +62 -0
  473. data/lib/aws/s3/s3_object.rb +1795 -0
  474. data/lib/aws/s3/tree.rb +116 -0
  475. data/lib/aws/s3/tree/branch_node.rb +68 -0
  476. data/lib/aws/s3/tree/child_collection.rb +104 -0
  477. data/lib/aws/s3/tree/leaf_node.rb +94 -0
  478. data/lib/aws/s3/tree/node.rb +22 -0
  479. data/lib/aws/s3/tree/parent.rb +87 -0
  480. data/lib/aws/s3/uploaded_part.rb +82 -0
  481. data/lib/aws/s3/uploaded_part_collection.rb +84 -0
  482. data/lib/aws/s3/website_configuration.rb +102 -0
  483. data/lib/aws/simple_db.rb +218 -0
  484. data/lib/aws/simple_db/attribute.rb +156 -0
  485. data/lib/aws/simple_db/attribute_collection.rb +240 -0
  486. data/lib/aws/simple_db/client.rb +67 -0
  487. data/lib/aws/simple_db/config.rb +20 -0
  488. data/lib/aws/simple_db/consistent_read_option.rb +42 -0
  489. data/lib/aws/simple_db/delete_attributes.rb +62 -0
  490. data/lib/aws/simple_db/domain.rb +123 -0
  491. data/lib/aws/simple_db/domain_collection.rb +86 -0
  492. data/lib/aws/simple_db/domain_metadata.rb +110 -0
  493. data/lib/aws/simple_db/errors.rb +55 -0
  494. data/lib/aws/simple_db/expect_condition_option.rb +45 -0
  495. data/lib/aws/simple_db/item.rb +93 -0
  496. data/lib/aws/simple_db/item_collection.rb +654 -0
  497. data/lib/aws/simple_db/item_data.rb +73 -0
  498. data/lib/aws/simple_db/put_attributes.rb +60 -0
  499. data/lib/aws/simple_email_service.rb +443 -0
  500. data/lib/aws/simple_email_service/client.rb +37 -0
  501. data/lib/aws/simple_email_service/config.rb +18 -0
  502. data/lib/aws/simple_email_service/email_address_collection.rb +69 -0
  503. data/lib/aws/simple_email_service/errors.rb +22 -0
  504. data/lib/aws/simple_email_service/identity.rb +230 -0
  505. data/lib/aws/simple_email_service/identity_collection.rb +81 -0
  506. data/lib/aws/simple_email_service/quotas.rb +66 -0
  507. data/lib/aws/simple_workflow.rb +227 -0
  508. data/lib/aws/simple_workflow/activity_task.rb +178 -0
  509. data/lib/aws/simple_workflow/activity_task_collection.rb +123 -0
  510. data/lib/aws/simple_workflow/activity_type.rb +140 -0
  511. data/lib/aws/simple_workflow/activity_type_collection.rb +102 -0
  512. data/lib/aws/simple_workflow/client.rb +69 -0
  513. data/lib/aws/simple_workflow/config.rb +18 -0
  514. data/lib/aws/simple_workflow/count.rb +49 -0
  515. data/lib/aws/simple_workflow/decision_task.rb +617 -0
  516. data/lib/aws/simple_workflow/decision_task_collection.rb +223 -0
  517. data/lib/aws/simple_workflow/domain.rb +122 -0
  518. data/lib/aws/simple_workflow/domain_collection.rb +169 -0
  519. data/lib/aws/simple_workflow/errors.rb +20 -0
  520. data/lib/aws/simple_workflow/history_event.rb +280 -0
  521. data/lib/aws/simple_workflow/history_event_collection.rb +76 -0
  522. data/lib/aws/simple_workflow/option_formatters.rb +86 -0
  523. data/lib/aws/simple_workflow/resource.rb +94 -0
  524. data/lib/aws/simple_workflow/type.rb +89 -0
  525. data/lib/aws/simple_workflow/type_collection.rb +140 -0
  526. data/lib/aws/simple_workflow/workflow_execution.rb +391 -0
  527. data/lib/aws/simple_workflow/workflow_execution_collection.rb +617 -0
  528. data/lib/aws/simple_workflow/workflow_type.rb +186 -0
  529. data/lib/aws/simple_workflow/workflow_type_collection.rb +100 -0
  530. data/lib/aws/sns.rb +76 -0
  531. data/lib/aws/sns/client.rb +35 -0
  532. data/lib/aws/sns/config.rb +18 -0
  533. data/lib/aws/sns/errors.rb +22 -0
  534. data/lib/aws/sns/has_delivery_policy.rb +68 -0
  535. data/lib/aws/sns/message.rb +204 -0
  536. data/lib/aws/sns/originators/from_auto_scaling.rb +68 -0
  537. data/lib/aws/sns/policy.rb +47 -0
  538. data/lib/aws/sns/subscription.rb +165 -0
  539. data/lib/aws/sns/subscription_collection.rb +78 -0
  540. data/lib/aws/sns/topic.rb +403 -0
  541. data/lib/aws/sns/topic_collection.rb +62 -0
  542. data/lib/aws/sns/topic_subscription_collection.rb +54 -0
  543. data/lib/aws/sqs.rb +80 -0
  544. data/lib/aws/sqs/client.rb +53 -0
  545. data/lib/aws/sqs/config.rb +20 -0
  546. data/lib/aws/sqs/errors.rb +125 -0
  547. data/lib/aws/sqs/policy.rb +48 -0
  548. data/lib/aws/sqs/queue.rb +856 -0
  549. data/lib/aws/sqs/queue_collection.rb +186 -0
  550. data/lib/aws/sqs/received_message.rb +190 -0
  551. data/lib/aws/sqs/received_sns_message.rb +116 -0
  552. data/lib/aws/storage_gateway.rb +72 -0
  553. data/lib/aws/storage_gateway/client.rb +42 -0
  554. data/lib/aws/storage_gateway/config.rb +18 -0
  555. data/lib/aws/storage_gateway/errors.rb +22 -0
  556. data/lib/aws/sts.rb +164 -0
  557. data/lib/aws/sts/client.rb +55 -0
  558. data/lib/aws/sts/config.rb +18 -0
  559. data/lib/aws/sts/errors.rb +22 -0
  560. data/lib/aws/sts/federated_session.rb +56 -0
  561. data/lib/aws/sts/policy.rb +30 -0
  562. data/lib/aws/sts/session.rb +48 -0
  563. data/lib/aws/support.rb +29 -0
  564. data/lib/aws/support/client.rb +35 -0
  565. data/lib/aws/support/config.rb +18 -0
  566. data/lib/aws/support/errors.rb +20 -0
  567. data/lib/aws/version.rb +17 -0
  568. data/rails/init.rb +15 -0
  569. metadata +645 -0
@@ -0,0 +1,51 @@
1
+ require 'thread'
2
+
3
+ module AWS
4
+ class S3
5
+ class BucketRegionCache
6
+
7
+ def initialize
8
+ @regions = {}
9
+ @mutex = Mutex.new
10
+ end
11
+
12
+ def [](bucket_name)
13
+ @mutex.synchronize do
14
+ @regions[bucket_name]
15
+ end
16
+ end
17
+
18
+ def []=(bucket_name, region_name)
19
+ @mutex.synchronize do
20
+ @regions[bucket_name] = region_name
21
+ end
22
+ end
23
+
24
+ def delete(bucket_name)
25
+ @mutex.synchronize do
26
+ @regions[bucket_name] = region_name
27
+ end
28
+ end
29
+
30
+ def update!(bucket_regions)
31
+ @mutex.synchronize do
32
+ @regions.update!(bucket_regions)
33
+ end
34
+ end
35
+
36
+ def clear
37
+ @mutex.synchronize do
38
+ @regions = {}
39
+ end
40
+ end
41
+
42
+ def to_hash
43
+ @mutex.synchronize do
44
+ @regions.dup
45
+ end
46
+ end
47
+ alias to_h to_hash
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,111 @@
1
+ # Copyright 2011-2013 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
+ module AWS
15
+ class S3
16
+
17
+ # Manages tags for a single S3 {Bucket}.
18
+ #
19
+ # @example Setting a tag.
20
+ #
21
+ # bucket.tags['key'] = 'value'
22
+ #
23
+ # @example Getting a tag.
24
+ #
25
+ # bucket.tags['key']
26
+ # #=> 'value'
27
+ #
28
+ # @example Getting all tags
29
+ #
30
+ # bucket.tags.to_h
31
+ # #=> { 'key' => 'value', ... }
32
+ #
33
+ # @example Removing all tags
34
+ #
35
+ # bucket.tags.clear
36
+ #
37
+ class BucketTagCollection
38
+
39
+ include Core::Model
40
+
41
+ # @param [Bucket] bucket
42
+ # @param [Hash] options
43
+ def initialize bucket, options = {}
44
+ @bucket = bucket
45
+ super
46
+ end
47
+
48
+ # @return [Bucket]
49
+ attr_reader :bucket
50
+
51
+ # @param [String] key
52
+ # @return [String,nil] Returns the tag for the given key. If there
53
+ # Returns `nil` if the key does not exist.
54
+ def [] key
55
+ self.to_h[key]
56
+ end
57
+
58
+ # @param [String] key
59
+ # @param [String] value
60
+ def []= key, value
61
+ self.set(self.to_h.merge(key => value))
62
+ end
63
+
64
+ # @param [Hash<String,String>] tags A hash of tag keys and values.
65
+ # @return [nil]
66
+ def set tags
67
+ if tags.nil? or tags.empty?
68
+ self.clear
69
+ else
70
+ client.put_bucket_tagging(:bucket_name => bucket.name, :tags => tags)
71
+ end
72
+ nil
73
+ end
74
+
75
+ # Removes all tags from the bucket.
76
+ #
77
+ # @example
78
+ #
79
+ # bucket.tags.clear
80
+ # bucket.tags.to_h #=> {}
81
+ #
82
+ # @return [nil]
83
+ def clear
84
+ client.delete_bucket_tagging(:bucket_name => bucket.name)
85
+ nil
86
+ end
87
+
88
+ # @return [Hash]
89
+ def to_h
90
+ client.get_bucket_tagging(:bucket_name => bucket.name).data[:tags]
91
+ rescue AWS::S3::Errors::NoSuchTagSet
92
+ {}
93
+ end
94
+ alias_method :to_hash, :to_h
95
+
96
+ # @param [Hash] other
97
+ # @return [Boolean] Returns `true` if the tags for this bucket match
98
+ # the passed hash.
99
+ def eql? other
100
+ self.to_h == other
101
+ end
102
+ alias_method :==, :eql?
103
+
104
+ # @api private
105
+ def inspect
106
+ self.to_h.inspect
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,79 @@
1
+ # Copyright 2011-2013 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
+ module AWS
15
+ class S3
16
+
17
+ # A collection of versioned objects for the entire bucket.
18
+ #
19
+ # @see PrefixedCollection
20
+ class BucketVersionCollection
21
+
22
+ include PrefixAndDelimiterCollection
23
+
24
+ # @param [Bucket] bucket
25
+ def initialize bucket, options = {}
26
+ @bucket = bucket
27
+ super
28
+ end
29
+
30
+ # @return [Bucket] The bucket this collection belongs to.
31
+ attr_reader :bucket
32
+
33
+ # @return [ObjectVersion] Returns the most recently created object
34
+ # version in the entire bucket.
35
+ def latest
36
+ first
37
+ #self.find{|version| true }
38
+ end
39
+
40
+ # Yields once for each version in the bucket.
41
+ #
42
+ # @yield [object_version]
43
+ #
44
+ # @yieldparam [ObjectVersion] object_version
45
+ #
46
+ # @return nil
47
+ #
48
+ def each options = {}, &block; super; end
49
+
50
+ # @api private
51
+ protected
52
+ def each_member_in_page(page, &block)
53
+ super
54
+ page.versions.each do |version|
55
+ object_version = ObjectVersion.new(bucket.objects[version.key],
56
+ version.version_id,
57
+ :delete_marker => version.delete_marker?,
58
+ :last_modified => version.last_modified)
59
+ yield(object_version)
60
+ end
61
+ end
62
+
63
+ # @api private
64
+ protected
65
+ def list_request(options)
66
+ client.list_object_versions(options)
67
+ end
68
+
69
+ # @api private
70
+ protected
71
+ def limit_param; :max_keys; end
72
+
73
+ # @api private
74
+ protected
75
+ def pagination_markers; super + [:version_id_marker]; end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,120 @@
1
+ # Copyright 2011-2013 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
+ module AWS
15
+ class S3
16
+
17
+ # @api private
18
+ class CipherIO
19
+
20
+ def initialize cipher, stream, stream_size = nil
21
+
22
+ @stream = stream
23
+ @stream_size = stream_size
24
+ @orig_cipher = cipher.clone
25
+
26
+ reset_cipher
27
+
28
+ # add a #rewind method if the original stream can be rewound
29
+ if @stream.respond_to?(:rewind)
30
+ Core::MetaUtils.extend_method(self, :rewind) do
31
+ reset_cipher
32
+ @stream.rewind
33
+ end
34
+ end
35
+
36
+ # add a #size method if the stream size is known
37
+ if stream_size
38
+ Core::MetaUtils.extend_method(self, :size) do
39
+ EncryptionUtils.get_encrypted_size(@stream_size)
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ # @return [String] Returns the requested number of bytes. If no byte
46
+ # amount is given, it will return the entire body of encrypted data
47
+ def read bytes = nil, output_buffer = nil
48
+ data = if bytes
49
+ (@eof) ? nil : read_chunk(bytes)
50
+ else
51
+ (@eof) ? "" : read_all
52
+ end
53
+ output_buffer ? output_buffer.replace(data || '') : data
54
+ end
55
+
56
+ # @return [Boolean] Returns `true` when the entire stream has been read.
57
+ def eof?
58
+ @eof
59
+ end
60
+
61
+ private
62
+
63
+ attr_reader :cipher
64
+
65
+ # Sets the CipherIO in a reset state without having to know anything
66
+ # about the cipher
67
+ def reset_cipher
68
+ @cipher = @orig_cipher.clone
69
+ @eof = false
70
+ @final = nil
71
+ end
72
+
73
+ # @return [String] Returns an encrytped chunk
74
+ def read_chunk bytes
75
+ unless @final
76
+ # If given a number of bytes, read it out and work out encryption
77
+ # issues
78
+ chunk = @stream.read(bytes)
79
+
80
+ # If there is nothing, finish the encryption
81
+ if chunk and chunk.length > 0
82
+ handle_finish(bytes, cipher.update(chunk))
83
+ else
84
+ @eof = true
85
+ cipher.final
86
+ end
87
+ # Read as much as possible if not given a byte size
88
+ else
89
+ @eof = true
90
+ @final
91
+ end
92
+ end
93
+
94
+ # @return [String] Returns the entire encrypted data
95
+ def read_all
96
+ @eof = true
97
+ body = @stream.read()
98
+ data = (body and body.length > 0) ? cipher.update(body) : ""
99
+ data << cipher.final
100
+ end
101
+
102
+ # Figures out how much of the final block goes into the current chunk
103
+ # and adds it.
104
+ # @return [String] Returns the encrypted chunk with possible padding.
105
+ def handle_finish(bytes, chunk)
106
+ free_space = bytes - chunk.size
107
+
108
+ if free_space > 0
109
+ @final = cipher.final
110
+ chunk << @final[0..free_space-1]
111
+ @final = @final[free_space..@final.size-1]
112
+ @eof = true unless @final and @final.size > 0
113
+ end
114
+
115
+ chunk
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,2089 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2011-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://aws.amazon.com/apache2.0/
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ require 'rexml/document'
16
+ require 'pathname'
17
+ require 'stringio'
18
+ require 'json'
19
+ require 'digest/md5'
20
+ require 'base64'
21
+ require 'nokogiri'
22
+ require 'set'
23
+
24
+ module AWS
25
+ class S3
26
+
27
+ # Client class for Amazon Simple Storage Service (S3).
28
+ class Client < Core::Client
29
+
30
+ include RegionDetection
31
+
32
+ def initialize(options = {})
33
+ super(options.merge(:http_continue_threshold => 0))
34
+ end
35
+
36
+ signature_version :S3
37
+
38
+ API_VERSION = '2006-03-01'
39
+
40
+ XMLNS = "http://s3.amazonaws.com/doc/#{API_VERSION}/"
41
+
42
+ HTTP_200_ERROR_OPERATIONS = Set.new([
43
+ :complete_multipart_upload,
44
+ :copy_object,
45
+ :copy_part,
46
+ ])
47
+
48
+ autoload :XML, 'aws/s3/client/xml'
49
+
50
+ # @api private
51
+ EMPTY_BODY_ERRORS = {
52
+ 304 => Errors::NotModified,
53
+ 403 => Errors::Forbidden,
54
+ 400 => Errors::BadRequest,
55
+ 404 => Errors::NoSuchKey,
56
+ }
57
+
58
+ # @api private
59
+ CACHEABLE_REQUESTS = Set[]
60
+
61
+ include DataOptions
62
+ include Core::UriEscape
63
+
64
+ # @param [Core::Http::Request] request
65
+ # @api private
66
+ def sign_request request
67
+ case @config.s3_signature_version.to_sym
68
+ when :v4 then v4_signer.sign_request(request)
69
+ when :v3 then v3_signer.sign_request(request)
70
+ else
71
+ raise "invalid signature version #{@config.s3_signature_version.inspect}"
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ # @return [Core::Signers::S3]
78
+ def v3_signer
79
+ @v3_signer ||= Core::Signers::S3.new(credential_provider)
80
+ end
81
+
82
+ # @return [Core::Signers::Version4]
83
+ def v4_signer
84
+ @v4_signer ||= begin
85
+ Core::Signers::Version4.new(credential_provider, 's3', @region)
86
+ end
87
+ end
88
+
89
+ # @param [Http::Request] req
90
+ # @return [Boolean]
91
+ def chunk_sign? req
92
+ req.http_method == 'PUT' &&
93
+ req.headers['content-length'].to_i > 2 * 1024 * 1024 # 2MB
94
+ end
95
+
96
+ def self.bucket_method(method_name, verb, *args, &block)
97
+
98
+ method_options = (args.pop if args.last.kind_of?(Hash)) || {}
99
+ xml_grammar = (args.pop if args.last.respond_to?(:rules))
100
+ verb = verb.to_s.upcase
101
+ subresource = args.first
102
+
103
+ add_client_request_method(method_name) do
104
+
105
+ configure_request do |req, options|
106
+
107
+ require_bucket_name!(options[:bucket_name])
108
+
109
+ req.http_method = verb
110
+ req.bucket = options[:bucket_name]
111
+ req.add_param(subresource) if subresource
112
+
113
+ if header_options = method_options[:header_options]
114
+ header_options.each do |(opt, header)|
115
+ if value = options[opt]
116
+ # for backwards compatability we translate canned acls
117
+ # header values from symbols to strings (e.g.
118
+ # :public_read translates to 'public-read')
119
+ value = (opt == :acl ? value.to_s.tr('_', '-') : value)
120
+ req.headers[header] = value
121
+ end
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ instance_eval(&block) if block
128
+
129
+ if xml_grammar
130
+
131
+ parser = Core::XML::Parser.new(xml_grammar.rules)
132
+
133
+ process_response do |resp|
134
+ resp.data = parser.parse(resp.http_response.body)
135
+ super(resp)
136
+ end
137
+
138
+ simulate_response do |resp|
139
+ resp.data = parser.simulate
140
+ super(resp)
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+ end
147
+
148
+ protected
149
+
150
+ def set_metadata request, options
151
+ if metadata = options[:metadata]
152
+ Array(metadata).each do |name, value|
153
+ request.headers["x-amz-meta-#{name}"] = value
154
+ end
155
+ end
156
+ end
157
+
158
+ def set_storage_class request, options
159
+ storage_class = options[:storage_class]
160
+ if storage_class.kind_of?(Symbol)
161
+ request.headers["x-amz-storage-class"] = storage_class.to_s.upcase
162
+ elsif storage_class
163
+ request.headers["x-amz-storage-class"] = storage_class
164
+ end
165
+ end
166
+
167
+ def set_server_side_encryption request, options
168
+ sse = options[:server_side_encryption]
169
+ if sse.is_a?(Symbol)
170
+ request.headers['x-amz-server-side-encryption'] = sse.to_s.upcase
171
+ elsif sse
172
+ request.headers['x-amz-server-side-encryption'] = sse
173
+ end
174
+ end
175
+
176
+ def extract_error_details response
177
+ if
178
+ (
179
+ response.http_response.status >= 300 ||
180
+ HTTP_200_ERROR_OPERATIONS.include?(response.request_type)
181
+ ) and
182
+ body = response.http_response.body and
183
+ error = Core::XML::Parser.parse(body) and
184
+ error[:code]
185
+ then
186
+ [error[:code], error[:message]]
187
+ end
188
+ end
189
+
190
+ def empty_response_body? response_body
191
+ response_body.nil? or response_body == ''
192
+ end
193
+
194
+ # There are a few of s3 requests that can generate empty bodies and
195
+ # yet still be errors. These return empty bodies to comply with the
196
+ # HTTP spec. We have to detect these errors specially.
197
+ def populate_error resp
198
+ code = resp.http_response.status
199
+ if EMPTY_BODY_ERRORS.include?(code) and empty_response_body?(resp.http_response.body)
200
+ error_class = EMPTY_BODY_ERRORS[code]
201
+ resp.error = error_class.new(resp.http_request, resp.http_response)
202
+ else
203
+ super
204
+ end
205
+ end
206
+
207
+ def retryable_error? response
208
+ super ||
209
+ http_200_error?(response) ||
210
+ response.error.is_a?(Errors::RequestTimeout)
211
+ end
212
+
213
+ # S3 may return with a 200 status code in the response, but still
214
+ # embed an error in the body for the following operations:
215
+ #
216
+ # * `#complete_multipart_upload`
217
+ # * `#copy_object`
218
+ # * `#copy_part`
219
+ #
220
+ # To ensure the response is not in error, we have to parse
221
+ # it before the normal parser.
222
+ def http_200_error? response
223
+ HTTP_200_ERROR_OPERATIONS.include?(response.request_type) &&
224
+ extract_error_details(response)
225
+ end
226
+
227
+ def new_request
228
+ req = S3::Request.new
229
+ req.force_path_style = config.s3_force_path_style?
230
+ req
231
+ end
232
+
233
+ # Previously the access control policy could be specified via :acl
234
+ # as a string or an object that responds to #to_xml. The prefered
235
+ # method now is to pass :access_control_policy an xml document.
236
+ def move_access_control_policy options
237
+ if acl = options[:acl]
238
+ if acl.is_a?(String) and is_xml?(acl)
239
+ options[:access_control_policy] = options.delete(:acl)
240
+ elsif acl.respond_to?(:to_xml)
241
+ options[:access_control_policy] = options.delete(:acl).to_xml
242
+ end
243
+ end
244
+ end
245
+
246
+ # @param [String] possible_xml
247
+ # @return [Boolean] Returns `true` if the given string is a valid xml
248
+ # document.
249
+ def is_xml? possible_xml
250
+ begin
251
+ REXML::Document.new(possible_xml).has_elements?
252
+ rescue
253
+ false
254
+ end
255
+ end
256
+
257
+ def md5 str
258
+ Base64.encode64(OpenSSL::Digest::MD5.digest(str)).strip
259
+ end
260
+
261
+ def parse_copy_part_response resp
262
+ doc = REXML::Document.new(resp.http_response.body)
263
+ resp[:etag] = doc.root.elements["ETag"].text
264
+ resp[:last_modified] = doc.root.elements["LastModified"].text
265
+ if header = resp.http_response.headers['x-amzn-requestid']
266
+ data[:request_id] = [header].flatten.first
267
+ end
268
+ end
269
+
270
+ def extract_object_headers resp
271
+ meta = {}
272
+ resp.http_response.headers.each_pair do |name,value|
273
+ if name =~ /^x-amz-meta-(.+)$/i
274
+ meta[$1] = [value].flatten.join
275
+ end
276
+ end
277
+ resp.data[:meta] = meta
278
+
279
+ if expiry = resp.http_response.headers['x-amz-expiration']
280
+ expiry.first =~ /^expiry-date="(.+)", rule-id="(.+)"$/
281
+ exp_date = DateTime.parse($1)
282
+ exp_rule_id = $2
283
+ else
284
+ exp_date = nil
285
+ exp_rule_id = nil
286
+ end
287
+ resp.data[:expiration_date] = exp_date if exp_date
288
+ resp.data[:expiration_rule_id] = exp_rule_id if exp_rule_id
289
+
290
+ restoring = false
291
+ restore_date = nil
292
+
293
+ if restore = resp.http_response.headers['x-amz-restore']
294
+ if restore.first =~ /ongoing-request="(.+?)", expiry-date="(.+?)"/
295
+ restoring = $1 == "true"
296
+ restore_date = $2 && DateTime.parse($2)
297
+ elsif restore.first =~ /ongoing-request="(.+?)"/
298
+ restoring = $1 == "true"
299
+ end
300
+ end
301
+ resp.data[:restore_in_progress] = restoring
302
+ resp.data[:restore_expiration_date] = restore_date if restore_date
303
+
304
+ {
305
+ 'x-amz-version-id' => :version_id,
306
+ 'content-type' => :content_type,
307
+ 'content-encoding' => :content_encoding,
308
+ 'cache-control' => :cache_control,
309
+ 'expires' => :expires,
310
+ 'etag' => :etag,
311
+ 'x-amz-website-redirect-location' => :website_redirect_location,
312
+ 'accept-ranges' => :accept_ranges,
313
+ 'x-amz-server-side-encryption-customer-algorithm' => :sse_customer_algorithm,
314
+ 'x-amz-server-side-encryption-customer-key-MD5' => :sse_customer_key_md5
315
+ }.each_pair do |header,method|
316
+ if value = resp.http_response.header(header)
317
+ resp.data[method] = value
318
+ end
319
+ end
320
+
321
+ if time = resp.http_response.header('Last-Modified')
322
+ resp.data[:last_modified] = Time.parse(time)
323
+ end
324
+
325
+ if length = resp.http_response.header('content-length')
326
+ resp.data[:content_length] = length.to_i
327
+ end
328
+
329
+ if sse = resp.http_response.header('x-amz-server-side-encryption')
330
+ resp.data[:server_side_encryption] = sse.downcase.to_sym
331
+ end
332
+
333
+ end
334
+
335
+ module Validators
336
+
337
+ # @return [Boolean] Returns true if the given bucket name is valid.
338
+ def valid_bucket_name?(bucket_name)
339
+ validate_bucket_name!(bucket_name) rescue false
340
+ end
341
+
342
+ # Returns true if the given `bucket_name` is DNS compatible.
343
+ #
344
+ # DNS compatible bucket names may be accessed like:
345
+ #
346
+ # http://dns.compat.bucket.name.s3.amazonaws.com/
347
+ #
348
+ # Whereas non-dns compatible bucket names must place the bucket
349
+ # name in the url path, like:
350
+ #
351
+ # http://s3.amazonaws.com/dns_incompat_bucket_name/
352
+ #
353
+ # @return [Boolean] Returns true if the given bucket name may be
354
+ # is dns compatible.
355
+ # this bucket n
356
+ #
357
+ def dns_compatible_bucket_name?(bucket_name)
358
+ return false if
359
+ !valid_bucket_name?(bucket_name) or
360
+
361
+ # Bucket names should be between 3 and 63 characters long
362
+ bucket_name.size > 63 or
363
+
364
+ # Bucket names must only contain lowercase letters, numbers, dots, and dashes
365
+ # and must start and end with a lowercase letter or a number
366
+ bucket_name !~ /^[a-z0-9][a-z0-9.-]+[a-z0-9]$/ or
367
+
368
+ # Bucket names should not be formatted like an IP address (e.g., 192.168.5.4)
369
+ bucket_name =~ /(\d+\.){3}\d+/ or
370
+
371
+ # Bucket names cannot contain two, adjacent periods
372
+ bucket_name['..'] or
373
+
374
+ # Bucket names cannot contain dashes next to periods
375
+ # (e.g., "my-.bucket.com" and "my.-bucket" are invalid)
376
+ (bucket_name['-.'] || bucket_name['.-'])
377
+
378
+ true
379
+ end
380
+
381
+ # Returns true if the bucket name must be used in the request
382
+ # path instead of as a sub-domain when making requests against
383
+ # S3.
384
+ #
385
+ # This can be an issue if the bucket name is DNS compatible but
386
+ # contains '.' (periods). These cause the SSL certificate to
387
+ # become invalid when making authenticated requets over SSL to the
388
+ # bucket name. The solution is to send this as a path argument
389
+ # instead.
390
+ #
391
+ # @return [Boolean] Returns true if the bucket name should be used
392
+ # as a path segement instead of dns prefix when making requests
393
+ # against s3.
394
+ #
395
+ def path_style_bucket_name? bucket_name
396
+ if dns_compatible_bucket_name?(bucket_name)
397
+ bucket_name =~ /\./ ? true : false
398
+ else
399
+ true
400
+ end
401
+ end
402
+
403
+ def validate! name, value, &block
404
+ if error_msg = yield
405
+ raise ArgumentError, "#{name} #{error_msg}"
406
+ end
407
+ value
408
+ end
409
+
410
+ def validate_key!(key)
411
+ validate!('key', key) do
412
+ case
413
+ when key.nil? || key == ''
414
+ 'may not be blank'
415
+ end
416
+ end
417
+ end
418
+
419
+ def require_bucket_name! bucket_name
420
+ if [nil, ''].include?(bucket_name)
421
+ raise ArgumentError, "bucket_name may not be blank"
422
+ end
423
+ end
424
+
425
+ # Returns true if the given bucket name is valid. If the name
426
+ # is invalid, an ArgumentError is raised.
427
+ def validate_bucket_name!(bucket_name)
428
+ validate!('bucket_name', bucket_name) do
429
+ case
430
+ when bucket_name.nil? || bucket_name == ''
431
+ 'may not be blank'
432
+ when bucket_name !~ /^[A-Za-z0-9._\-]+$/
433
+ 'may only contain uppercase letters, lowercase letters, numbers, periods (.), ' +
434
+ 'underscores (_), and dashes (-)'
435
+ when !(3..255).include?(bucket_name.size)
436
+ 'must be between 3 and 255 characters long'
437
+ when bucket_name =~ /\n/
438
+ 'must not contain a newline character'
439
+ end
440
+ end
441
+ end
442
+
443
+ def require_policy!(policy)
444
+ validate!('policy', policy) do
445
+ case
446
+ when policy.nil? || policy == ''
447
+ 'may not be blank'
448
+ else
449
+ json_validation_message(policy)
450
+ end
451
+ end
452
+ end
453
+
454
+ def require_acl! options
455
+ acl_options = [
456
+ :acl,
457
+ :grant_read,
458
+ :grant_write,
459
+ :grant_read_acp,
460
+ :grant_write_acp,
461
+ :grant_full_control,
462
+ :access_control_policy,
463
+ ]
464
+ unless options.keys.any?{|opt| acl_options.include?(opt) }
465
+ msg = "missing a required ACL option, must provide an ACL " +
466
+ "via :acl, :grant_* or :access_control_policy"
467
+ raise ArgumentError, msg
468
+ end
469
+ end
470
+
471
+ def set_body_stream_and_content_length request, options
472
+
473
+ unless options[:content_length]
474
+ msg = "S3 requires a content-length header, unable to determine "
475
+ msg << "the content length of the data provided, please set "
476
+ msg << ":content_length"
477
+ raise ArgumentError, msg
478
+ end
479
+
480
+ request.headers['content-length'] = options[:content_length]
481
+ request.body_stream = options[:data]
482
+
483
+ end
484
+
485
+ def require_upload_id!(upload_id)
486
+ validate!("upload_id", upload_id) do
487
+ "must not be blank" if upload_id.to_s.empty?
488
+ end
489
+ end
490
+
491
+ def require_part_number! part_number
492
+ validate!("part_number", part_number) do
493
+ "must not be blank" if part_number.to_s.empty?
494
+ end
495
+ end
496
+
497
+ def validate_parts!(parts)
498
+ validate!("parts", parts) do
499
+ if !parts.kind_of?(Array)
500
+ "must not be blank"
501
+ elsif parts.empty?
502
+ "must contain at least one entry"
503
+ elsif !parts.all? { |p| p.kind_of?(Hash) }
504
+ "must be an array of hashes"
505
+ elsif !parts.all? { |p| p[:part_number] }
506
+ "must contain part_number for each part"
507
+ elsif !parts.all? { |p| p[:etag] }
508
+ "must contain etag for each part"
509
+ elsif parts.any? { |p| p[:part_number].to_i < 1 }
510
+ "must not have part numbers less than 1"
511
+ end
512
+ end
513
+ end
514
+
515
+ def json_validation_message(obj)
516
+ if obj.respond_to?(:to_str)
517
+ obj = obj.to_str
518
+ elsif obj.respond_to?(:to_json)
519
+ obj = obj.to_json
520
+ end
521
+
522
+ error = nil
523
+ begin
524
+ JSON.parse(obj)
525
+ rescue => e
526
+ error = e
527
+ end
528
+ "contains invalid JSON: #{error}" if error
529
+ end
530
+
531
+ def require_allowed_methods!(allowed_methods)
532
+ validate!("allowed_methods", allowed_methods) do
533
+ if !allowed_methods.kind_of?(Array)
534
+ "must be an array"
535
+ elsif !allowed_methods.all? { |x| x.kind_of?(String) }
536
+ "must be an array of strings"
537
+ end
538
+ end
539
+ end
540
+
541
+ def require_allowed_origins!(allowed_origins)
542
+ validate!("allowed_origins", allowed_origins) do
543
+ if !allowed_origins.kind_of?(Array)
544
+ "must be an array"
545
+ elsif !allowed_origins.all? { |x| x.kind_of?(String) }
546
+ "must be an array of strings"
547
+ end
548
+ end
549
+ end
550
+
551
+ end
552
+
553
+ include Validators
554
+ extend Validators
555
+
556
+ end
557
+
558
+ class Client::V20060301 < Client
559
+
560
+ def self.object_method(method_name, verb, *args, &block)
561
+ bucket_method(method_name, verb, *args) do
562
+ configure_request do |req, options|
563
+ validate_key!(options[:key])
564
+ super(req, options)
565
+ req.key = options[:key]
566
+ end
567
+
568
+ instance_eval(&block) if block
569
+ end
570
+ end
571
+
572
+ public
573
+
574
+ # Creates a bucket.
575
+ # @overload create_bucket(options = {})
576
+ # @param [Hash] options
577
+ # @option options [required,String] :bucket_name
578
+ # @option options [String] :acl A canned ACL (e.g. 'private',
579
+ # 'public-read', etc). See the S3 API documentation for
580
+ # a complete list of valid values.
581
+ # @option options [String] :grant_read
582
+ # @option options [String] :grant_write
583
+ # @option options [String] :grant_read_acp
584
+ # @option options [String] :grant_write_acp
585
+ # @option options [String] :grant_full_control
586
+ # @return [Core::Response]
587
+ bucket_method(:create_bucket, :put, :header_options => {
588
+ :acl => 'x-amz-acl',
589
+ :grant_read => 'x-amz-grant-read',
590
+ :grant_write => 'x-amz-grant-write',
591
+ :grant_read_acp => 'x-amz-grant-read-acp',
592
+ :grant_write_acp => 'x-amz-grant-write-acp',
593
+ :grant_full_control => 'x-amz-grant-full-control',
594
+ }) do
595
+
596
+ configure_request do |req, options|
597
+ validate_bucket_name!(options[:bucket_name])
598
+ if location = options[:location_constraint]
599
+ xmlns = "http://s3.amazonaws.com/doc/#{API_VERSION}/"
600
+ req.body = <<-XML
601
+ <CreateBucketConfiguration xmlns="#{xmlns}">
602
+ <LocationConstraint>#{location}</LocationConstraint>
603
+ </CreateBucketConfiguration>
604
+ XML
605
+ end
606
+ super(req, options)
607
+ end
608
+
609
+ end
610
+ alias_method :put_bucket, :create_bucket
611
+
612
+ # @!method put_bucket_website(options = {})
613
+ # @param [Hash] options
614
+ # @option (see WebsiteConfiguration#initialize)
615
+ # @option options [required,String] :bucket_name
616
+ # @return [Core::Response]
617
+ bucket_method(:put_bucket_website, :put, 'website') do
618
+
619
+ configure_request do |req, options|
620
+ req.body = Nokogiri::XML::Builder.new do |xml|
621
+ xml.WebsiteConfiguration(:xmlns => XMLNS) do
622
+
623
+ if redirect = options[:redirect_all_requests_to]
624
+ xml.RedirectAllRequestsTo do
625
+ xml.HostName(redirect[:host_name])
626
+ xml.Protocol(redirect[:protocol]) if redirect[:protocol]
627
+ end
628
+ end
629
+
630
+ if indx = options[:index_document]
631
+ xml.IndexDocument do
632
+ xml.Suffix(indx[:suffix])
633
+ end
634
+ end
635
+
636
+ if err = options[:error_document]
637
+ xml.ErrorDocument do
638
+ xml.Key(err[:key])
639
+ end
640
+ end
641
+
642
+ rules = options[:routing_rules]
643
+ if rules.is_a?(Array) && !rules.empty?
644
+ xml.RoutingRules do
645
+ rules.each do |rule|
646
+ xml.RoutingRule do
647
+
648
+ redirect = rule[:redirect]
649
+ xml.Redirect do
650
+ xml.Protocol(redirect[:protocol]) if redirect[:protocol]
651
+ xml.HostName(redirect[:host_name]) if redirect[:host_name]
652
+ xml.ReplaceKeyPrefixWith(redirect[:replace_key_prefix_with]) if redirect[:replace_key_prefix_with]
653
+ xml.ReplaceKeyWith(redirect[:replace_key_with]) if redirect[:replace_key_with]
654
+ xml.HttpRedirectCode(redirect[:http_redirect_code]) if redirect[:http_redirect_code]
655
+ end
656
+
657
+ if condition = rule[:condition]
658
+ xml.Condition do
659
+ xml.KeyPrefixEquals(condition[:key_prefix_equals]) if condition[:key_prefix_equals]
660
+ xml.HttpErrorCodeReturnedEquals(condition[:http_error_code_returned_equals]) if condition[:http_error_code_returned_equals]
661
+ end
662
+ end
663
+
664
+ end
665
+ end
666
+ end
667
+ end
668
+
669
+ end
670
+ end.doc.root.to_xml
671
+ super(req, options)
672
+ end
673
+
674
+ end
675
+
676
+ # @overload get_bucket_website(options = {})
677
+ # @param [Hash] options
678
+ # @option options [required,String] :bucket_name
679
+ # @return [Core::Response]
680
+ # * `:index_document` - (Hash)
681
+ # * `:suffix` - (String)
682
+ # * `:error_document` - (Hash)
683
+ # * `:key` - (String)
684
+ bucket_method(:get_bucket_website, :get, 'website', XML::GetBucketWebsite)
685
+
686
+ # @overload delete_bucket_website(options = {})
687
+ # @param [Hash] options
688
+ # @option options [required,String] :bucket_name
689
+ # @return [Core::Response]
690
+ bucket_method(:delete_bucket_website, :delete, 'website')
691
+
692
+ # Deletes an empty bucket.
693
+ # @overload delete_bucket(options = {})
694
+ # @param [Hash] options
695
+ # @option options [required,String] :bucket_name
696
+ # @return [Core::Response]
697
+ bucket_method(:delete_bucket, :delete)
698
+
699
+ # @overload set_bucket_lifecycle_configuration(options = {})
700
+ # @param [Hash] options
701
+ # @option options [required,String] :bucket_name
702
+ # @option options [required,String] :lifecycle_configuration
703
+ # @return [Core::Response]
704
+ bucket_method(:set_bucket_lifecycle_configuration, :put) do
705
+
706
+ configure_request do |req, options|
707
+ xml = options[:lifecycle_configuration]
708
+ req.add_param('lifecycle')
709
+ req.body = xml
710
+ req.headers['content-md5'] = md5(xml)
711
+ super(req, options)
712
+ end
713
+
714
+ end
715
+
716
+ # @overload get_bucket_lifecycle_configuration(options = {})
717
+ # @param [Hash] options
718
+ # @option options [required,String] :bucket_name
719
+ # @return [Core::Response]
720
+ bucket_method(:get_bucket_lifecycle_configuration, :get) do
721
+
722
+ configure_request do |req, options|
723
+ req.add_param('lifecycle')
724
+ super(req, options)
725
+ end
726
+
727
+ process_response do |resp|
728
+ xml = resp.http_response.body
729
+ resp.data = XML::GetBucketLifecycleConfiguration.parse(xml)
730
+ end
731
+
732
+ end
733
+
734
+ # @overload delete_bucket_lifecycle_configuration(options = {})
735
+ # @param [Hash] options
736
+ # @option options [required,String] :bucket_name
737
+ # @return [Core::Response]
738
+ bucket_method(:delete_bucket_lifecycle_configuration, :delete) do
739
+
740
+ configure_request do |req, options|
741
+ req.add_param('lifecycle')
742
+ super(req, options)
743
+ end
744
+
745
+ end
746
+
747
+ # @overload put_bucket_cors(options = {})
748
+ # @param [Hash] options
749
+ # @option options [required,String] :bucket_name
750
+ # @option options [required,Array<Hash>] :rules An array of rule hashes.
751
+ # * `:id` - (String) A unique identifier for the rule. The ID
752
+ # value can be up to 255 characters long. The IDs help you find
753
+ # a rule in the configuration.
754
+ # * `:allowed_methods` - (required,Array<String>) A list of HTTP
755
+ # methods that you want to allow the origin to execute.
756
+ # Each rule must identify at least one method.
757
+ # * `:allowed_origins` - (required,Array<String>) A list of origins
758
+ # you want to allow cross-domain requests from. This can
759
+ # contain at most one * wild character.
760
+ # * `:allowed_headers` - (Array<String>) A list of headers allowed
761
+ # in a pre-flight OPTIONS request via the
762
+ # Access-Control-Request-Headers header. Each header name
763
+ # specified in the Access-Control-Request-Headers header must
764
+ # have a corresponding entry in the rule.
765
+ # Amazon S3 will send only the allowed headers in a response
766
+ # that were requested. This can contain at most one * wild
767
+ # character.
768
+ # * `:max_age_seconds` - (Integer) The time in seconds that your
769
+ # browser is to cache the preflight response for the specified
770
+ # resource.
771
+ # * `:expose_headers` - (Array<String>) One or more headers in
772
+ # the response that you want customers to be able to access
773
+ # from their applications (for example, from a JavaScript
774
+ # XMLHttpRequest object).
775
+ # @return [Core::Response]
776
+ bucket_method(:put_bucket_cors, :put) do
777
+ configure_request do |req, options|
778
+
779
+ req.add_param('cors')
780
+
781
+ options[:rules].each do |rule|
782
+ require_allowed_methods!(rule[:allowed_methods])
783
+ require_allowed_origins!(rule[:allowed_origins])
784
+ end
785
+
786
+ xml = Nokogiri::XML::Builder.new do |xml|
787
+ xml.CORSConfiguration do
788
+ options[:rules].each do |rule|
789
+ xml.CORSRule do
790
+
791
+ xml.ID(rule[:id]) if rule[:id]
792
+
793
+ (rule[:allowed_methods] || []).each do |method|
794
+ xml.AllowedMethod(method)
795
+ end
796
+
797
+ (rule[:allowed_origins] || []).each do |origin|
798
+ xml.AllowedOrigin(origin)
799
+ end
800
+
801
+ (rule[:allowed_headers] || []).each do |header|
802
+ xml.AllowedHeader(header)
803
+ end
804
+
805
+ xml.MaxAgeSeconds(rule[:max_age_seconds]) if
806
+ rule[:max_age_seconds]
807
+
808
+ (rule[:expose_headers] || []).each do |header|
809
+ xml.ExposeHeader(header)
810
+ end
811
+
812
+ end
813
+ end
814
+ end
815
+ end.doc.root.to_xml
816
+
817
+ req.body = xml
818
+ req.headers['content-md5'] = md5(xml)
819
+
820
+ super(req, options)
821
+
822
+ end
823
+ end
824
+
825
+ # @overload get_bucket_cors(options = {})
826
+ # @param [Hash] options
827
+ # @option options [required,String] :bucket_name
828
+ # @return [Core::Response]
829
+ bucket_method(:get_bucket_cors, :get) do
830
+
831
+ configure_request do |req, options|
832
+ req.add_param('cors')
833
+ super(req, options)
834
+ end
835
+
836
+ process_response do |resp|
837
+ resp.data = XML::GetBucketCors.parse(resp.http_response.body)
838
+ end
839
+
840
+ end
841
+
842
+ # @overload delete_bucket_cors(options = {})
843
+ # @param [Hash] options
844
+ # @option options [required,String] :bucket_name
845
+ # @return [Core::Response]
846
+ bucket_method(:delete_bucket_cors, :delete) do
847
+ configure_request do |req, options|
848
+ req.add_param('cors')
849
+ super(req, options)
850
+ end
851
+ end
852
+
853
+ # @overload put_bucket_tagging(options = {})
854
+ # @param [Hash] options
855
+ # @option options [required,String] :bucket_name
856
+ # @option options [Hash] :tags
857
+ # @return [Core::Response]
858
+ bucket_method(:put_bucket_tagging, :put) do
859
+ configure_request do |req, options|
860
+
861
+ req.add_param('tagging')
862
+
863
+ xml = Nokogiri::XML::Builder.new
864
+ xml.Tagging do |xml|
865
+ xml.TagSet do
866
+ options[:tags].each_pair do |key,value|
867
+ xml.Tag do
868
+ xml.Key(key)
869
+ xml.Value(value)
870
+ end
871
+ end
872
+ end
873
+ end
874
+
875
+ xml = xml.doc.root.to_xml
876
+ req.body = xml
877
+ req.headers['content-md5'] = md5(xml)
878
+
879
+ super(req, options)
880
+
881
+ end
882
+ end
883
+
884
+ # @overload get_bucket_tagging(options = {})
885
+ # @param [Hash] options
886
+ # @option options [required,String] :bucket_name
887
+ # @return [Core::Response]
888
+ bucket_method(:get_bucket_tagging, :get) do
889
+
890
+ configure_request do |req, options|
891
+ req.add_param('tagging')
892
+ super(req, options)
893
+ end
894
+
895
+ process_response do |resp|
896
+ resp.data = XML::GetBucketTagging.parse(resp.http_response.body)
897
+ end
898
+
899
+ end
900
+
901
+ # @overload delete_bucket_tagging(options = {})
902
+ # @param [Hash] options
903
+ # @option options [required,String] :bucket_name
904
+ # @return [Core::Response]
905
+ bucket_method(:delete_bucket_tagging, :delete) do
906
+ configure_request do |req, options|
907
+ req.add_param('tagging')
908
+ super(req, options)
909
+ end
910
+ end
911
+
912
+ # @overload list_buckets(options = {})
913
+ # @param [Hash] options
914
+ # @return [Core::Response]
915
+ add_client_request_method(:list_buckets) do
916
+
917
+ configure_request do |req, options|
918
+ req.http_method = "GET"
919
+ end
920
+
921
+ process_response do |resp|
922
+ resp.data = XML::ListBuckets.parse(resp.http_response.body)
923
+ end
924
+
925
+ simulate_response do |resp|
926
+ resp.data = Core::XML::Parser.new(XML::ListBuckets.rules).simulate
927
+ end
928
+
929
+ end
930
+
931
+ # Sets the access policy for a bucket.
932
+ # @overload set_bucket_policy(options = {})
933
+ # @param [Hash] options
934
+ # @option options [required,String] :bucket_name
935
+ # @option options [required,String] :policy This can be a String
936
+ # or any object that responds to `#to_json`.
937
+ # @return [Core::Response]
938
+ bucket_method(:set_bucket_policy, :put, 'policy') do
939
+
940
+ configure_request do |req, options|
941
+ require_policy!(options[:policy])
942
+ super(req, options)
943
+ policy = options[:policy]
944
+ policy = policy.to_json unless policy.respond_to?(:to_str)
945
+ req.body = policy
946
+ end
947
+
948
+ end
949
+
950
+ # Gets the access policy for a bucket.
951
+ # @overload get_bucket_policy(options = {})
952
+ # @param [Hash] options
953
+ # @option options [required,String] :bucket_name
954
+ # @return [Core::Response]
955
+ bucket_method(:get_bucket_policy, :get, 'policy') do
956
+
957
+ process_response do |resp|
958
+ resp.data[:policy] = resp.http_response.body
959
+ end
960
+
961
+ end
962
+
963
+ # Deletes the access policy for a bucket.
964
+ # @overload delete_bucket_policy(options = {})
965
+ # @param [Hash] options
966
+ # @option options [required,String] :bucket_name
967
+ # @return [Core::Response]
968
+ bucket_method(:delete_bucket_policy, :delete, 'policy')
969
+
970
+ # @overload set_bucket_versioning(options = {})
971
+ # @param [Hash] options
972
+ # @option options [required,String] :bucket_name
973
+ # @option options [required,String] :state
974
+ # @option options [String] :mfa_delete
975
+ # @option options [String] :mfa
976
+ # @return [Core::Response]
977
+ bucket_method(:set_bucket_versioning, :put, 'versioning', :header_options => { :mfa => "x-amz-mfa" }) do
978
+
979
+ configure_request do |req, options|
980
+ state = options[:state].to_s.downcase.capitalize
981
+ unless state =~ /^(Enabled|Suspended)$/
982
+ raise ArgumentError, "invalid versioning state `#{state}`"
983
+ end
984
+
985
+ # Leave validation of MFA options to S3
986
+ mfa_delete = options[:mfa_delete].to_s.downcase.capitalize if options[:mfa_delete]
987
+
988
+ # Generate XML request for versioning
989
+ req.body = Nokogiri::XML::Builder.new do |xml|
990
+ xml.VersioningConfiguration('xmlns' => XMLNS) do
991
+ xml.Status(state)
992
+ xml.MfaDelete(mfa_delete) if mfa_delete
993
+ end
994
+ end.doc.root.to_xml
995
+
996
+ super(req, options)
997
+ end
998
+
999
+ end
1000
+
1001
+ # Gets the bucket's location constraint.
1002
+ # @overload get_bucket_location(options = {})
1003
+ # @param [Hash] options
1004
+ # @option options [required,String] :bucket_name
1005
+ # @return [Core::Response]
1006
+ bucket_method(:get_bucket_location, :get, 'location') do
1007
+
1008
+ process_response do |response|
1009
+ regex = />(.*)<\/LocationConstraint>/
1010
+ matches = response.http_response.body.to_s.match(regex)
1011
+ response.data[:location_constraint] = matches ? matches[1] : nil
1012
+ end
1013
+
1014
+ end
1015
+
1016
+ # @overload put_bucket_logging(options = {})
1017
+ # @param [Hash] options
1018
+ # @option options [required,String] :bucket_name
1019
+ # @option options [Boolean] :logging_enabled Set to true if turning on
1020
+ # bucket logging. If not set or false, all of the following options
1021
+ # will be ignored.
1022
+ # @option options [String] :target_bucket The name of the bucket in
1023
+ # which you want Amazon S3 to store server access logs. You can push
1024
+ # logs to any bucket you own, including the bucket being logged.
1025
+ # @option options [String] :target_prefix Allows you to specify a prefix
1026
+ # for the keys that the log files will be stored under. Recommended
1027
+ # if you will be writing logs from multiple buckets to the same target
1028
+ # bucket.
1029
+ # @option options [Array<Hash>] :grants An array of hashes specifying
1030
+ # permission grantees. For each hash, specify ONLY ONE of :id, :uri,
1031
+ # or :email_address.
1032
+ # * `:email_address` - (String) E-mail address of the person being
1033
+ # granted logging permissions.
1034
+ # * `:id` - (String) The canonical user ID of the grantee.
1035
+ # * `:uri` - (String) URI of the grantee group.
1036
+ # * `:permission` - (String) Logging permissions given to the Grantee
1037
+ # for the bucket. The bucket owner is automatically granted FULL_CONTROL
1038
+ # to all logs delivered to the bucket. This optional element enables
1039
+ # you grant access to others. Valid Values: FULL_CONTROL | READ | WRITE
1040
+ # @return [Core::Response]
1041
+ bucket_method(:put_bucket_logging, :put) do
1042
+ configure_request do |req, options|
1043
+
1044
+ req.add_param('logging')
1045
+
1046
+ xml = Nokogiri::XML::Builder.new
1047
+ xml.BucketLoggingStatus('xmlns' => XMLNS) do |xml|
1048
+ if options[:logging_enabled] == true
1049
+ xml.LoggingEnabled do
1050
+ xml.TargetBucket(options[:target_bucket])
1051
+ xml.TargetPrefix(options[:target_prefix])
1052
+ unless options[:grants].nil?
1053
+
1054
+ xml.TargetGrants do
1055
+ options[:grants].each do |grant|
1056
+ xml.Grant do
1057
+ if !grant[:email_address].nil?
1058
+ xml.Grantee('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
1059
+ 'xsi:type' => 'AmazonCustomerByEmail') do
1060
+ xml.EmailAddress(grant[:email_address])
1061
+ end
1062
+ elsif !grant[:uri].nil?
1063
+ xml.Grantee('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
1064
+ 'xsi:type' => 'Group') do
1065
+ xml.URI(grant[:uri])
1066
+ end
1067
+ elsif !grant[:id].nil?
1068
+ xml.Grantee('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
1069
+ 'xsi:type' => 'CanonicalUser') do
1070
+ xml.ID(grant[:id])
1071
+ end
1072
+ end
1073
+
1074
+ xml.Permission(grant[:permission])
1075
+ end
1076
+ end
1077
+ end
1078
+ end
1079
+ end
1080
+ end
1081
+ end
1082
+
1083
+ xml = xml.doc.root.to_xml
1084
+ req.body = xml
1085
+ req.headers['content-md5'] = md5(xml)
1086
+
1087
+ super(req, options)
1088
+
1089
+ end
1090
+ end
1091
+
1092
+ # Gets the bucket's logging status.
1093
+ # @overload get_bucket_logging(options = {})
1094
+ # @param [Hash] options
1095
+ # @option options [required,String] :bucket_name
1096
+ # @return [Core::Response]
1097
+ bucket_method(:get_bucket_logging, :get, 'logging',
1098
+ XML::GetBucketLogging)
1099
+
1100
+ # @overload get_bucket_versioning(options = {})
1101
+ # @param [Hash] options
1102
+ # @option options [required,String] :bucket_name
1103
+ # @return [Core::Response]
1104
+ bucket_method(:get_bucket_versioning, :get, 'versioning',
1105
+ XML::GetBucketVersioning)
1106
+
1107
+ # @overload list_object_versions(options = {})
1108
+ # @param [Hash] options
1109
+ # @option options [required,String] :bucket_name
1110
+ # @option options [String] :prefix
1111
+ # @option options [String] :delimiter
1112
+ # @option options [String] :max_keys
1113
+ # @option options [String] :key_marker
1114
+ # @option options [String] :version_id_marker
1115
+ # @return [Core::Response]
1116
+ bucket_method(:list_object_versions, :get, 'versions',
1117
+ XML::ListObjectVersions) do
1118
+
1119
+ configure_request do |req, options|
1120
+ super(req, options)
1121
+ params = %w(delimiter key_marker max_keys prefix version_id_marker)
1122
+ params.each do |param|
1123
+ if options[param.to_sym]
1124
+ req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
1125
+ end
1126
+ end
1127
+ end
1128
+
1129
+ end
1130
+
1131
+ # Sets the access control list for a bucket. You must specify an ACL
1132
+ # via one of the following methods:
1133
+ #
1134
+ # * as a canned ACL (via `:acl`)
1135
+ # * as a list of grants (via the `:grant_*` options)
1136
+ # * as an access control policy document (via `:access_control_policy`)
1137
+ #
1138
+ # @example Using a canned acl
1139
+ # s3_client.put_bucket_acl(
1140
+ # :bucket_name => 'bucket-name',
1141
+ # :acl => 'public-read')
1142
+ #
1143
+ # @example Using grants
1144
+ # s3_client.put_bucket_acl(
1145
+ # :bucket_name => 'bucket-name',
1146
+ # :grant_read => 'uri="http://acs.amazonaws.com/groups/global/AllUsers"',
1147
+ # :grant_full_control => 'emailAddress="xyz@amazon.com", id="8a9...fa7"')
1148
+ #
1149
+ # @example Using an access control policy document
1150
+ # policy_xml = <<-XML
1151
+ # <AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
1152
+ # <Owner>
1153
+ # <ID>852b113e7a2f25102679df27bb0ae12b3f85be6BucketOwnerCanonicalUserID</ID>
1154
+ # <DisplayName>OwnerDisplayName</DisplayName>
1155
+ # </Owner>
1156
+ # <AccessControlList>
1157
+ # <Grant>
1158
+ # <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
1159
+ # <ID>BucketOwnerCanonicalUserID</ID>
1160
+ # <DisplayName>OwnerDisplayName</DisplayName>
1161
+ # </Grantee>
1162
+ # <Permission>FULL_CONTROL</Permission>
1163
+ # </Grant>
1164
+ # <Grant>
1165
+ # <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
1166
+ # <URI xmlns="">http://acs.amazonaws.com/groups/global/AllUsers</URI>
1167
+ # </Grantee>
1168
+ # <Permission xmlns="">READ</Permission>
1169
+ # </Grant>
1170
+ # </AccessControlList>
1171
+ # </AccessControlPolicy>
1172
+ #
1173
+ # XML
1174
+ # s3_client.put_bucket_acl(
1175
+ # :bucket_name => 'bucket-name',
1176
+ # :access_control_policy => policy_xml)
1177
+ #
1178
+ # @overload put_bucket_acl(options = {})
1179
+ # @param [Hash] options
1180
+ # @option options [required,String] :bucket_name
1181
+ # @option options [String] :access_control_policy An access control
1182
+ # policy description as a string of XML. See the S3 API
1183
+ # documentation for a description.
1184
+ # @option options [String] :acl A canned ACL (e.g. 'private',
1185
+ # 'public-read', etc). See the S3 API documentation for
1186
+ # a complete list of valid values.
1187
+ # @option options [String] :grant_read
1188
+ # @option options [String] :grant_write
1189
+ # @option options [String] :grant_read_acp
1190
+ # @option options [String] :grant_write_acp
1191
+ # @option options [String] :grant_full_control
1192
+ # @return [Core::Response]
1193
+ bucket_method(:put_bucket_acl, :put, 'acl', :header_options => {
1194
+ :acl => 'x-amz-acl',
1195
+ :grant_read => 'x-amz-grant-read',
1196
+ :grant_write => 'x-amz-grant-write',
1197
+ :grant_read_acp => 'x-amz-grant-read-acp',
1198
+ :grant_write_acp => 'x-amz-grant-write-acp',
1199
+ :grant_full_control => 'x-amz-grant-full-control',
1200
+ }) do
1201
+
1202
+ configure_request do |req, options|
1203
+ move_access_control_policy(options)
1204
+ require_acl!(options)
1205
+ super(req, options)
1206
+ req.body = options[:access_control_policy] if
1207
+ options[:access_control_policy]
1208
+ end
1209
+
1210
+ end
1211
+ alias_method :set_bucket_acl, :put_bucket_acl
1212
+
1213
+ # Gets the access control list for a bucket.
1214
+ # @overload get_bucket_acl(options = {})
1215
+ # @param [Hash] options
1216
+ # @option options [required,String] :bucket_name
1217
+ # @return [Core::Response]
1218
+ bucket_method(:get_bucket_acl, :get, 'acl', XML::GetBucketAcl)
1219
+
1220
+ # Sets the access control list for an object. You must specify an ACL
1221
+ # via one of the following methods:
1222
+ #
1223
+ # * as a canned ACL (via `:acl`)
1224
+ # * as a list of grants (via the `:grant_*` options)
1225
+ # * as an access control policy document (via `:access_control_policy`)
1226
+ #
1227
+ # @example Using a canned acl
1228
+ # s3_client.put_object_acl(
1229
+ # :bucket_name => 'bucket-name',
1230
+ # :key => 'object-key',
1231
+ # :acl => 'public-read')
1232
+ #
1233
+ # @example Using grants
1234
+ # s3_client.put_bucket_acl(
1235
+ # :bucket_name => 'bucket-name',
1236
+ # :key => 'object-key',
1237
+ # :grant_read => 'uri="http://acs.amazonaws.com/groups/global/AllUsers"',
1238
+ # :grant_full_control => 'emailAddress="xyz@amazon.com", id="8a9...fa7"')
1239
+ #
1240
+ # @example Using an access control policy document
1241
+ # policy_xml = <<-XML
1242
+ # <AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
1243
+ # <Owner>
1244
+ # <ID>852b113e7a2f25102679df27bb0ae12b3f85be6BucketOwnerCanonicalUserID</ID>
1245
+ # <DisplayName>OwnerDisplayName</DisplayName>
1246
+ # </Owner>
1247
+ # <AccessControlList>
1248
+ # <Grant>
1249
+ # <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
1250
+ # <ID>BucketOwnerCanonicalUserID</ID>
1251
+ # <DisplayName>OwnerDisplayName</DisplayName>
1252
+ # </Grantee>
1253
+ # <Permission>FULL_CONTROL</Permission>
1254
+ # </Grant>
1255
+ # <Grant>
1256
+ # <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
1257
+ # <URI xmlns="">http://acs.amazonaws.com/groups/global/AllUsers</URI>
1258
+ # </Grantee>
1259
+ # <Permission xmlns="">READ</Permission>
1260
+ # </Grant>
1261
+ # </AccessControlList>
1262
+ # </AccessControlPolicy>
1263
+ #
1264
+ # XML
1265
+ # s3_client.put_bucket_acl(
1266
+ # :bucket_name => 'bucket-name',
1267
+ # :key => 'object-key',
1268
+ # :access_control_policy => policy_xml)
1269
+ #
1270
+ # @overload put_object_acl(options = {})
1271
+ # @param [Hash] options
1272
+ # @option options [required,String] :bucket_name
1273
+ # @option options [required,String] :key
1274
+ # @option options [String] :access_control_policy An access control
1275
+ # policy description as a string of XML. See the S3 API
1276
+ # documentation for a description.
1277
+ # @option options [String] :acl A canned ACL (e.g. 'private',
1278
+ # 'public-read', etc). See the S3 API documentation for
1279
+ # a complete list of valid values.
1280
+ # @option options [String] :grant_read
1281
+ # @option options [String] :grant_write
1282
+ # @option options [String] :grant_read_acp
1283
+ # @option options [String] :grant_write_acp
1284
+ # @option options [String] :grant_full_control
1285
+ # @return [Core::Response]
1286
+ object_method(:put_object_acl, :put, 'acl', :header_options => {
1287
+ :acl => 'x-amz-acl',
1288
+ :grant_read => 'x-amz-grant-read',
1289
+ :grant_write => 'x-amz-grant-write',
1290
+ :grant_read_acp => 'x-amz-grant-read-acp',
1291
+ :grant_write_acp => 'x-amz-grant-write-acp',
1292
+ :grant_full_control => 'x-amz-grant-full-control',
1293
+ }) do
1294
+
1295
+ configure_request do |req, options|
1296
+ move_access_control_policy(options)
1297
+ require_acl!(options)
1298
+ super(req, options)
1299
+ req.body = options[:access_control_policy] if
1300
+ options[:access_control_policy]
1301
+ end
1302
+
1303
+ end
1304
+ alias_method :set_object_acl, :put_object_acl
1305
+
1306
+ # Gets the access control list for an object.
1307
+ # @overload get_object_acl(options = {})
1308
+ # @param [Hash] options
1309
+ # @option options [required,String] :bucket_name
1310
+ # @option options [required,String] :key
1311
+ # @return [Core::Response]
1312
+ object_method(:get_object_acl, :get, 'acl', XML::GetBucketAcl)
1313
+
1314
+ # Puts data into an object, replacing the current contents.
1315
+ #
1316
+ # s3_client.put_object({
1317
+ # :bucket_name => 'bucket-name',
1318
+ # :key => 'readme.txt',
1319
+ # :data => 'This is the readme for ...',
1320
+ # })
1321
+ #
1322
+ # @overload put_object(options = {})
1323
+ # @param [Hash] options
1324
+ # @option options [required,String] :bucket_name
1325
+ # @option options [required,String] :key
1326
+ # @option options [required,String,Pathname,File,IO] :data
1327
+ # The data to upload. This can be provided as a string,
1328
+ # a Pathname object, or any object that responds to
1329
+ # `#read` and `#eof?` (e.g. IO, File, Tempfile, StringIO, etc).
1330
+ # @option options [Integer] :content_length
1331
+ # Required if you are using block form to write data or if it is
1332
+ # not possible to determine the size of `:data`. A best effort
1333
+ # is made to determine the content length of strings, files,
1334
+ # tempfiles, io objects, and any object that responds
1335
+ # to `#length` or `#size`.
1336
+ # @option options [String] :website_redirect_location If the bucket is
1337
+ # configured as a website, redirects requests for this object to
1338
+ # another object in the same bucket or to an external URL.
1339
+ # @option options [Hash] :metadata
1340
+ # A hash of metadata to be included with the
1341
+ # object. These will be sent to S3 as headers prefixed with
1342
+ # `x-amz-meta`.
1343
+ # @option options [Symbol] :acl (:private) A canned access
1344
+ # control policy. Accepted values include:
1345
+ # * `:private`
1346
+ # * `:public_read`
1347
+ # * ...
1348
+ # @option options [String] :storage_class+ ('STANDARD')
1349
+ # Controls whether Reduced Redundancy Storage is enabled for
1350
+ # the object. Valid values are 'STANDARD' and
1351
+ # 'REDUCED_REDUNDANCY'.
1352
+ # @option options [Symbol,String] :server_side_encryption (nil) The
1353
+ # algorithm used to encrypt the object on the server side
1354
+ # (e.g. :aes256).
1355
+ # object on the server side, e.g. `:aes256`)
1356
+ # @option options [String] :cache_control
1357
+ # Can be used to specify caching behavior.
1358
+ # @option options [String] :content_disposition
1359
+ # Specifies presentational information.
1360
+ # @option options [String] :content_encoding
1361
+ # Specifies the content encoding.
1362
+ # @option options [String] :content_md5
1363
+ # The base64 encoded content md5 of the `:data`.
1364
+ # @option options [String] :content_type
1365
+ # Specifies the content type.
1366
+ # @option options [String] :expires The date and time at which the
1367
+ # object is no longer cacheable.
1368
+ # @option options [String] :acl A canned ACL (e.g. 'private',
1369
+ # 'public-read', etc). See the S3 API documentation for
1370
+ # a complete list of valid values.
1371
+ # @option options [String] :grant_read
1372
+ # @option options [String] :grant_write
1373
+ # @option options [String] :grant_read_acp
1374
+ # @option options [String] :grant_write_acp
1375
+ # @option options [String] :grant_full_control
1376
+ # @option options [String] :sse_customer_algorithm Specifies the
1377
+ # algorithm to use to when encrypting the object (e.g., AES256).
1378
+ # @option options [String] :sse_customer_key Specifies the
1379
+ # customer-provided encryption key for Amazon S3 to use in encrypting
1380
+ # data. This value is used to store the object and then it is
1381
+ # discarded; Amazon does not store the encryption key. The key must be
1382
+ # appropriate for use with the algorithm specified in the
1383
+ # `:sse_customer_algorithm` header.
1384
+ # @option options [String] :sse_customer_key_md5 Specifies the 128-bit
1385
+ # MD5 digest of the encryption key according to RFC 1321. Amazon S3
1386
+ # uses this header for a message integrity check to ensure the
1387
+ # encryption key was transmitted without error.
1388
+ # @return [Core::Response]
1389
+ #
1390
+ object_method(:put_object, :put, :header_options => {
1391
+ :website_redirect_location => 'x-amz-website-redirect-location',
1392
+ :acl => 'x-amz-acl',
1393
+ :grant_read => 'x-amz-grant-read',
1394
+ :grant_write => 'x-amz-grant-write',
1395
+ :grant_read_acp => 'x-amz-grant-read-acp',
1396
+ :grant_write_acp => 'x-amz-grant-write-acp',
1397
+ :grant_full_control => 'x-amz-grant-full-control',
1398
+ :content_md5 => 'Content-MD5',
1399
+ :cache_control => 'Cache-Control',
1400
+ :content_disposition => 'Content-Disposition',
1401
+ :content_encoding => 'Content-Encoding',
1402
+ :content_type => 'Content-Type',
1403
+ :expires => 'Expires',
1404
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
1405
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
1406
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
1407
+ }) do
1408
+
1409
+ configure_request do |request, options|
1410
+
1411
+ options = compute_write_options(options)
1412
+ set_body_stream_and_content_length(request, options)
1413
+
1414
+ set_metadata(request, options)
1415
+ set_storage_class(request, options)
1416
+ set_server_side_encryption(request, options)
1417
+
1418
+ super(request, options)
1419
+
1420
+ end
1421
+
1422
+ process_response do |resp|
1423
+ extract_object_headers(resp)
1424
+ end
1425
+
1426
+ simulate_response do |response|
1427
+ response.data[:etag] = 'abc123'
1428
+ response.data[:version_id] = nil
1429
+ end
1430
+
1431
+ end
1432
+
1433
+ # Gets the data for a key.
1434
+ # @overload get_object(options = {})
1435
+ # @param [Hash] options
1436
+ # @option options [required,String] :bucket_name
1437
+ # @option options [required,String] :key
1438
+ # @option options [String] :request_payer If specified, the request
1439
+ # will contain the specified String value in the x-amz-request-payer
1440
+ # header. This is required for Requester Pays enabled buckets.
1441
+ # @option options [Time] :if_modified_since If specified, the
1442
+ # response will contain an additional `:modified` value that
1443
+ # returns true if the object was modified after the given
1444
+ # time. If `:modified` is false, then the response
1445
+ # `:data` value will be `nil`.
1446
+ # @option options [Time] :if_unmodified_since If specified, the
1447
+ # response will contain an additional `:unmodified` value
1448
+ # that is true if the object was not modified after the
1449
+ # given time. If `:unmodified` returns false, the `:data`
1450
+ # value will be `nil`.
1451
+ # @option options [String] :if_match If specified, the response
1452
+ # will contain an additional `:matches` value that is true
1453
+ # if the object ETag matches the value for this option. If
1454
+ # `:matches` is false, the `:data` value of the
1455
+ # response will be `nil`.
1456
+ # @option options [String] :if_none_match If specified, the
1457
+ # response will contain an additional `:matches` value that
1458
+ # is true if and only if the object ETag matches the value for
1459
+ # this option. If `:matches` is true, the `:data` value
1460
+ # of the response will be `nil`.
1461
+ # @option options [String] :sse_customer_algorithm Specifies the
1462
+ # algorithm to use to when encrypting the object (e.g., AES256).
1463
+ # @option options [String] :sse_customer_key Specifies the
1464
+ # customer-provided encryption key for Amazon S3 to use in encrypting
1465
+ # data. This value is used to store the object and then it is
1466
+ # discarded; Amazon does not store the encryption key. The key must be
1467
+ # appropriate for use with the algorithm specified in the
1468
+ # `:sse_customer_algorithm` header.
1469
+ # @option options [String] :sse_customer_key_md5 Specifies the 128-bit
1470
+ # MD5 digest of the encryption key according to RFC 1321. Amazon S3
1471
+ # uses this header for a message integrity check to ensure the
1472
+ # encryption key was transmitted without error.
1473
+ # @option options [Range<Integer>] :range A byte range of data to request.
1474
+ # @return [Core::Response]
1475
+ #
1476
+ object_method(:get_object, :get,
1477
+ :header_options => {
1478
+ :request_payer => "x-amz-request-payer",
1479
+ :if_modified_since => "If-Modified-Since",
1480
+ :if_unmodified_since => "If-Unmodified-Since",
1481
+ :if_match => "If-Match",
1482
+ :if_none_match => "If-None-Match",
1483
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
1484
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
1485
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
1486
+ }) do
1487
+ configure_request do |req, options|
1488
+
1489
+ super(req, options)
1490
+
1491
+ if options[:version_id]
1492
+ req.add_param('versionId', options[:version_id])
1493
+ end
1494
+
1495
+ ["If-Modified-Since",
1496
+ "If-Unmodified-Since"].each do |date_header|
1497
+ case value = req.headers[date_header]
1498
+ when DateTime
1499
+ req.headers[date_header] = Time.parse(value.to_s).rfc2822
1500
+ when Time
1501
+ req.headers[date_header] = value.rfc2822
1502
+ end
1503
+ end
1504
+
1505
+ if options[:range]
1506
+ range = options[:range]
1507
+ if range.is_a?(Range)
1508
+ offset = range.exclude_end? ? -1 : 0
1509
+ range = "bytes=#{range.first}-#{range.last + offset}"
1510
+ end
1511
+ req.headers['Range'] = range
1512
+ end
1513
+
1514
+ end
1515
+
1516
+ process_response do |resp|
1517
+ extract_object_headers(resp)
1518
+ resp.data[:data] = resp.http_response.body
1519
+ end
1520
+
1521
+ end
1522
+
1523
+ # Gets the torrent for a key.
1524
+ # @overload get_object_torrent(options = {})
1525
+ # @param [Hash] options
1526
+ # @option options [required,String] :bucket_name
1527
+ # @option options [required,String] :key
1528
+ # @return [Core::Response]
1529
+ #
1530
+ object_method(:get_object_torrent, :get, 'torrent') do
1531
+ process_response do |resp|
1532
+ extract_object_headers(resp)
1533
+ resp.data[:data] = resp.http_response.body
1534
+ end
1535
+ end
1536
+
1537
+ # @overload head_object(options = {})
1538
+ # @param [Hash] options
1539
+ # @option options [required,String] :bucket_name
1540
+ # @option options [required,String] :key
1541
+ # @option options [String] :version_id
1542
+ # @option options [Time] :if_modified_since If specified, the
1543
+ # response will contain an additional `:modified` value that
1544
+ # returns true if the object was modified after the given
1545
+ # time. If `:modified` is false, then the response
1546
+ # `:data` value will be `nil`.
1547
+ # @option options [Time] :if_unmodified_since If specified, the
1548
+ # response will contain an additional `:unmodified` value
1549
+ # that is true if the object was not modified after the
1550
+ # given time. If `:unmodified` returns false, the `:data`
1551
+ # value will be `nil`.
1552
+ # @option options [String] :if_match If specified, the response
1553
+ # will contain an additional `:matches` value that is true
1554
+ # if the object ETag matches the value for this option. If
1555
+ # `:matches` is false, the `:data` value of the
1556
+ # response will be `nil`.
1557
+ # @option options [String] :if_none_match If specified, the
1558
+ # response will contain an additional `:matches` value that
1559
+ # is true if and only if the object ETag matches the value for
1560
+ # this option. If `:matches` is true, the `:data` value
1561
+ # of the response will be `nil`.
1562
+ # @option options [String] :sse_customer_algorithm Specifies the
1563
+ # algorithm to use to when encrypting the object (e.g., AES256).
1564
+ # @option options [String] :sse_customer_key Specifies the
1565
+ # customer-provided encryption key for Amazon S3 to use in encrypting
1566
+ # data. This value is used to store the object and then it is
1567
+ # discarded; Amazon does not store the encryption key. The key must be
1568
+ # appropriate for use with the algorithm specified in the
1569
+ # `:sse_customer_algorithm` header.
1570
+ # @option options [String] :sse_customer_key_md5 Specifies the 128-bit
1571
+ # MD5 digest of the encryption key according to RFC 1321. Amazon S3
1572
+ # uses this header for a message integrity check to ensure the
1573
+ # encryption key was transmitted without error.
1574
+ # @option options [Range<Integer>] :range A byte range of data to request.
1575
+ # @return [Core::Response]
1576
+ object_method(:head_object, :head,
1577
+ :header_options => {
1578
+ :if_modified_since => "If-Modified-Since",
1579
+ :if_unmodified_since => "If-Unmodified-Since",
1580
+ :if_match => "If-Match",
1581
+ :if_none_match => "If-None-Match",
1582
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
1583
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
1584
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
1585
+ }) do
1586
+
1587
+ configure_request do |req, options|
1588
+ super(req, options)
1589
+ if options[:version_id]
1590
+ req.add_param('versionId', options[:version_id])
1591
+ end
1592
+
1593
+ ["If-Modified-Since",
1594
+ "If-Unmodified-Since"].each do |date_header|
1595
+ case value = req.headers[date_header]
1596
+ when DateTime
1597
+ req.headers[date_header] = Time.parse(value.to_s).rfc2822
1598
+ when Time
1599
+ req.headers[date_header] = value.rfc2822
1600
+ end
1601
+ end
1602
+
1603
+ if options[:range]
1604
+ range = options[:range]
1605
+ if range.is_a?(Range)
1606
+ offset = range.exclude_end? ? -1 : 0
1607
+ range = "bytes=#{range.first}-#{range.last + offset}"
1608
+ end
1609
+ req.headers['Range'] = range
1610
+ end
1611
+ end
1612
+
1613
+ process_response do |resp|
1614
+ extract_object_headers(resp)
1615
+ end
1616
+
1617
+ end
1618
+
1619
+ # @overload delete_object(options = {})
1620
+ # @param [Hash] options
1621
+ # @option options [required,String] :bucket_name
1622
+ # @option options [required,String] :key
1623
+ # @option options [String] :version_id
1624
+ # @option options [String] :mfa
1625
+ # @return [Core::Response]
1626
+ object_method(:delete_object, :delete, :header_options => { :mfa => "x-amz-mfa" }) do
1627
+
1628
+ configure_request do |req, options|
1629
+ super(req, options)
1630
+ if options[:version_id]
1631
+ req.add_param('versionId', options[:version_id])
1632
+ end
1633
+ end
1634
+
1635
+ process_response do |resp|
1636
+ resp.data[:version_id] = resp.http_response.header('x-amz-version-id')
1637
+ end
1638
+
1639
+ end
1640
+
1641
+ # @overload restore_object(options = {})
1642
+ # Restores a temporary copy of an archived object.
1643
+ # @param [Hash] options
1644
+ # @option options [required,String] :bucket_name
1645
+ # @option options [required,String] :key
1646
+ # @option options [required,Integer] :days the number of days to keep
1647
+ # the restored object.
1648
+ # @return [Core::Response]
1649
+ # @since 1.7.2
1650
+ object_method(:restore_object, :post, 'restore',
1651
+ :header_options => { :content_md5 => 'Content-MD5' }) do
1652
+ configure_request do |req, options|
1653
+ super(req, options)
1654
+
1655
+ validate!(:days, options[:days]) do
1656
+ "must be greater or equal to 1" if options[:days].to_i <= 0
1657
+ end
1658
+
1659
+ xml = Nokogiri::XML::Builder.new do |xml|
1660
+ xml.RestoreRequest('xmlns' => XMLNS) do
1661
+ xml.Days(options[:days].to_i) if options[:days]
1662
+ end
1663
+ end.doc.root.to_xml
1664
+
1665
+ req.body = xml
1666
+ req.headers['content-type'] = 'application/xml'
1667
+ req.headers['content-md5'] = md5(xml)
1668
+ end
1669
+ end
1670
+
1671
+
1672
+ # @overload list_objects(options = {})
1673
+ # @param [Hash] options
1674
+ # @option options [required,String] :bucket_name
1675
+ # @option options [String] :delimiter
1676
+ # @option options [String] :marker
1677
+ # @option options [String] :max_keys
1678
+ # @option options [String] :prefix
1679
+ # @return [Core::Response]
1680
+ bucket_method(:list_objects, :get, XML::ListObjects) do
1681
+ configure_request do |req, options|
1682
+ super(req, options)
1683
+ params = %w(delimiter marker max_keys prefix)
1684
+ params.each do |param|
1685
+ if options[param.to_sym]
1686
+ req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
1687
+ end
1688
+ end
1689
+ end
1690
+ end
1691
+
1692
+ alias_method :get_bucket, :list_objects
1693
+
1694
+ # @overload initiate_multipart_upload(options = {})
1695
+ # @param [Hash] options
1696
+ # @option options [required,String] :bucket_name
1697
+ # @option options [required,String] :key
1698
+ # @option options [String] :website_redirect_location If the bucket is
1699
+ # configured as a website, redirects requests for this object to
1700
+ # another object in the same bucket or to an external URL.
1701
+ # @option options [Hash] :metadata
1702
+ # @option options [Symbol] :acl
1703
+ # @option options [String] :cache_control
1704
+ # @option options [String] :content_disposition
1705
+ # @option options [String] :content_encoding
1706
+ # @option options [String] :content_type
1707
+ # @option options [String] :storage_class+ ('STANDARD')
1708
+ # Controls whether Reduced Redundancy Storage is enabled for
1709
+ # the object. Valid values are 'STANDARD' and
1710
+ # 'REDUCED_REDUNDANCY'.
1711
+ # @option options [Symbol,String] :server_side_encryption (nil) The
1712
+ # algorithm used to encrypt the object on the server side
1713
+ # (e.g. :aes256).
1714
+ # @option options [String] :expires The date and time at which the
1715
+ # object is no longer cacheable.
1716
+ # @option options [String] :acl A canned ACL (e.g. 'private',
1717
+ # 'public-read', etc). See the S3 API documentation for
1718
+ # a complete list of valid values.
1719
+ # @option options [String] :grant_read
1720
+ # @option options [String] :grant_write
1721
+ # @option options [String] :grant_read_acp
1722
+ # @option options [String] :grant_write_acp
1723
+ # @option options [String] :grant_full_control
1724
+ # @option options [String] :sse_customer_algorithm Specifies the
1725
+ # algorithm to use to when encrypting the object (e.g., AES256).
1726
+ # @option options [String] :sse_customer_key Specifies the
1727
+ # customer-provided encryption key for Amazon S3 to use in encrypting
1728
+ # data. This value is used to store the object and then it is
1729
+ # discarded; Amazon does not store the encryption key. The key must be
1730
+ # appropriate for use with the algorithm specified in the
1731
+ # `:sse_customer_algorithm` header.
1732
+ # @option options [String] :sse_customer_key_md5 Specifies the 128-bit
1733
+ # MD5 digest of the encryption key according to RFC 1321. Amazon S3
1734
+ # uses this header for a message integrity check to ensure the
1735
+ # encryption key was transmitted without error.
1736
+ # @return [Core::Response]
1737
+ object_method(:initiate_multipart_upload, :post, 'uploads',
1738
+ XML::InitiateMultipartUpload,
1739
+ :header_options => {
1740
+ :website_redirect_location => 'x-amz-website-redirect-location',
1741
+ :acl => 'x-amz-acl',
1742
+ :grant_read => 'x-amz-grant-read',
1743
+ :grant_write => 'x-amz-grant-write',
1744
+ :grant_read_acp => 'x-amz-grant-read-acp',
1745
+ :grant_write_acp => 'x-amz-grant-write-acp',
1746
+ :grant_full_control => 'x-amz-grant-full-control',
1747
+ :cache_control => 'Cache-Control',
1748
+ :content_disposition => 'Content-Disposition',
1749
+ :content_encoding => 'Content-Encoding',
1750
+ :content_type => 'Content-Type',
1751
+ :expires => 'Expires',
1752
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
1753
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
1754
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
1755
+ }) do
1756
+
1757
+ configure_request do |req, options|
1758
+ set_metadata(req, options)
1759
+ set_storage_class(req, options)
1760
+ set_server_side_encryption(req, options)
1761
+ super(req, options)
1762
+ end
1763
+
1764
+ process_response do |resp|
1765
+ extract_object_headers(resp)
1766
+ end
1767
+
1768
+ end
1769
+
1770
+ # @overload list_multipart_uploads(options = {})
1771
+ # @param [Hash] options
1772
+ # @option options [required,String] :bucket_name
1773
+ # @option options [String] :delimiter
1774
+ # @option options [String] :key_marker
1775
+ # @option options [String] :max_keys
1776
+ # @option options [String] :upload_id_marker
1777
+ # @option options [String] :max_uploads
1778
+ # @option options [String] :prefix
1779
+ # @return [Core::Response]
1780
+ bucket_method(:list_multipart_uploads,
1781
+ :get, 'uploads',
1782
+ XML::ListMultipartUploads) do
1783
+ configure_request do |req, options|
1784
+ super(req, options)
1785
+ params = %w(delimiter key_marker max_keys) +
1786
+ %w(upload_id_marker max_uploads prefix)
1787
+ params.each do |param|
1788
+ if options[param.to_sym]
1789
+ req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
1790
+ end
1791
+ end
1792
+ end
1793
+ end
1794
+
1795
+ # @overload delete_objects(options = {})
1796
+ # @param [Hash] options
1797
+ # @option options [required,String] :bucket_name
1798
+ # @option options [required,Array<Hash>] :objects Each entry should be
1799
+ # a hash with the following keys:
1800
+ # * `:key` - *required*
1801
+ # * `:version_id`
1802
+ # @option options [Boolean] :quiet (true)
1803
+ # @option options [String] :mfa
1804
+ # @return [Core::Response]
1805
+ bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects,
1806
+ :header_options => { :mfa => "x-amz-mfa" }
1807
+ ) do
1808
+
1809
+ configure_request do |req, options|
1810
+
1811
+ super(req, options)
1812
+
1813
+ req.body = Nokogiri::XML::Builder.new do |xml|
1814
+ xml.Delete do
1815
+ xml.Quiet(options.key?(:quiet) ? options[:quiet] : true)
1816
+ (options[:objects] || options[:keys]).each do |obj|
1817
+ xml.Object do
1818
+ xml.Key(obj[:key])
1819
+ xml.VersionId(obj[:version_id]) if obj[:version_id]
1820
+ end
1821
+ end
1822
+ end
1823
+ end.doc.root.to_xml
1824
+
1825
+ req.headers['content-md5'] = md5(req.body)
1826
+
1827
+ end
1828
+ end
1829
+
1830
+ # @overload upload_part(options = {})
1831
+ # @param [Hash] options
1832
+ # @option options [required,String] :bucket_name
1833
+ # @option options [required,String] :key
1834
+ # @option options [required,String] :upload_id
1835
+ # @option options [required,Integer] :part_number
1836
+ # @option options [required,String,Pathname,File,IO] :data
1837
+ # The data to upload. This can be provided as a string,
1838
+ # a Pathname object, or any object that responds to
1839
+ # `#read` and `#eof?` (e.g. IO, File, Tempfile, StringIO, etc).
1840
+ # @return [Core::Response]
1841
+ object_method(:upload_part, :put,
1842
+ :header_options => {
1843
+ :content_md5 => 'Content-MD5',
1844
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
1845
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
1846
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
1847
+ }) do
1848
+ configure_request do |request, options|
1849
+
1850
+ options = compute_write_options(options)
1851
+ set_body_stream_and_content_length(request, options)
1852
+
1853
+ require_upload_id!(options[:upload_id])
1854
+ request.add_param('uploadId', options[:upload_id])
1855
+
1856
+ require_part_number!(options[:part_number])
1857
+ request.add_param('partNumber', options[:part_number])
1858
+
1859
+ super(request, options)
1860
+
1861
+ end
1862
+
1863
+ process_response do |resp|
1864
+ extract_object_headers(resp)
1865
+ end
1866
+
1867
+ simulate_response do |response|
1868
+ response.data[:etag] = 'abc123'
1869
+ end
1870
+ end
1871
+
1872
+ # @overload complete_multipart_upload(options = {})
1873
+ # @param [Hash] options
1874
+ # @option options [required,String] :bucket_name
1875
+ # @option options [required,String] :key
1876
+ # @option options [required,String] :upload_id
1877
+ # @option options [required,Array<Hash>] :parts An array of hashes
1878
+ # with the following keys:
1879
+ # * `:part_number` [Integer] - *required*
1880
+ # * `:etag` [String] - *required*
1881
+ # @return [Core::Response]
1882
+ object_method(:complete_multipart_upload, :post,
1883
+ XML::CompleteMultipartUpload) do
1884
+ configure_request do |req, options|
1885
+ require_upload_id!(options[:upload_id])
1886
+ validate_parts!(options[:parts])
1887
+ super(req, options)
1888
+ req.add_param('uploadId', options[:upload_id])
1889
+
1890
+ req.body = Nokogiri::XML::Builder.new do |xml|
1891
+ xml.CompleteMultipartUpload do
1892
+ options[:parts].each do |part|
1893
+ xml.Part do
1894
+ xml.PartNumber(part[:part_number])
1895
+ xml.ETag(part[:etag])
1896
+ end
1897
+ end
1898
+ end
1899
+ end.doc.root.to_xml
1900
+
1901
+ end
1902
+
1903
+ process_response do |resp|
1904
+ extract_object_headers(resp)
1905
+ end
1906
+
1907
+ simulate_response do |response|
1908
+ response.data = {}
1909
+ end
1910
+
1911
+ end
1912
+
1913
+ # @overload abort_multipart_upload(options = {})
1914
+ # @param [Hash] options
1915
+ # @option options [required,String] :bucket_name
1916
+ # @option options [required,String] :key
1917
+ # @option options [required,String] :upload_id
1918
+ # @return [Core::Response]
1919
+ object_method(:abort_multipart_upload, :delete) do
1920
+ configure_request do |req, options|
1921
+ require_upload_id!(options[:upload_id])
1922
+ super(req, options)
1923
+ req.add_param('uploadId', options[:upload_id])
1924
+ end
1925
+ end
1926
+
1927
+ # @overload list_parts(options = {})
1928
+ # @param [Hash] options
1929
+ # @option options [required,String] :bucket_name
1930
+ # @option options [required,String] :key
1931
+ # @option options [required,String] :upload_id
1932
+ # @option options [Integer] :max_parts
1933
+ # @option options [Integer] :part_number_marker
1934
+ # @return [Core::Response]
1935
+ object_method(:list_parts, :get, XML::ListParts) do
1936
+
1937
+ configure_request do |req, options|
1938
+ require_upload_id!(options[:upload_id])
1939
+ super(req, options)
1940
+ req.add_param('uploadId', options[:upload_id])
1941
+ req.add_param('max-parts', options[:max_parts])
1942
+ req.add_param('part-number-marker', options[:part_number_marker])
1943
+ end
1944
+
1945
+ end
1946
+
1947
+ # Copies an object from one key to another.
1948
+ # @overload copy_object(options = {})
1949
+ # @param [Hash] options
1950
+ # @option options [required, String] :bucket_name Name of the bucket
1951
+ # to copy a object into.
1952
+ # @option options [required, String] :key Where (object key) in the
1953
+ # bucket the object should be copied to.
1954
+ # @option options [String] :website_redirect_location If the bucket is
1955
+ # configured as a website, redirects requests for this object to
1956
+ # another object in the same bucket or to an external URL.
1957
+ # @option options [required, String] :copy_source The source
1958
+ # bucket name and key, joined by a forward slash ('/').
1959
+ # This string must be URL-encoded. Additionally, you must
1960
+ # have read access to the source object.
1961
+ # @option options [String] :acl A canned ACL (e.g. 'private',
1962
+ # 'public-read', etc). See the S3 API documentation for
1963
+ # a complete list of valid values.
1964
+ # @option options [Symbol,String] :server_side_encryption (nil) The
1965
+ # algorithm used to encrypt the object on the server side
1966
+ # (e.g. :aes256).
1967
+ # @option options [String] :storage_class+ ('STANDARD')
1968
+ # Controls whether Reduced Redundancy Storage is enabled for
1969
+ # the object. Valid values are 'STANDARD' and
1970
+ # 'REDUCED_REDUNDANCY'.
1971
+ # @option options [String] :metadata_directive ('COPY') Specify 'COPY' or
1972
+ # 'REPLACE'.
1973
+ # @option options [String] :content_type
1974
+ # @option options [String] :content_encoding
1975
+ # @option options [String] :content_disposition
1976
+ # @option options [String] :cache_control
1977
+ # @option options [String] :expires The date and time at which the
1978
+ # object is no longer cacheable.
1979
+ # @option options [String] :grant_read
1980
+ # @option options [String] :grant_write
1981
+ # @option options [String] :grant_read_acp
1982
+ # @option options [String] :grant_write_acp
1983
+ # @option options [String] :grant_full_control
1984
+ # @option options [String] :sse_customer_algorithm Specifies the
1985
+ # algorithm to use to when encrypting the object (e.g., AES256).
1986
+ # @option options [String] :sse_customer_key Specifies the
1987
+ # customer-provided encryption key for Amazon S3 to use in encrypting
1988
+ # data. This value is used to store the object and then it is
1989
+ # discarded; Amazon does not store the encryption key. The key must be
1990
+ # appropriate for use with the algorithm specified in the
1991
+ # `:sse_customer_algorithm` header.
1992
+ # @option options [String] :sse_customer_key_md5 Specifies the 128-bit
1993
+ # MD5 digest of the encryption key according to RFC 1321. Amazon S3
1994
+ # uses this header for a message integrity check to ensure the
1995
+ # encryption key was transmitted without error.
1996
+ # @option options [String] :copy_source_sse_customer_algorithm Specifies
1997
+ # the algorithm to use when decrypting the source object (e.g.,
1998
+ # AES256).
1999
+ # @option options [String] :copy_source_sse_customer_key Specifies the
2000
+ # customer-provided encryption key for Amazon S3 to use to decrypt the
2001
+ # source object. The encryption key provided in this header must be
2002
+ # one that was used when the source object was created.
2003
+ # @option options [String] :copy_source_sse_customer_key_md5 Specifies
2004
+ # the 128-bit MD5 digest of the encryption key according to RFC 1321.
2005
+ # Amazon S3 uses this header for a message integrity check to ensure
2006
+ # the encryption key was transmitted without error.
2007
+ # @return [Core::Response]
2008
+ object_method(:copy_object, :put, :header_options => {
2009
+ :website_redirect_location => 'x-amz-website-redirect-location',
2010
+ :acl => 'x-amz-acl',
2011
+ :grant_read => 'x-amz-grant-read',
2012
+ :grant_write => 'x-amz-grant-write',
2013
+ :grant_read_acp => 'x-amz-grant-read-acp',
2014
+ :grant_write_acp => 'x-amz-grant-write-acp',
2015
+ :grant_full_control => 'x-amz-grant-full-control',
2016
+ :copy_source => 'x-amz-copy-source',
2017
+ :cache_control => 'Cache-Control',
2018
+ :metadata_directive => 'x-amz-metadata-directive',
2019
+ :content_type => 'Content-Type',
2020
+ :content_encoding => 'Content-Encoding',
2021
+ :content_disposition => 'Content-Disposition',
2022
+ :expires => 'Expires',
2023
+ :sse_customer_algorithm => 'x-amz-server-side-encryption-customer-algorithm',
2024
+ :sse_customer_key => 'x-amz-server-side-encryption-customer-key',
2025
+ :sse_customer_key_md5 => 'x-amz-server-side-encryption-customer-key-MD5',
2026
+ :copy_source_sse_customer_algorithm => 'x-amz-copy-source-server-side-encryption-customer-algorithm',
2027
+ :copy_source_sse_customer_key => 'x-amz-copy-source-server-side-encryption-customer-key',
2028
+ :copy_source_sse_customer_key_md5 => 'x-amz-copy-source-server-side-encryption-customer-key-MD5',
2029
+ }) do
2030
+
2031
+ configure_request do |req, options|
2032
+
2033
+ validate!(:copy_source, options[:copy_source]) do
2034
+ "may not be blank" if options[:copy_source].to_s.empty?
2035
+ end
2036
+
2037
+ options = options.merge(:copy_source => escape_path(options[:copy_source]))
2038
+ super(req, options)
2039
+ set_metadata(req, options)
2040
+ set_storage_class(req, options)
2041
+ set_server_side_encryption(req, options)
2042
+
2043
+ if options[:version_id]
2044
+ req.headers['x-amz-copy-source'] += "?versionId=#{options[:version_id]}"
2045
+ end
2046
+ end
2047
+
2048
+ process_response do |resp|
2049
+ extract_object_headers(resp)
2050
+ end
2051
+
2052
+ end
2053
+
2054
+ object_method(:copy_part, :put, XML::CopyPart, :header_options => {
2055
+ :copy_source => 'x-amz-copy-source',
2056
+ :copy_source_range => 'x-amz-copy-source-range',
2057
+ }) do
2058
+
2059
+ configure_request do |request, options|
2060
+
2061
+ validate!(:copy_source, options[:copy_source]) do
2062
+ "may not be blank" if options[:copy_source].to_s.empty?
2063
+ end
2064
+
2065
+ validate!(:copy_source_range, options[:copy_source_range]) do
2066
+ "must start with bytes=" if options[:copy_source_range] && !options[:copy_source_range].start_with?("bytes=")
2067
+ end
2068
+
2069
+ options = options.merge(:copy_source => escape_path(options[:copy_source]))
2070
+
2071
+ require_upload_id!(options[:upload_id])
2072
+ request.add_param('uploadId', options[:upload_id])
2073
+
2074
+ require_part_number!(options[:part_number])
2075
+ request.add_param('partNumber', options[:part_number])
2076
+
2077
+ super(request, options)
2078
+
2079
+ if options[:version_id]
2080
+ req.headers['x-amz-copy-source'] += "?versionId=#{options[:version_id]}"
2081
+ end
2082
+
2083
+ end
2084
+
2085
+ end
2086
+
2087
+ end
2088
+ end
2089
+ end