aws-sdk-v1 1.52.0

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