azure-fix 0.7.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) hide show
  1. checksums.yaml +7 -0
  2. data/.env_sample +13 -0
  3. data/.gitignore +30 -0
  4. data/.travis.yml +13 -0
  5. data/ChangeLog.txt +56 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +702 -0
  9. data/Rakefile +121 -0
  10. data/azure.gemspec +51 -0
  11. data/bin/pfxer +35 -0
  12. data/lib/azure.rb +147 -0
  13. data/lib/azure/base_management/affinity_group.rb +32 -0
  14. data/lib/azure/base_management/base_management_service.rb +220 -0
  15. data/lib/azure/base_management/location.rb +27 -0
  16. data/lib/azure/base_management/management_http_request.rb +172 -0
  17. data/lib/azure/base_management/serialization.rb +135 -0
  18. data/lib/azure/base_management/sql_management_http_request.rb +35 -0
  19. data/lib/azure/blob/auth/shared_access_signature.rb +147 -0
  20. data/lib/azure/blob/blob.rb +32 -0
  21. data/lib/azure/blob/blob_service.rb +1452 -0
  22. data/lib/azure/blob/block.rb +31 -0
  23. data/lib/azure/blob/container.rb +32 -0
  24. data/lib/azure/blob/serialization.rb +285 -0
  25. data/lib/azure/client.rb +31 -0
  26. data/lib/azure/client_services.rb +98 -0
  27. data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
  28. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +135 -0
  29. data/lib/azure/cloud_service_management/serialization.rb +118 -0
  30. data/lib/azure/configurable.rb +290 -0
  31. data/lib/azure/core/auth/authorizer.rb +36 -0
  32. data/lib/azure/core/auth/shared_key.rb +118 -0
  33. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  34. data/lib/azure/core/auth/signer.rb +51 -0
  35. data/lib/azure/core/error.rb +21 -0
  36. data/lib/azure/core/filtered_service.rb +45 -0
  37. data/lib/azure/core/http/debug_filter.rb +36 -0
  38. data/lib/azure/core/http/http_error.rb +86 -0
  39. data/lib/azure/core/http/http_filter.rb +53 -0
  40. data/lib/azure/core/http/http_request.rb +173 -0
  41. data/lib/azure/core/http/http_response.rb +96 -0
  42. data/lib/azure/core/http/retry_policy.rb +74 -0
  43. data/lib/azure/core/http/signer_filter.rb +33 -0
  44. data/lib/azure/core/service.rb +46 -0
  45. data/lib/azure/core/signed_service.rb +45 -0
  46. data/lib/azure/core/utility.rb +244 -0
  47. data/lib/azure/default.rb +126 -0
  48. data/lib/azure/http_client.rb +85 -0
  49. data/lib/azure/queue/message.rb +30 -0
  50. data/lib/azure/queue/queue.rb +28 -0
  51. data/lib/azure/queue/queue_service.rb +570 -0
  52. data/lib/azure/queue/serialization.rb +105 -0
  53. data/lib/azure/service/access_policy.rb +26 -0
  54. data/lib/azure/service/cors.rb +11 -0
  55. data/lib/azure/service/cors_rule.rb +15 -0
  56. data/lib/azure/service/enumeration_results.rb +21 -0
  57. data/lib/azure/service/logging.rb +32 -0
  58. data/lib/azure/service/metrics.rb +31 -0
  59. data/lib/azure/service/retention_policy.rb +25 -0
  60. data/lib/azure/service/serialization.rb +299 -0
  61. data/lib/azure/service/signed_identifier.rb +30 -0
  62. data/lib/azure/service/storage_service.rb +86 -0
  63. data/lib/azure/service/storage_service_properties.rb +37 -0
  64. data/lib/azure/service_bus/action.rb +21 -0
  65. data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
  66. data/lib/azure/service_bus/auth/wrap_service.rb +90 -0
  67. data/lib/azure/service_bus/auth/wrap_signer.rb +77 -0
  68. data/lib/azure/service_bus/brokered_message.rb +124 -0
  69. data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
  70. data/lib/azure/service_bus/correlation_filter.rb +45 -0
  71. data/lib/azure/service_bus/empty_rule_action.rb +30 -0
  72. data/lib/azure/service_bus/false_filter.rb +38 -0
  73. data/lib/azure/service_bus/filter.rb +21 -0
  74. data/lib/azure/service_bus/interval.rb +104 -0
  75. data/lib/azure/service_bus/queue.rb +230 -0
  76. data/lib/azure/service_bus/relay.rb +88 -0
  77. data/lib/azure/service_bus/resource.rb +109 -0
  78. data/lib/azure/service_bus/rule.rb +98 -0
  79. data/lib/azure/service_bus/rule_aspect.rb +34 -0
  80. data/lib/azure/service_bus/serialization.rb +161 -0
  81. data/lib/azure/service_bus/service_bus_service.rb +899 -0
  82. data/lib/azure/service_bus/sql_filter.rb +50 -0
  83. data/lib/azure/service_bus/sql_rule_action.rb +50 -0
  84. data/lib/azure/service_bus/subscription.rb +184 -0
  85. data/lib/azure/service_bus/topic.rb +187 -0
  86. data/lib/azure/service_bus/true_filter.rb +38 -0
  87. data/lib/azure/sql_database_management/errors.rb +11 -0
  88. data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
  89. data/lib/azure/sql_database_management/serialization.rb +99 -0
  90. data/lib/azure/sql_database_management/sql_database_management_service.rb +211 -0
  91. data/lib/azure/sql_database_management/sql_server.rb +32 -0
  92. data/lib/azure/storage_management/serialization.rb +204 -0
  93. data/lib/azure/storage_management/storage_account.rb +48 -0
  94. data/lib/azure/storage_management/storage_management_service.rb +207 -0
  95. data/lib/azure/table/auth/shared_key.rb +59 -0
  96. data/lib/azure/table/auth/shared_key_lite.rb +44 -0
  97. data/lib/azure/table/batch.rb +330 -0
  98. data/lib/azure/table/batch_response.rb +118 -0
  99. data/lib/azure/table/edmtype.rb +127 -0
  100. data/lib/azure/table/entity.rb +31 -0
  101. data/lib/azure/table/guid.rb +24 -0
  102. data/lib/azure/table/query.rb +112 -0
  103. data/lib/azure/table/serialization.rb +108 -0
  104. data/lib/azure/table/table_service.rb +563 -0
  105. data/lib/azure/version.rb +31 -0
  106. data/lib/azure/virtual_machine_image_management/serialization.rb +70 -0
  107. data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
  108. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
  109. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +83 -0
  110. data/lib/azure/virtual_machine_management/serialization.rb +459 -0
  111. data/lib/azure/virtual_machine_management/virtual_machine.rb +44 -0
  112. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +552 -0
  113. data/lib/azure/virtual_network_management/serialization.rb +193 -0
  114. data/lib/azure/virtual_network_management/virtual_network.rb +37 -0
  115. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +108 -0
  116. data/test/fixtures/32px-fulls-black.jpg +0 -0
  117. data/test/fixtures/affinity_group.xml +33 -0
  118. data/test/fixtures/all_containers.xml +20 -0
  119. data/test/fixtures/all_tables.xml +22 -0
  120. data/test/fixtures/container_acl.xml +11 -0
  121. data/test/fixtures/create_sql_database_server.xml +2 -0
  122. data/test/fixtures/create_storage_desc_error.xml +5 -0
  123. data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
  124. data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
  125. data/test/fixtures/create_storage_full_error.xml +6 -0
  126. data/test/fixtures/create_storage_label_error.xml +5 -0
  127. data/test/fixtures/create_storage_location_error.xml +5 -0
  128. data/test/fixtures/create_storage_name_error.xml +6 -0
  129. data/test/fixtures/create_table_response_entry.xml +15 -0
  130. data/test/fixtures/delete_storage_container_error.xml +5 -0
  131. data/test/fixtures/delete_storage_error.xml +5 -0
  132. data/test/fixtures/deployment_error.xml +5 -0
  133. data/test/fixtures/empty_xml_file +0 -0
  134. data/test/fixtures/get_storage_account_error.xml +5 -0
  135. data/test/fixtures/get_storage_account_properties.xml +34 -0
  136. data/test/fixtures/get_storage_account_properties_new.xml +32 -0
  137. data/test/fixtures/http_error.xml +5 -0
  138. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  139. data/test/fixtures/list_affinity_groups.xml +22 -0
  140. data/test/fixtures/list_blobs.xml +121 -0
  141. data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
  142. data/test/fixtures/list_blocks_all.xml +23 -0
  143. data/test/fixtures/list_blocks_committed.xml +13 -0
  144. data/test/fixtures/list_cloud_services.xml +39 -0
  145. data/test/fixtures/list_containers.xml +38 -0
  146. data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
  147. data/test/fixtures/list_locations.xml +212 -0
  148. data/test/fixtures/list_os_images.xml +110 -0
  149. data/test/fixtures/list_page_ranges.xml +11 -0
  150. data/test/fixtures/list_sql_database.xml +24 -0
  151. data/test/fixtures/list_sql_server_firewall.xml +23 -0
  152. data/test/fixtures/list_storage_account_single.xml +25 -0
  153. data/test/fixtures/list_storage_accounts.xml +48 -0
  154. data/test/fixtures/list_virtual_networks.xml +92 -0
  155. data/test/fixtures/list_vm_images.xml +21 -0
  156. data/test/fixtures/logging.xml +11 -0
  157. data/test/fixtures/management_certificate.pfx +0 -0
  158. data/test/fixtures/messages.xml +12 -0
  159. data/test/fixtures/metrics.xml +10 -0
  160. data/test/fixtures/privatekey.key +28 -0
  161. data/test/fixtures/query_entities_empty_response.xml +7 -0
  162. data/test/fixtures/query_entities_response.xml +45 -0
  163. data/test/fixtures/queue_service_properties.xml +22 -0
  164. data/test/fixtures/queue_service_properties_original.xml +19 -0
  165. data/test/fixtures/queues.xml +16 -0
  166. data/test/fixtures/retention_policy.xml +5 -0
  167. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  168. data/test/fixtures/sb_default_create_relay_response.xml +15 -0
  169. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  170. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  171. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  172. data/test/fixtures/storage_service_keys.xml +8 -0
  173. data/test/fixtures/storage_service_properties.xml +55 -0
  174. data/test/fixtures/update_storage_account.xml +16 -0
  175. data/test/fixtures/update_storage_error.xml +5 -0
  176. data/test/fixtures/updated_storage_accounts.xml +55 -0
  177. data/test/fixtures/virtual_machine.xml +116 -0
  178. data/test/fixtures/windows_virtual_machine.xml +106 -0
  179. data/test/integration/affinity_group/Affinity_test.rb +55 -0
  180. data/test/integration/affinity_group/Create_Affinity_test.rb +64 -0
  181. data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
  182. data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
  183. data/test/integration/affinity_group/Update_Affinity_test.rb +87 -0
  184. data/test/integration/blob/blob_gb18030_test.rb +199 -0
  185. data/test/integration/blob/blob_metadata_test.rb +75 -0
  186. data/test/integration/blob/blob_pages_test.rb +119 -0
  187. data/test/integration/blob/blob_properties_test.rb +77 -0
  188. data/test/integration/blob/block_blob_test.rb +254 -0
  189. data/test/integration/blob/container/container_acl_test.rb +69 -0
  190. data/test/integration/blob/container/container_metadata_test.rb +50 -0
  191. data/test/integration/blob/container/create_container_test.rb +60 -0
  192. data/test/integration/blob/container/delete_container_test.rb +39 -0
  193. data/test/integration/blob/container/get_container_properties_test.rb +48 -0
  194. data/test/integration/blob/container/list_containers_test.rb +79 -0
  195. data/test/integration/blob/container/root_container_test.rb +55 -0
  196. data/test/integration/blob/copy_blob_test.rb +113 -0
  197. data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
  198. data/test/integration/blob/create_page_blob_test.rb +83 -0
  199. data/test/integration/blob/delete_blob_test.rb +159 -0
  200. data/test/integration/blob/get_blob_test.rb +65 -0
  201. data/test/integration/blob/informative_errors_test.rb +39 -0
  202. data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
  203. data/test/integration/blob/lease/break_lease_test.rb +40 -0
  204. data/test/integration/blob/lease/release_lease_test.rb +40 -0
  205. data/test/integration/blob/lease/renew_lease_test.rb +42 -0
  206. data/test/integration/blob/list_blobs_test.rb +113 -0
  207. data/test/integration/cloud_service/Cloud_Create_test.rb +45 -0
  208. data/test/integration/cloud_service/Cloud_Delete_test.rb +45 -0
  209. data/test/integration/database/create_sql_server_firewall_test.rb +81 -0
  210. data/test/integration/database/create_sql_server_test.rb +53 -0
  211. data/test/integration/database/delete_sql_server_firewall_test.rb +64 -0
  212. data/test/integration/database/delete_sql_server_test.rb +45 -0
  213. data/test/integration/database/list_sql_server_firewall_test.rb +44 -0
  214. data/test/integration/database/list_sql_servers_test.rb +44 -0
  215. data/test/integration/database/reset_password_sql_server_test.rb +53 -0
  216. data/test/integration/location/Location_List_test.rb +39 -0
  217. data/test/integration/location/RoleSize_List_test.rb +35 -0
  218. data/test/integration/queue/clear_messages_test.rb +42 -0
  219. data/test/integration/queue/create_message_test.rb +75 -0
  220. data/test/integration/queue/create_queue_test.rb +50 -0
  221. data/test/integration/queue/delete_message_test.rb +67 -0
  222. data/test/integration/queue/delete_queue_test.rb +45 -0
  223. data/test/integration/queue/informative_errors_test.rb +42 -0
  224. data/test/integration/queue/list_messages_encoded_test.rb +79 -0
  225. data/test/integration/queue/list_messages_test.rb +79 -0
  226. data/test/integration/queue/list_queues_test.rb +43 -0
  227. data/test/integration/queue/peek_messages_test.rb +59 -0
  228. data/test/integration/queue/queue_gb18030_test.rb +131 -0
  229. data/test/integration/queue/queue_metadata_test.rb +40 -0
  230. data/test/integration/queue/update_message_test.rb +74 -0
  231. data/test/integration/service_bus/informative_errors_test.rb +37 -0
  232. data/test/integration/service_bus/queues_scenario_test.rb +200 -0
  233. data/test/integration/service_bus/queues_test.rb +266 -0
  234. data/test/integration/service_bus/relay_test.rb +132 -0
  235. data/test/integration/service_bus/rules_test.rb +145 -0
  236. data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
  237. data/test/integration/service_bus/scenario_test.rb +101 -0
  238. data/test/integration/service_bus/subscriptions_test.rb +211 -0
  239. data/test/integration/service_bus/topics_scenario_test.rb +406 -0
  240. data/test/integration/service_bus/topics_test.rb +129 -0
  241. data/test/integration/storage_management/storage_management_test.rb +185 -0
  242. data/test/integration/table/create_table_test.rb +36 -0
  243. data/test/integration/table/delete_entity_batch_test.rb +107 -0
  244. data/test/integration/table/delete_entity_test.rb +94 -0
  245. data/test/integration/table/delete_table_test.rb +40 -0
  246. data/test/integration/table/get_table_test.rb +37 -0
  247. data/test/integration/table/informative_errors_test.rb +39 -0
  248. data/test/integration/table/insert_entity_batch_test.rb +100 -0
  249. data/test/integration/table/insert_entity_test.rb +88 -0
  250. data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
  251. data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
  252. data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
  253. data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
  254. data/test/integration/table/merge_entity_batch_test.rb +128 -0
  255. data/test/integration/table/merge_entity_test.rb +113 -0
  256. data/test/integration/table/query_entities_test.rb +196 -0
  257. data/test/integration/table/query_tables_test.rb +43 -0
  258. data/test/integration/table/query_test.rb +251 -0
  259. data/test/integration/table/table_acl_test.rb +52 -0
  260. data/test/integration/table/table_gb18030_test.rb +355 -0
  261. data/test/integration/table/update_entity_batch_test.rb +149 -0
  262. data/test/integration/table/update_entity_test.rb +131 -0
  263. data/test/integration/test_helper.rb +40 -0
  264. data/test/integration/vm/VM_Create_test.rb +262 -0
  265. data/test/integration/vm/VM_Delete_test.rb +53 -0
  266. data/test/integration/vm/VM_Operations_test.rb +172 -0
  267. data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
  268. data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
  269. data/test/integration/vnet/Virtual_Network_Create_test.rb +116 -0
  270. data/test/integration/vnet/Virtual_Network_list_test.rb +48 -0
  271. data/test/support/env.rb +19 -0
  272. data/test/support/fixtures.rb +36 -0
  273. data/test/support/name_generator.rb +168 -0
  274. data/test/support/stubs.rb +42 -0
  275. data/test/support/virtual_machine_name_generator.rb +102 -0
  276. data/test/support/virtual_network_helper.rb +73 -0
  277. data/test/test_helper.rb +47 -0
  278. data/test/unit/affinity_group/affinity_group_test.rb +189 -0
  279. data/test/unit/affinity_group/serialization_test.rb +87 -0
  280. data/test/unit/base_management/base_management_service_test.rb +19 -0
  281. data/test/unit/base_management/location_test.rb +56 -0
  282. data/test/unit/base_management/role_size_test.rb +50 -0
  283. data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
  284. data/test/unit/blob/blob_service_test.rb +1970 -0
  285. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +94 -0
  286. data/test/unit/cloud_service_management/serialization_test.rb +169 -0
  287. data/test/unit/config/azure_test.rb +112 -0
  288. data/test/unit/config/client_test.rb +37 -0
  289. data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
  290. data/test/unit/core/auth/shared_key_test.rb +58 -0
  291. data/test/unit/core/auth/signer_test.rb +30 -0
  292. data/test/unit/core/http/http_error_test.rb +61 -0
  293. data/test/unit/core/http/http_request_test.rb +138 -0
  294. data/test/unit/core/http/http_response_test.rb +20 -0
  295. data/test/unit/core/http/retry_policy_test.rb +23 -0
  296. data/test/unit/core/utility_test.rb +122 -0
  297. data/test/unit/database/serialization_test.rb +94 -0
  298. data/test/unit/database/sql_database_server_service_test.rb +341 -0
  299. data/test/unit/http_client_test.rb +74 -0
  300. data/test/unit/service/serialization_test.rb +533 -0
  301. data/test/unit/service/storage_service_test.rb +297 -0
  302. data/test/unit/storage_management/serialization_test.rb +244 -0
  303. data/test/unit/storage_management/storage_management_service_test.rb +247 -0
  304. data/test/unit/table/edmtype_test.rb +108 -0
  305. data/test/unit/virtual_machine_image_management/serialization_test.rb +50 -0
  306. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +114 -0
  307. data/test/unit/virtual_machine_management/serialization_test.rb +316 -0
  308. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +480 -0
  309. data/test/unit/vnet/serialization_test.rb +187 -0
  310. data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
  311. metadata +579 -0
@@ -0,0 +1,32 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+
16
+ module Azure
17
+ module Blob
18
+ class Blob
19
+
20
+ def initialize
21
+ @properties = {}
22
+ @metadata = {}
23
+ yield self if block_given?
24
+ end
25
+
26
+ attr_accessor :name
27
+ attr_accessor :snapshot
28
+ attr_accessor :properties
29
+ attr_accessor :metadata
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,1452 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'azure/service/storage_service'
16
+ require 'azure/blob/serialization'
17
+ require 'azure/blob/auth/shared_access_signature'
18
+ require 'base64'
19
+
20
+ module Azure
21
+ module Blob
22
+ class BlobService < Service::StorageService
23
+
24
+ def initialize(options = {})
25
+ client_config = options[:client] || Azure
26
+ signer = options[:signer] || Azure::Core::Auth::SharedKey.new(client_config.storage_account_name,
27
+ client_config.storage_access_key)
28
+ super(signer, client_config.storage_account_name, options)
29
+ @host = client.storage_blob_host
30
+ end
31
+
32
+ # Public: Get a list of Containers from the server
33
+ #
34
+ # ==== Attributes
35
+ #
36
+ # * +options+ - Hash. Optional parameters.
37
+ #
38
+ # ==== Options
39
+ #
40
+ # Accepted key/value pairs in options parameter are:
41
+ # * +:prefix+ - String. Filters the results to return only containers
42
+ # whose name begins with the specified prefix. (optional)
43
+ #
44
+ # * +:marker+ - String. An identifier the specifies the portion of the
45
+ # list to be returned. This value comes from the property
46
+ # Azure::Service::EnumerationResults.continuation_token when there
47
+ # are more containers available than were returned. The
48
+ # marker value may then be used here to request the next set
49
+ # of list items. (optional)
50
+ #
51
+ # * +:max_results+ - Integer. Specifies the maximum number of containers to return.
52
+ # If max_results is not specified, or is a value greater than
53
+ # 5,000, the server will return up to 5,000 items. If it is set
54
+ # to a value less than or equal to zero, the server will return
55
+ # status code 400 (Bad Request). (optional)
56
+ #
57
+ # * +:metadata+ - Boolean. Specifies whether or not to return the container metadata.
58
+ # (optional, Default=false)
59
+ #
60
+ # * +:timeout+ - Integer. A timeout in seconds.
61
+ #
62
+ # NOTE: Metadata requested with the :metadata parameter must have been stored in
63
+ # accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
64
+ # service. Beginning with that version, all metadata names must adhere to the naming
65
+ # conventions for C# identifiers.
66
+ #
67
+ # See: http://msdn.microsoft.com/en-us/library/aa664670(VS.71).aspx
68
+ #
69
+ # Any metadata with invalid names which were previously stored, will be returned with the
70
+ # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
71
+ # Array (vs a String if it only contains a single value).
72
+ #
73
+ # Returns an Azure::Service::EnumerationResults
74
+ def list_containers(options={})
75
+ query = { }
76
+ if options
77
+ query['prefix'] = options[:prefix] if options[:prefix]
78
+ query['marker'] = options[:marker] if options[:marker]
79
+ query['maxresults'] = options[:max_results].to_s if options[:max_results]
80
+ query['include'] = 'metadata' if options[:metadata] == true
81
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
82
+ end
83
+
84
+ uri = containers_uri(query)
85
+ response = call(:get, uri)
86
+
87
+ Serialization.container_enumeration_results_from_xml(response.body)
88
+ end
89
+
90
+ # Public: Create a new container
91
+ #
92
+ # ==== Attributes
93
+ #
94
+ # * +name+ - String. The name of the container
95
+ # * +options+ - Hash. Optional parameters.
96
+ #
97
+ # ==== Options
98
+ #
99
+ # Accepted key/value pairs in options parameter are:
100
+ # * +:metadata+ - Hash. User defined metadata for the container (optional)
101
+ # * +:public_access_level+ - String. One of "container" or "blob" (optional)
102
+ # * +:timeout+ - Integer. A timeout in seconds.
103
+ #
104
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179468.aspx
105
+ #
106
+ # Returns a Container
107
+ def create_container(name, options={})
108
+ query = { }
109
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
110
+
111
+ uri = container_uri(name, query)
112
+
113
+ headers = service_properties_headers
114
+
115
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
116
+
117
+ headers['x-ms-blob-public-access'] = options[:public_access_level].to_s if options[:public_access_level]
118
+
119
+ response = call(:put, uri, nil, headers)
120
+
121
+ container = Serialization.container_from_headers(response.headers)
122
+ container.name = name
123
+ container.metadata = options[:metadata]
124
+ container
125
+ end
126
+
127
+ # Public: Deletes a container
128
+ #
129
+ # ==== Attributes
130
+ #
131
+ # * +name+ - String. The name of the container
132
+ # * +options+ - Hash. Optional parameters.
133
+ #
134
+ # ==== Options
135
+ #
136
+ # Accepted key/value pairs in options parameter are:
137
+ # * +:timeout+ - Integer. A timeout in seconds.
138
+ #
139
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179408.aspx
140
+ #
141
+ # Returns nil on success
142
+ def delete_container(name, options={})
143
+ query = { }
144
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
145
+
146
+ call(:delete, container_uri(name, query))
147
+ nil
148
+ end
149
+
150
+ # Public: Returns all properties and metadata on the container.
151
+ #
152
+ # ==== Attributes
153
+ #
154
+ # * +name+ - String. The name of the container
155
+ # * +options+ - Hash. Optional parameters.
156
+ #
157
+ # ==== Options
158
+ #
159
+ # Accepted key/value pairs in options parameter are:
160
+ # * +:timeout+ - Integer. A timeout in seconds.
161
+ #
162
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179370.aspx
163
+ #
164
+ # Returns a Container
165
+ def get_container_properties(name, options={})
166
+ query = { }
167
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
168
+
169
+ response = call(:get, container_uri(name, query))
170
+
171
+ container = Serialization.container_from_headers(response.headers)
172
+ container.name = name
173
+ container
174
+ end
175
+
176
+ # Public: Returns only user-defined metadata for the specified container.
177
+ #
178
+ # ==== Attributes
179
+ #
180
+ # * +name+ - String. The name of the container
181
+ # * +options+ - Hash. Optional parameters.
182
+ #
183
+ # ==== Options
184
+ #
185
+ # Accepted key/value pairs in options parameter are:
186
+ # * +:timeout+ - Integer. A timeout in seconds.
187
+ #
188
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691976.aspx
189
+ #
190
+ # Returns a Container
191
+ def get_container_metadata(name, options={})
192
+ query = { 'comp' => 'metadata'}
193
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
194
+
195
+ response = call(:get, container_uri(name, query))
196
+
197
+ container = Serialization.container_from_headers(response.headers)
198
+ container.name = name
199
+ container
200
+ end
201
+
202
+ # Public: Gets the access control list (ACL) and any container-level access policies
203
+ # for the container.
204
+ #
205
+ # ==== Attributes
206
+ #
207
+ # * +name+ - String. The name of the container
208
+ # * +options+ - Hash. Optional parameters.
209
+ #
210
+ # ==== Options
211
+ #
212
+ # Accepted key/value pairs in options parameter are:
213
+ # * +:timeout+ - Integer. A timeout in seconds.
214
+ #
215
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179469.aspx
216
+ #
217
+ # Returns a tuple of (container, signed_identifiers)
218
+ # container - A Azure::Entity::Blob::Container instance
219
+ # signed_identifiers - A list of Azure::Entity::SignedIdentifier instances
220
+ #
221
+ def get_container_acl(name, options={})
222
+ query = { 'comp' => 'acl'}
223
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
224
+ response = call(:get, container_uri(name, query))
225
+
226
+ container = Serialization.container_from_headers(response.headers)
227
+ container.name = name
228
+
229
+ signed_identifiers = nil
230
+ signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) if response.body != nil && response.body.length > 0
231
+
232
+ return container, signed_identifiers
233
+ end
234
+
235
+ # Public: Sets the ACL and any container-level access policies for the container.
236
+ #
237
+ # ==== Attributes
238
+ #
239
+ # * +name+ - String. The name of the container
240
+ # * +public_access_level+ - String. The container public access level
241
+ # * +options+ - Hash. Optional parameters.
242
+ #
243
+ # ==== Options
244
+ #
245
+ # Accepted key/value pairs in options parameter are:
246
+ # * +:signed_identifiers+ - Array. A list of Azure::Entity::SignedIdentifier instances (optional)
247
+ # * +:timeout+ - Integer. A timeout in seconds.
248
+ #
249
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179391.aspx
250
+ #
251
+ # Returns a tuple of (container, signed_identifiers)
252
+ # * +container+ - A Azure::Entity::Blob::Container instance
253
+ # * +signed_identifiers+ - A list of Azure::Entity::SignedIdentifier instances
254
+ #
255
+ def set_container_acl(name, public_access_level, options={})
256
+ query = { 'comp' => 'acl'}
257
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
258
+ uri =container_uri(name, query)
259
+
260
+ headers = service_properties_headers
261
+ headers['x-ms-blob-public-access'] = public_access_level if public_access_level && public_access_level.to_s.length > 0
262
+
263
+ signed_identifiers = nil
264
+ signed_identifiers = options[:signed_identifiers] if options[:signed_identifiers]
265
+
266
+ body = nil
267
+ body = Serialization.signed_identifiers_to_xml(signed_identifiers) if signed_identifiers
268
+
269
+ response = call(:put, uri, body, headers)
270
+
271
+ container = Serialization.container_from_headers(response.headers)
272
+ container.name = name
273
+ container.public_access_level = public_access_level
274
+
275
+ return container, signed_identifiers || []
276
+
277
+ end
278
+
279
+ # Public: Sets custom metadata for the container.
280
+ #
281
+ # ==== Attributes
282
+ #
283
+ # * +name+ - String. The name of the container
284
+ # * +metadata+ - Hash. A Hash of the metadata values
285
+ # * +options+ - Hash. Optional parameters.
286
+ #
287
+ # ==== Options
288
+ #
289
+ # Accepted key/value pairs in options parameter are:
290
+ # * +:timeout+ - Integer. A timeout in seconds.
291
+ #
292
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179362.aspx
293
+ #
294
+ # Returns nil on success
295
+ def set_container_metadata(name, metadata, options={})
296
+ query = { 'comp' => 'metadata'}
297
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
298
+
299
+ headers = service_properties_headers
300
+ add_metadata_to_headers(metadata, headers) if metadata
301
+
302
+ call(:put, container_uri(name, query), nil, headers)
303
+ nil
304
+ end
305
+
306
+ # Public: Get a list of Blobs from the server
307
+ #
308
+ # ==== Attributes
309
+ #
310
+ # * +name+ - String. The name of the container to list blobs for.
311
+ # * +options+ - Hash. Optional parameters.
312
+ #
313
+ # ==== Options
314
+ #
315
+ # Accepted key/value pairs in options parameter are:
316
+ # * +:prefix+ - String. Filters the results to return only blobs
317
+ # whose name begins with the specified prefix. (optional)
318
+ # * +:delimiter+ - String. When the request includes this parameter, the operation
319
+ # returns a BlobPrefix element in the response body that acts as a
320
+ # placeholder for all blobs whose names begin with the same substring
321
+ # up to the appearance of the delimiter character. The delimiter may
322
+ # be a single character or a string.
323
+ # * +:marker+ - String. An identifier that specifies the portion of the
324
+ # list to be returned. This value comes from the property
325
+ # Azure::Service::EnumerationResults.continuation_token when
326
+ # there are more blobs available than were returned. The
327
+ # marker value may then be used here to request the next set
328
+ # of list items. (optional)
329
+ # * +:max_results+ - Integer. Specifies the maximum number of blobs to return.
330
+ # If max_results is not specified, or is a value greater than
331
+ # 5,000, the server will return up to 5,000 items. If it is set
332
+ # to a value less than or equal to zero, the server will return
333
+ # status code 400 (Bad Request). (optional)
334
+ # * +:metadata+ - Boolean. Specifies whether or not to return the blob metadata.
335
+ # (optional, Default=false)
336
+ # * +:snapshots+ - Boolean. Specifies that snapshots should be included in the
337
+ # enumeration. Snapshots are listed from oldest to newest in the
338
+ # response. (optional, Default=false)
339
+ # * +:uncomittedblobs+ - Boolean. Specifies that blobs for which blocks have been uploaded,
340
+ # but which have not been committed using put_block_list, be included
341
+ # in the response. (optional, Default=false)
342
+ # * +:copy+ - Boolean. Specifies that metadata related to any current or previous
343
+ # copy_blob operation should be included in the response.
344
+ # (optional, Default=false)
345
+ # * +:timeout+ - Integer. A timeout in seconds.
346
+ #
347
+ # NOTE: Metadata requested with the :metadata parameter must have been stored in
348
+ # accordance with the naming restrictions imposed by the 2009-09-19 version of the Blob
349
+ # service. Beginning with that version, all metadata names must adhere to the naming
350
+ # conventions for C# identifiers.
351
+ #
352
+ # See: http://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
353
+ #
354
+ # Any metadata with invalid names which were previously stored, will be returned with the
355
+ # key "x-ms-invalid-name" in the metadata hash. This may contain multiple values and be an
356
+ # Array (vs a String if it only contains a single value).
357
+ #
358
+ # Returns an Azure::Service::EnumerationResults
359
+ def list_blobs(name, options={})
360
+ query = { 'comp' => 'list'}
361
+ query['prefix'] = options[:prefix].gsub(/\\/, '/') if options[:prefix]
362
+ query['delimiter'] = options[:delimiter] if options[:delimiter]
363
+ query['marker'] = options[:marker] if options[:marker]
364
+ query['maxresults'] = options[:max_results].to_s if options[:max_results]
365
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
366
+
367
+ included_datasets = []
368
+ included_datasets.push('metadata') if options[:metadata] == true
369
+ included_datasets.push('snapshots') if options[:snapshots] == true
370
+ included_datasets.push('uncommittedblobs') if options[:uncommittedblobs] == true
371
+ included_datasets.push('copy') if options[:copy] == true
372
+
373
+ query['include'] = included_datasets.join ',' if included_datasets.length > 0
374
+
375
+ uri = container_uri(name, query)
376
+ response = call(:get, uri)
377
+
378
+ Serialization.blob_enumeration_results_from_xml(response.body)
379
+ end
380
+
381
+ # Public: Creates a new page blob. Note that calling create_page_blob to create a page
382
+ # blob only initializes the blob. To add content to a page blob, call create_blob_pages method.
383
+ #
384
+ # ==== Attributes
385
+ #
386
+ # * +container+ - String. The container name.
387
+ # * +blob+ - String. The blob name.
388
+ # * +length+ - Integer. Specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.
389
+ # * +options+ - Hash. Optional parameters.
390
+ #
391
+ # ==== Options
392
+ #
393
+ # Accepted key/value pairs in options parameter are:
394
+ # * +:content_type+ - String. Content type for the request. Will be saved with blob unless alternate value is provided in blob_content_type.
395
+ # * +:content_encoding+ - String. Content encoding for the request. Will be saved with blob unless alternate value is provided in blob_content_encoding.
396
+ # * +:content_language+ - String. Content language for the request. Will be saved with blob unless alternate value is provided in blob_content_language.
397
+ # * +:content_md5+ - String. Content MD5 for the request. Will be saved with blob unless alternate value is provided in blob_content_md5.
398
+ # * +:cache_control+ - String. Cache control for the request. Will be saved with blob unless alternate value is provided in blob_cache_control.
399
+ # * +:blob_content_type+ - String. Content type for the blob. Will be saved with blob.
400
+ # * +:blob_content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
401
+ # * +:blob_content_language+ - String. Content language for the blob. Will be saved with blob.
402
+ # * +:blob_content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
403
+ # * +:blob_cache_control+ - String. Cache control for the blob. Will be saved with blob.
404
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
405
+ # * +:sequence_number+ - Integer. The sequence number is a user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
406
+ # * +:timeout+ - Integer. A timeout in seconds.
407
+ #
408
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
409
+ #
410
+ # Returns a Blob
411
+ def create_page_blob(container, blob, length, options={})
412
+ query = { }
413
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
414
+
415
+ uri = blob_uri(container, blob, query)
416
+
417
+ headers = service_properties_headers
418
+
419
+ # set x-ms-blob-type to PageBlob
420
+ headers['x-ms-blob-type'] = 'PageBlob'
421
+
422
+ # ensure content-length is 0 and x-ms-blob-content-length is the blob length
423
+ headers['Content-Length'] = 0.to_s
424
+ headers['x-ms-blob-content-length'] = length.to_s
425
+
426
+ # set x-ms-sequence-number from options (or default to 0)
427
+ headers['x-ms-sequence-number'] = (options[:sequence_number] || 0).to_s
428
+
429
+ # set the rest of the optional headers
430
+ headers['Content-Type'] = options[:content_type] if options[:content_type]
431
+ headers['Content-Encoding'] = options[:content_encoding] if options[:content_encoding]
432
+ headers['Content-Language'] = options[:content_language] if options[:content_language]
433
+ headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
434
+ headers['Cache-Control'] = options[:cache_control] if options[:cache_control]
435
+
436
+ headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
437
+ headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
438
+ headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
439
+ headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
440
+ headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
441
+
442
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
443
+
444
+ # call PutBlob with empty body
445
+ response = call(:put, uri, nil, headers)
446
+
447
+ result = Serialization.blob_from_headers(response.headers)
448
+ result.name = blob
449
+
450
+ result
451
+ end
452
+
453
+ # Public: Creates a range of pages in a page blob.
454
+ #
455
+ # ==== Attributes
456
+ #
457
+ # * +container+ - String. Name of container
458
+ # * +blob+ - String. Name of blob
459
+ # * +start_range+ - Integer. Position of first byte of first page
460
+ # * +end_range+ - Integer. Position of last byte of of last page
461
+ # * +content+ - IO or String. Content to write. Length in bytes should equal end_range - start_range
462
+ # * +options+ - Hash. A collection of options.
463
+ #
464
+ # ==== Options
465
+ #
466
+ # Accepted key/value pairs in options parameter are:
467
+ # * +:if_sequence_number_le+ - If the blob's sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails with the SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
468
+ # * +:if_sequence_number_lt+ - If the blob's sequence number is less than the specified value, the request proceeds; otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
469
+ # * +:if_sequence_number_eq+ - If the blob's sequence number is equal to the specified value, the request proceeds; otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
470
+ # * +:if_modified_since+ - A DateTime value. Specify this conditional header to write the page only if the blob has been modified since the specified date/time. If the blob has not been modified, the Blob service returns status code 412 (Precondition Failed).
471
+ # * +:if_unmodified_since+ - A DateTime value. Specify this conditional header to write the page only if the blob has not been modified since the specified date/time. If the blob has been modified, the Blob service returns status code 412 (Precondition Failed).
472
+ # * +:if_match+ - An ETag value. Specify an ETag value for this conditional header to write the page only if the blob's ETag value matches the value specified. If the values do not match, the Blob service returns status code 412 (Precondition Failed).
473
+ # * +:if_none_match+ - An ETag value. Specify an ETag value for this conditional header to write the page only if the blob's ETag value does not match the value specified. If the values are identical, the Blob service returns status code 412 (Precondition Failed).
474
+ # * +:timeout+ - Integer. A timeout in seconds.
475
+ #
476
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
477
+ #
478
+ # Returns Blob
479
+ def create_blob_pages(container, blob, start_range, end_range, content, options={})
480
+ query = { 'comp' => 'page'}
481
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
482
+
483
+ uri = blob_uri(container, blob, query)
484
+ headers = service_properties_headers
485
+ headers['x-ms-range'] = "bytes=#{start_range}-#{end_range}"
486
+ headers['x-ms-page-write'] = 'update'
487
+
488
+ # clear default content type
489
+ headers['Content-Type'] = ''
490
+
491
+ # set optional headers
492
+ unless options.empty?
493
+ headers['x-ms-if-sequence-number-le'] = options[:if_sequence_number_le] if options[:if_sequence_number_le]
494
+ headers['x-ms-if-sequence-number-lt'] = options[:if_sequence_number_lt] if options[:if_sequence_number_lt]
495
+ headers['x-ms-if-sequence-number-eq'] = options[:if_sequence_number_eq] if options[:if_sequence_number_eq]
496
+ headers['If-Modified-Since'] = options[:if_modified_since] if options[:if_modified_since]
497
+ headers['If-Unmodified-Since'] = options[:if_unmodified_since] if options[:if_unmodified_since]
498
+ headers['If-Match'] = options[:if_match] if options[:if_match]
499
+ headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
500
+ end
501
+
502
+ response = call(:put, uri, content, headers)
503
+
504
+ result = Serialization.blob_from_headers(response.headers)
505
+ result.name = blob
506
+
507
+ result
508
+ end
509
+
510
+ # Public: Clears a range of pages from the blob.
511
+ #
512
+ # ==== Attributes
513
+ #
514
+ # * +container+ - String. Name of container.
515
+ # * +blob+ - String. Name of blob.
516
+ # * +start_range+ - Integer. Position of first byte of first page.
517
+ # * +end_range+ - Integer. Position of last byte of of last page.
518
+ # * +options+ - Hash. Optional parameters.
519
+ #
520
+ # ==== Options
521
+ #
522
+ # Accepted key/value pairs in options parameter are:
523
+ # * +:timeout+ - Integer. A timeout in seconds.
524
+ #
525
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
526
+ #
527
+ # Returns Blob
528
+ def clear_blob_pages(container, blob, start_range, end_range, options={})
529
+ query = { 'comp' => 'page'}
530
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
531
+
532
+ uri = blob_uri(container, blob, query)
533
+
534
+ headers = service_properties_headers
535
+ headers['x-ms-range'] = "bytes=#{start_range}-#{end_range}"
536
+ headers['x-ms-page-write'] = 'clear'
537
+
538
+ # clear default content type
539
+ headers['Content-Type'] = ''
540
+
541
+ response = call(:put, uri, nil, headers)
542
+
543
+ result = Serialization.blob_from_headers(response.headers)
544
+ result.name = blob
545
+
546
+ result
547
+ end
548
+
549
+ # Public: Creates a new block blob or updates the content of an existing block blob.
550
+ #
551
+ # Updating an existing block blob overwrites any existing metadata on the blob
552
+ # Partial updates are not supported with create_block_blob the content of the
553
+ # existing blob is overwritten with the content of the new blob. To perform a
554
+ # partial update of the content of a block blob, use the create_block_list
555
+ # method.
556
+ #
557
+ # Note that the default content type is application/octet-stream.
558
+ #
559
+ # ==== Attributes
560
+ #
561
+ # * +container+ - String. The container name.
562
+ # * +blob+ - String. The blob name.
563
+ # * +content+ - IO or String. The content of the blob.
564
+ # * +options+ - Hash. Optional parameters.
565
+ #
566
+ # ==== Options
567
+ #
568
+ # Accepted key/value pairs in options parameter are:
569
+ # * +:content_type+ - String. Content type for the request. Will be saved with blob unless alternate value is provided in blob_content_type.
570
+ # * +:content_encoding+ - String. Content encoding for the request. Will be saved with blob unless alternate value is provided in blob_content_encoding.
571
+ # * +:content_language+ - String. Content language for the request. Will be saved with blob unless alternate value is provided in blob_content_language.
572
+ # * +:content_md5+ - String. Content MD5 for the request. Will be saved with blob unless alternate value is provided in blob_content_md5.
573
+ # * +:cache_control+ - String. Cache control for the request. Will be saved with blob unless alternate value is provided in blob_cache_control.
574
+ # * +:blob_content_type+ - String. Content type for the blob. Will be saved with blob.
575
+ # * +:blob_content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
576
+ # * +:blob_content_language+ - String. Content language for the blob. Will be saved with blob.
577
+ # * +:blob_content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
578
+ # * +:blob_cache_control+ - String. Cache control for the blob. Will be saved with blob.
579
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
580
+ # * +:timeout+ - Integer. A timeout in seconds.
581
+ #
582
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
583
+ #
584
+ # Returns a Blob
585
+ def create_block_blob(container, blob, content, options={})
586
+ query = { }
587
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
588
+
589
+ uri = blob_uri(container, blob, query)
590
+
591
+ headers = service_properties_headers
592
+
593
+ # set x-ms-blob-type to BlockBlob
594
+ headers['x-ms-blob-type'] = 'BlockBlob'
595
+
596
+ # set the rest of the optional headers
597
+ headers['Content-Type'] = options[:content_type] || 'application/octet-stream'
598
+ headers['Content-Encoding'] = options[:content_encoding] if options[:content_encoding]
599
+ headers['Content-Language'] = options[:content_language] if options[:content_language]
600
+ headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
601
+ headers['Cache-Control'] = options[:cache_control] if options[:cache_control]
602
+
603
+ headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
604
+ headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
605
+ headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
606
+ headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
607
+ headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
608
+ headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
609
+
610
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
611
+
612
+ # call PutBlob with empty body
613
+ response = call(:put, uri, content, headers)
614
+
615
+ result = Serialization.blob_from_headers(response.headers)
616
+ result.name = blob
617
+
618
+ result
619
+ end
620
+
621
+ # Public: Creates a new block to be committed as part of a block blob.
622
+ #
623
+ # ==== Attributes
624
+ #
625
+ # * +container+ - String. The container name.
626
+ # * +blob+ - String. The blob name.
627
+ # * +block_id+ - String. The block id. Note: this should be the raw block id, not Base64 encoded.
628
+ # * +content+ - IO or String. The content of the blob.
629
+ # * +options+ - Hash. Optional parameters.
630
+ #
631
+ # ==== Options
632
+ #
633
+ # Accepted key/value pairs in options parameter are:
634
+ # * +:content_md5+ - String. Content MD5 for the request contents.
635
+ # * +:timeout+ - Integer. A timeout in seconds.
636
+ #
637
+ # See http://msdn.microsoft.com/en-us/library/azure/dd135726.aspx
638
+ #
639
+ # Returns the MD5 of the uploaded block (as calculated by the server)
640
+ def create_blob_block(container, blob, block_id, content, options={})
641
+ query = { 'comp' => 'block'}
642
+ query['blockid'] = Base64.strict_encode64(block_id)
643
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
644
+
645
+ uri = blob_uri(container, blob, query)
646
+
647
+ headers = service_properties_headers
648
+ headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
649
+
650
+ response = call(:put, uri, content, headers)
651
+
652
+ response.headers['Content-MD5']
653
+ end
654
+
655
+ # Public: Commits existing blob blocks to a blob.
656
+ #
657
+ # This method writes a blob by specifying the list of block IDs that make up the
658
+ # blob. In order to be written as part of a blob, a block must have been
659
+ # successfully written to the server in a prior create_blob_block method.
660
+ #
661
+ # You can call Put Block List to update a blob by uploading only those blocks
662
+ # that have changed, then committing the new and existing blocks together.
663
+ # You can do this by specifying whether to commit a block from the committed
664
+ # block list or from the uncommitted block list, or to commit the most recently
665
+ # uploaded version of the block, whichever list it may belong to.
666
+ #
667
+ # ==== Attributes
668
+ #
669
+ # * +container+ - String. The container name.
670
+ # * +blob+ - String. The blob name.
671
+ # * +block_list+ - Array. A ordered list of lists in the following format:
672
+ # [ ["block_id1", :committed], ["block_id2", :uncommitted], ["block_id3"], ["block_id4", :committed]... ]
673
+ # The first element of the inner list is the block_id, the second is optional
674
+ # and can be either :committed or :uncommitted to indicate in which group of blocks
675
+ # the id should be looked for. If it is omitted, the latest of either group will be used.
676
+ # * +options+ - Hash. Optional parameters.
677
+ #
678
+ # ==== Options
679
+ #
680
+ # Accepted key/value pairs in options parameter are:
681
+ # * +:content_md5+ - String. Content MD5 for the request contents (not the blob contents!)
682
+ # * +:blob_content_type+ - String. Content type for the blob. Will be saved with blob.
683
+ # * +:blob_content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
684
+ # * +:blob_content_language+ - String. Content language for the blob. Will be saved with blob.
685
+ # * +:blob_content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
686
+ # * +:blob_cache_control+ - String. Cache control for the blob. Will be saved with blob.
687
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob.
688
+ # * +:timeout+ - Integer. A timeout in seconds.
689
+ #
690
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179467.aspx
691
+ #
692
+ # Returns nil on success
693
+ def commit_blob_blocks(container, blob, block_list, options={})
694
+ query = { 'comp' => 'blocklist'}
695
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
696
+
697
+ uri = blob_uri(container, blob, query)
698
+
699
+ headers = service_properties_headers
700
+ unless options.empty?
701
+ headers['Content-MD5'] = options[:content_md5] if options[:content_md5]
702
+ headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
703
+ headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
704
+ headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
705
+ headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
706
+ headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
707
+ headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
708
+
709
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
710
+ end
711
+
712
+ body = Serialization.block_list_to_xml(block_list)
713
+ call(:put, uri, body, headers)
714
+ nil
715
+ end
716
+
717
+ # Public: Retrieves the list of blocks that have been uploaded as part of a block blob.
718
+ #
719
+ # There are two block lists maintained for a blob:
720
+ # 1) Committed Block List: The list of blocks that have been successfully
721
+ # committed to a given blob with commitBlobBlocks.
722
+ # 2) Uncommitted Block List: The list of blocks that have been uploaded for a
723
+ # blob using Put Block (REST API), but that have not yet been committed.
724
+ # These blocks are stored in Microsoft Azure in association with a blob, but do
725
+ # not yet form part of the blob.
726
+ #
727
+ # ==== Attributes
728
+ #
729
+ # * +container+ - String. The container name.
730
+ # * +blob+ - String. The blob name.
731
+ # * +options+ - Hash. Optional parameters.
732
+ #
733
+ # ==== Options
734
+ #
735
+ # Accepted key/value pairs in options parameter are:
736
+ # * +:blocklist_type+ - Symbol. One of :all, :committed, :uncommitted. Defaults to :all (optional)
737
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
738
+ # retrieve information from. (optional)
739
+ # * +:timeout+ - Integer. A timeout in seconds.
740
+ #
741
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179400.aspx
742
+ #
743
+ # Returns a list of Azure::Entity::Blob::Block instances
744
+ def list_blob_blocks(container, blob, options={})
745
+
746
+ options[:blocklist_type] = options[:blocklist_type] || :all
747
+
748
+ query = { 'comp' => 'blocklist'}
749
+ query['snapshot'] = options[:snapshot] if options[:snapshot]
750
+ query['blocklisttype'] = options[:blocklist_type].to_s if options[:blocklist_type]
751
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
752
+
753
+ uri = blob_uri(container, blob, query)
754
+
755
+ response = call(:get, uri)
756
+
757
+ Serialization.block_list_from_xml(response.body)
758
+ end
759
+
760
+ # Public: Returns all properties and metadata on the blob.
761
+ #
762
+ # ==== Attributes
763
+ #
764
+ # * +container+ - String. The container name.
765
+ # * +blob+ - String. The blob name.
766
+ # * +options+ - Hash. Optional parameters.
767
+ #
768
+ # ==== Options
769
+ #
770
+ # Accepted key/value pairs in options parameter are:
771
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
772
+ # retrieve information from.
773
+ # * +:timeout+ - Integer. A timeout in seconds.
774
+ #
775
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179394.aspx
776
+ #
777
+ # Returns a Blob
778
+ def get_blob_properties(container, blob, options={})
779
+ query = { }
780
+ query['snapshot'] = options[:snapshot] if options[:snapshot]
781
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
782
+
783
+ uri = blob_uri(container, blob, query)
784
+
785
+ response = call(:head, uri)
786
+
787
+ result = Serialization.blob_from_headers(response.headers)
788
+
789
+ result.name = blob
790
+ result.snapshot = options[:snapshot]
791
+
792
+ result
793
+ end
794
+
795
+ # Public: Returns metadata on the blob.
796
+ #
797
+ # ==== Attributes
798
+ #
799
+ # * +container+ - String. The container name.
800
+ # * +blob+ - String. The blob name.
801
+ # * +options+ - Hash. Optional parameters.
802
+ #
803
+ # ==== Options
804
+ #
805
+ # Accepted key/value pairs in options parameter are:
806
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
807
+ # retrieve information from.
808
+ # * +:timeout+ - Integer. A timeout in seconds.
809
+ #
810
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179350.aspx
811
+ #
812
+ # Returns a Blob
813
+ def get_blob_metadata(container, blob, options={})
814
+ query = {'comp' => 'metadata'}
815
+ query['snapshot'] = options[:snapshot] if options[:snapshot]
816
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
817
+
818
+ uri = blob_uri(container, blob, query)
819
+
820
+ response = call(:get, uri)
821
+
822
+ result = Serialization.blob_from_headers(response.headers)
823
+
824
+ result.name = blob
825
+ result.snapshot = options[:snapshot]
826
+
827
+ result
828
+ end
829
+
830
+ # Public: Returns a list of active page ranges for a page blob. Active page ranges are
831
+ # those that have been populated with data.
832
+ #
833
+ # ==== Attributes
834
+ #
835
+ # * +container+ - String. The container name.
836
+ # * +blob+ - String. The blob name.
837
+ # * +options+ - Hash. Optional parameters.
838
+ #
839
+ # ==== Options
840
+ #
841
+ # Accepted key/value pairs in options parameter are:
842
+ # * +:start_range+ - Integer. Position of first byte of first page. (optional)
843
+ # * +:end_range+ - Integer. Position of last byte of of last page. (optional)
844
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
845
+ # retrieve information from. (optional)
846
+ # * +:timeout+ - Integer. A timeout in seconds.
847
+ #
848
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691973.aspx
849
+ #
850
+ # Returns a list of page ranges in the format [ [start, end], [start, end], ... ]
851
+ #
852
+ # eg. [ [0, 511], [512, 1024], ... ]
853
+ #
854
+ def list_page_blob_ranges(container, blob, options={})
855
+ query = {'comp' => 'pagelist'}
856
+ query.update({'snapshot' => options[:snapshot]}) if options[:snapshot]
857
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
858
+
859
+ uri = blob_uri(container, blob, query)
860
+
861
+ options[:start_range] = 0 if options[:end_range] and not options[:start_range]
862
+
863
+ headers = service_properties_headers
864
+ headers = { 'x-ms-range' => "bytes=#{options[:start_range]}-#{options[:end_range]}" } if options[:start_range]
865
+
866
+ response = call(:get, uri, nil, headers)
867
+
868
+ pagelist = Serialization.page_list_from_xml(response.body)
869
+ pagelist
870
+ end
871
+
872
+ # Public: Sets system properties defined for a blob.
873
+ #
874
+ # ==== Attributes
875
+ #
876
+ # * +container+ - String. The container name.
877
+ # * +blob+ - String. The blob name.
878
+ # * +options+ - Hash. Optional parameters.
879
+ #
880
+ # ==== Options
881
+ #
882
+ # Accepted key/value pairs in options parameter are:
883
+ # * +:content_type+ - String. Content type for the blob. Will be saved with blob.
884
+ # * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
885
+ # * +:content_language+ - String. Content language for the blob. Will be saved with blob.
886
+ # * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
887
+ # * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
888
+ # * +:content_length+ - Integer. Resizes a page blob to the specified size. If the specified
889
+ # value is less than the current size of the blob, then all pages above
890
+ # the specified value are cleared. This property cannot be used to change
891
+ # the size of a block blob. Setting this property for a block blob returns
892
+ # status code 400 (Bad Request).
893
+ # * +:sequence_number_action+ - Symbol. This property indicates how the service should modify the sequence
894
+ # number for the blob. Required if :sequence_number is used. This property
895
+ # applies to page blobs only.
896
+ #
897
+ # Specify one of the following options for this property:
898
+ #
899
+ # * +:max+ - Sets the sequence number to be the higher of the value included with
900
+ # the request and the value currently stored for the blob.
901
+ # * +:update+ - Sets the sequence number to the value included with the request.
902
+ # * +:increment+ - Increments the value of the sequence number by 1. If specifying this
903
+ # option, do not include the sequence_number option; doing so will return
904
+ # status code 400 (Bad Request).
905
+ # * +:sequence_number+ - Integer. This property sets the blob's sequence number. The sequence number is a
906
+ # user-controlled property that you can use to track requests and manage concurrency
907
+ # issues. Required if the :sequence_number_action option is set to :max or :update.
908
+ # This property applies to page blobs only.
909
+ #
910
+ # Use this together with the :sequence_number_action to update the blob's sequence
911
+ # number, either to the specified value or to the higher of the values specified with
912
+ # the request or currently stored with the blob.
913
+ #
914
+ # This header should not be specified if :sequence_number_action is set to :increment;
915
+ # in this case the service automatically increments the sequence number by one.
916
+ #
917
+ # To set the sequence number to a value of your choosing, this property must be specified
918
+ # together with :sequence_number_action
919
+ # * +:timeout+ - Integer. A timeout in seconds.
920
+ #
921
+ # Remarks:
922
+ #
923
+ # The semantics for updating a blob's properties are as follows:
924
+ #
925
+ # * A page blob's sequence number is updated only if the request meets either of the following conditions:
926
+ #
927
+ # * The :sequence_number_action property is set to :max or :update, and a value for :sequence_number is also set.
928
+ # * The :sequence_number_action property is set to :increment, indicating that the service should increment
929
+ # the sequence number by one.
930
+ #
931
+ # * The size of the page blob is modified only if a value for :content_length is specified.
932
+ #
933
+ # * If :sequence_number and/or :content_length are the only properties specified, then the other properties of the blob
934
+ # will NOT be modified.
935
+ #
936
+ # * If any one or more of the following properties are set, then all of these properties are set together. If a value is
937
+ # not provided for a given property when at least one of the properties listed below is set, then that property will be
938
+ # cleared for the blob.
939
+ #
940
+ # * :cache_control
941
+ # * :content_type
942
+ # * :content_md5
943
+ # * :content_encoding
944
+ # * :content_language
945
+ #
946
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
947
+ #
948
+ # Returns nil on success.
949
+ def set_blob_properties(container, blob, options={})
950
+ query = { 'comp' => 'properties'}
951
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
952
+ uri = blob_uri(container, blob, query)
953
+
954
+ headers = service_properties_headers
955
+
956
+ unless options.empty?
957
+ headers['x-ms-blob-content-type'] = options[:blob_content_type] if options[:blob_content_type]
958
+ headers['x-ms-blob-content-encoding'] = options[:blob_content_encoding] if options[:blob_content_encoding]
959
+ headers['x-ms-blob-content-language'] = options[:blob_content_language] if options[:blob_content_language]
960
+ headers['x-ms-blob-content-md5'] = options[:blob_content_md5] if options[:blob_content_md5]
961
+ headers['x-ms-blob-cache-control'] = options[:blob_cache_control] if options[:blob_cache_control]
962
+ headers['x-ms-blob-content-length'] = options[:blob_content_length].to_s if options[:blob_content_length]
963
+ headers['x-ms-blob-sequence-number-action'] = options[:sequence_number_action].to_s if options[:sequence_number_action]
964
+ headers['x-ms-blob-sequence-number'] = options[:sequence_number].to_s if options[:sequence_number]
965
+ headers['x-ms-blob-content-disposition'] = options[:blob_content_disposition] if options[:blob_content_disposition]
966
+ end
967
+
968
+ call(:put, uri, nil, headers)
969
+ nil
970
+ end
971
+
972
+ # Public: Sets metadata headers on the blob.
973
+ #
974
+ # ==== Attributes
975
+ #
976
+ # * +container+ - String. The container name.
977
+ # * +blob+ - String. The blob name.
978
+ # * +metadata+ - Hash. The custom metadata.
979
+ # * +options+ - Hash. Optional parameters.
980
+ #
981
+ # ==== Options
982
+ #
983
+ # Accepted key/value pairs in options parameter are:
984
+ # * +:timeout+ - Integer. A timeout in seconds.
985
+ #
986
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
987
+ #
988
+ # Returns nil on success.
989
+ def set_blob_metadata(container, blob, metadata, options={})
990
+ query = { 'comp' => 'metadata'}
991
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
992
+ uri = blob_uri(container, blob, query)
993
+
994
+ headers = service_properties_headers
995
+
996
+ add_metadata_to_headers(metadata, headers) if metadata
997
+
998
+ call(:put, uri, nil, headers)
999
+ nil
1000
+ end
1001
+
1002
+ # Public: Reads or downloads a blob from the system, including its metadata and properties.
1003
+ #
1004
+ # ==== Attributes
1005
+ #
1006
+ # * +container+ - String. The container name.
1007
+ # * +blob+ - String. The blob name.
1008
+ # * +options+ - Hash. Optional parameters.
1009
+ #
1010
+ # ==== Options
1011
+ #
1012
+ # Accepted key/value pairs in options parameter are:
1013
+ # * +:start_range+ - Integer. Position of first byte of first page. (optional)
1014
+ # * +:end_range+ - Integer. Position of last byte of of last page. (optional)
1015
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
1016
+ # retrieve information from. (optional)
1017
+ # * +:get_content_md5+ - Boolean. Return the MD5 hash for the range. This option only valid if
1018
+ # start_range and end_range are specified. (optional)
1019
+ # * +:timeout+ - Integer. A timeout in seconds.
1020
+ #
1021
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
1022
+ #
1023
+ # Returns a blob and the blob body
1024
+ def get_blob(container, blob, options={})
1025
+ query = { }
1026
+ query['snapshot'] = options[:snapshot] if options[:snapshot]
1027
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1028
+ uri = blob_uri(container, blob, query)
1029
+
1030
+ headers = service_properties_headers
1031
+ options[:start_range] = 0 if options[:end_range] and not options[:start_range]
1032
+ if options[:start_range]
1033
+ headers['x-ms-range'] = "bytes=#{options[:start_range]}-#{options[:end_range]}"
1034
+ headers['x-ms-range-get-content-md5'] = true if options[:get_content_md5]
1035
+ end
1036
+
1037
+ response = call(:get, uri, nil, headers)
1038
+ result = Serialization.blob_from_headers(response.headers)
1039
+ result.name = blob unless result.name
1040
+ return result, response.body
1041
+ end
1042
+
1043
+ # Public: Deletes a blob or blob snapshot.
1044
+ #
1045
+ # ==== Attributes
1046
+ #
1047
+ # * +container+ - String. The container name.
1048
+ # * +blob+ - String. The blob name.
1049
+ # * +options+ - Hash. Optional parameters.
1050
+ #
1051
+ # ==== Options
1052
+ #
1053
+ # Accepted key/value pairs in options parameter are:
1054
+ # * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
1055
+ # retrieve information from. (optional)
1056
+ # * +:delete_snapshots+ - Symbol. Used to specify the scope of the delete operation for snapshots.
1057
+ # This parameter is ignored if a blob does not have snapshots, or if a
1058
+ # snapshot is specified in the snapshot parameter. (optional)
1059
+ #
1060
+ # Possible values include:
1061
+ # * +:only+ - Deletes only the snapshots for the blob, but leaves the blob
1062
+ # * +:include+ - Deletes the blob and all of the snapshots for the blob
1063
+ # * +:timeout+ - Integer. A timeout in seconds.
1064
+ #
1065
+ # See http://msdn.microsoft.com/en-us/library/azure/dd179440.aspx
1066
+ #
1067
+ # Returns nil on success
1068
+ def delete_blob(container, blob, options={})
1069
+ query = { }
1070
+ query['snapshot'] = options[:snapshot] if options[:snapshot]
1071
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1072
+
1073
+ uri = blob_uri(container, blob, query)
1074
+
1075
+ options[:delete_snapshots] = :include unless options[:delete_snapshots]
1076
+
1077
+ headers = service_properties_headers
1078
+ headers['x-ms-delete-snapshots'] = options[:delete_snapshots].to_s if options[:delete_snapshots] && options[:snapshot] == nil
1079
+
1080
+ call(:delete, uri, nil, headers)
1081
+ nil
1082
+ end
1083
+
1084
+ # Public: Creates a snapshot of a blob.
1085
+ #
1086
+ # ==== Attributes
1087
+ #
1088
+ # * +container+ - String. The container name.
1089
+ # * +blob+ - String. The blob name.
1090
+ # * +options+ - Hash. Optional parameters.
1091
+ #
1092
+ # ==== Options
1093
+ #
1094
+ # Accepted key/value pairs in options parameter are:
1095
+ # * +:metadata+ - Hash. Custom metadata values to store with the blob snapshot.
1096
+ # * +:if_modified_since+ - A DateTime value. Specify this option to write the page only if the blob has been
1097
+ # modified since the specified date/time. If the blob has not been modified, the
1098
+ # Blob service returns status code 412 (Precondition Failed).
1099
+ # * +:if_unmodified_since+ - A DateTime value. Specify this option to write the page only if the blob has not
1100
+ # been modified since the specified date/time. If the blob has been modified, the
1101
+ # Blob service returns status code 412 (Precondition Failed).
1102
+ # * +:if_match+ - An ETag value. Specify an ETag value to write the page only if the blob's ETag
1103
+ # value matches the value specified. If the values do not match, the Blob service
1104
+ # returns status code 412 (Precondition Failed).
1105
+ # * +:if_none_match+ - An ETag value. Specify an ETag value to write the page only if the blob's ETag
1106
+ # value does not match the value specified. If the values are identical, the Blob
1107
+ # service returns status code 412 (Precondition Failed).
1108
+ # * +:timeout+ - Integer. A timeout in seconds.
1109
+ #
1110
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691971.aspx
1111
+ #
1112
+ # Returns the snapshot DateTime value
1113
+ def create_blob_snapshot(container, blob, options={})
1114
+ query = { 'comp' => 'snapshot'}
1115
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1116
+
1117
+ uri = blob_uri(container, blob, query)
1118
+
1119
+ headers = service_properties_headers
1120
+ unless options.empty?
1121
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
1122
+
1123
+ headers['If-Modified-Since'] = options[:if_modified_since] if options[:if_modified_since]
1124
+ headers['If-Unmodified-Since'] = options[:if_unmodified_since] if options[:if_unmodified_since]
1125
+ headers['If-Match'] = options[:if_match] if options[:if_match]
1126
+ headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
1127
+ end
1128
+
1129
+ response = call(:put, uri, nil, headers)
1130
+
1131
+ response.headers['x-ms-snapshot']
1132
+ end
1133
+
1134
+ # Public: Copies a source blob to a destination blob within the same storage account.
1135
+ #
1136
+ # ==== Attributes
1137
+ #
1138
+ # * +source_container+ - String. The destination container name to copy to.
1139
+ # * +source_blob+ - String. The destination blob name to copy to.
1140
+ # * +destination_container+ - String. The source container name to copy from.
1141
+ # * +destination_blob+ - String. The source blob name to copy from.
1142
+ # * +options+ - Hash. Optional parameters.
1143
+ #
1144
+ # ==== Options
1145
+ #
1146
+ # Accepted key/value pairs in options parameter are:
1147
+ # * +:source_snapshot+ - String. A snapshot id for the source blob
1148
+ # * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
1149
+ # specified, the operation will copy the source blob metadata to the destination
1150
+ # blob. If this parameter is specified, the destination blob is created with the
1151
+ # specified metadata, and metadata is not copied from the source blob.
1152
+ # * +:source_if_modified_since+ - A DateTime value. Specify this option to write the page only if the source blob
1153
+ # has been modified since the specified date/time. If the blob has not been
1154
+ # modified, the Blob service returns status code 412 (Precondition Failed).
1155
+ # * +:source_if_unmodified_since+ - A DateTime value. Specify this option to write the page only if the source blob
1156
+ # has not been modified since the specified date/time. If the blob has been
1157
+ # modified, the Blob service returns status code 412 (Precondition Failed).
1158
+ # * +:source_if_match+ - An ETag value. Specify an ETag value to write the page only if the source blob's
1159
+ # ETag value matches the value specified. If the values do not match, the Blob
1160
+ # service returns status code 412 (Precondition Failed).
1161
+ # * +:source_if_none_match+ - An ETag value. Specify an ETag value to write the page only if the source blob's
1162
+ # ETag value does not match the value specified. If the values are identical, the
1163
+ # Blob service returns status code 412 (Precondition Failed).
1164
+ # * +:dest_if_modified_since+ - A DateTime value. Specify this option to write the page only if the destination
1165
+ # blob has been modified since the specified date/time. If the blob has not been
1166
+ # modified, the Blob service returns status code 412 (Precondition Failed).
1167
+ # * +:dest_if_unmodified_since+ - A DateTime value. Specify this option to write the page only if the destination
1168
+ # blob has not been modified since the specified date/time. If the blob has been
1169
+ # modified, the Blob service returns status code 412 (Precondition Failed).
1170
+ # * +:dest_if_match+ - An ETag value. Specify an ETag value to write the page only if the destination
1171
+ # blob's ETag value matches the value specified. If the values do not match, the
1172
+ # Blob service returns status code 412 (Precondition Failed).
1173
+ # * +:dest_if_none_match+ - An ETag value. Specify an ETag value to write the page only if the destination
1174
+ # blob's ETag value does not match the value specified. If the values are
1175
+ # identical, the Blob service returns status code 412 (Precondition Failed).
1176
+ # * +:timeout+ - Integer. A timeout in seconds.
1177
+ #
1178
+ # See http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
1179
+ #
1180
+ # Returns a tuple of (copy_id, copy_status).
1181
+ #
1182
+ # * +copy_id+ - String identifier for this copy operation. Use with get_blob or get_blob_properties to check
1183
+ # the status of this copy operation, or pass to abort_copy_blob to abort a pending copy.
1184
+ # * +copy_status+ - String. The state of the copy operation, with these values:
1185
+ # "success" - The copy completed successfully.
1186
+ # "pending" - The copy is in progress.
1187
+ #
1188
+ def copy_blob(destination_container, destination_blob, source_container, source_blob, options={})
1189
+ query = { }
1190
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1191
+
1192
+ uri = blob_uri(destination_container, destination_blob, query)
1193
+ headers = service_properties_headers
1194
+ headers['x-ms-copy-source'] = blob_uri(source_container, source_blob, options[:source_snapshot] ? { 'snapshot' => options[:source_snapshot] } : {}).to_s
1195
+
1196
+ unless options.empty?
1197
+ headers['If-Modified-Since'] = options[:dest_if_modified_since] if options[:dest_if_modified_since]
1198
+ headers['If-Unmodified-Since'] = options[:dest_if_unmodified_since] if options[:dest_if_unmodified_since]
1199
+ headers['If-Match'] = options[:dest_if_match] if options[:dest_if_match]
1200
+ headers['If-None-Match'] = options[:dest_if_none_match] if options[:dest_if_none_match]
1201
+ headers['x-ms-source-if-modified-since'] = options[:source_if_modified_since] if options[:source_if_modified_since]
1202
+ headers['x-ms-source-if-unmodified-since'] = options[:source_if_unmodified_since] if options[:source_if_unmodified_since]
1203
+ headers['x-ms-source-if-match'] = options[:source_if_match] if options[:source_if_match]
1204
+ headers['x-ms-source-if-none-match'] = options[:source_if_none_match] if options[:source_if_none_match]
1205
+
1206
+ add_metadata_to_headers(options[:metadata], headers) if options[:metadata]
1207
+ end
1208
+
1209
+ response = call(:put, uri, nil, headers)
1210
+ return response.headers['x-ms-copy-id'], response.headers['x-ms-copy-status']
1211
+ end
1212
+
1213
+ # Public: Establishes an exclusive one-minute write lock on a blob. To write to a locked
1214
+ # blob, a client must provide a lease ID.
1215
+ #
1216
+ # ==== Attributes
1217
+ #
1218
+ # * +container+ - String. The container name.
1219
+ # * +blob+ - String. The blob name.
1220
+ # * +options+ - Hash. Optional parameters.
1221
+ #
1222
+ # ==== Options
1223
+ #
1224
+ # Accepted key/value pairs in options parameter are:
1225
+ # * +:duration+ - Integer. Default -1. Specifies the duration of the lease, in seconds, or negative one (-1)
1226
+ # for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. (optional)
1227
+ # * +:proposed_lease_id+ - String. Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request)
1228
+ # if the proposed lease ID is not in the correct format. (optional)
1229
+ # * +:timeout+ - Integer. A timeout in seconds.
1230
+ #
1231
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
1232
+ #
1233
+ # Returns a String of the new unique lease id. While the lease is active, you must include the lease ID with any request
1234
+ # to write to the blob, or to renew, change, or release the lease. A successful renew operation also returns the lease id
1235
+ # for the active lease.
1236
+ #
1237
+ def acquire_lease(container, blob, options={})
1238
+ query = { 'comp' => 'lease'}
1239
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1240
+
1241
+ uri = blob_uri(container, blob, query)
1242
+
1243
+ duration = -1
1244
+ duration = options[:duration] if options[:duration]
1245
+
1246
+ headers = service_properties_headers
1247
+ headers['x-ms-lease-action'] = 'acquire'
1248
+ headers['x-ms-lease-duration'] = duration.to_s if duration
1249
+ headers['x-ms-proposed-lease-id'] = options[:proposed_lease_id] if options[:proposed_lease_id]
1250
+
1251
+ response = call(:put, uri, nil, headers)
1252
+ response.headers['x-ms-lease-id']
1253
+ end
1254
+
1255
+ # Public: Renews the lease. The lease can be renewed if the lease ID specified on the request matches that
1256
+ # associated with the blob. Note that the lease may be renewed even if it has expired as long as the blob
1257
+ # has not been modified or leased again since the expiration of that lease. When you renew a lease, the
1258
+ # lease duration clock resets.
1259
+ #
1260
+ # ==== Attributes
1261
+ #
1262
+ # * +container+ - String. The container name.
1263
+ # * +blob+ - String. The blob name.
1264
+ # * +lease+ - String. The lease id
1265
+ # * +options+ - Hash. Optional parameters.
1266
+ #
1267
+ # ==== Options
1268
+ #
1269
+ # Accepted key/value pairs in options parameter are:
1270
+ # * +:timeout+ - Integer. A timeout in seconds.
1271
+ #
1272
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
1273
+ #
1274
+ # Returns the renewed lease id
1275
+ def renew_lease(container, blob, lease, options={})
1276
+ query = { 'comp' => 'lease'}
1277
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1278
+
1279
+ uri = blob_uri(container, blob, query)
1280
+
1281
+ headers = service_properties_headers
1282
+ headers['x-ms-lease-action'] = 'renew'
1283
+ headers['x-ms-lease-id'] = lease
1284
+
1285
+ response = call(:put, uri, nil, headers)
1286
+ response.headers['x-ms-lease-id']
1287
+ end
1288
+
1289
+ # Public: Releases the lease. The lease may be released if the lease ID specified on the request matches that
1290
+ # associated with the blob. Releasing the lease allows another client to immediately acquire the lease for
1291
+ # the blob as soon as the release is complete.
1292
+ #
1293
+ # ==== Attributes
1294
+ #
1295
+ # * +container+ - String. The container name.
1296
+ # * +blob+ - String. The blob name.
1297
+ # * +lease+ - String. The lease id.
1298
+ # * +options+ - Hash. Optional parameters.
1299
+ #
1300
+ # ==== Options
1301
+ #
1302
+ # Accepted key/value pairs in options parameter are:
1303
+ # * +:timeout+ - Integer. A timeout in seconds.
1304
+ #
1305
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
1306
+ #
1307
+ # Returns nil on success
1308
+ def release_lease(container, blob, lease, options={})
1309
+ query = { 'comp' => 'lease'}
1310
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1311
+
1312
+ uri = blob_uri(container, blob, query)
1313
+
1314
+ headers = service_properties_headers
1315
+ headers['x-ms-lease-action'] = 'release'
1316
+ headers['x-ms-lease-id'] = lease
1317
+
1318
+ call(:put, uri, nil, headers)
1319
+ nil
1320
+ end
1321
+
1322
+ # Public: Breaks the lease, if the blob has an active lease. Once a lease is broken, it cannot be renewed. Any
1323
+ # authorized request can break the lease; the request is not required to specify a matching lease ID. When a
1324
+ # lease is broken, the lease break period is allowed to elapse, during which time no lease operation except
1325
+ # break and release can be performed on the blob. When a lease is successfully broken, the response indicates
1326
+ # the interval in seconds until a new lease can be acquired.
1327
+ #
1328
+ # A lease that has been broken can also be released, in which case another client may immediately acquire the
1329
+ # lease on the blob.
1330
+ #
1331
+ # ==== Attributes
1332
+ #
1333
+ # * +container+ - String. The container name.
1334
+ # * +blob+ - String. The blob name.
1335
+ # * +options+ - Hash. Optional parameters.
1336
+ #
1337
+ # ==== Options
1338
+ #
1339
+ # Accepted key/value pairs in options parameter are:
1340
+ # * +:break_period+ - Integer. The proposed duration of seconds that the lease should continue before it is
1341
+ # broken, between 0 and 60 seconds. This break period is only used if it is shorter than
1342
+ # the time remaining on the lease. If longer, the time remaining on the lease is used. A
1343
+ # new lease will not be available before the break period has expired, but the lease may
1344
+ # be held for longer than the break period.
1345
+ #
1346
+ # If this option is not used, a fixed-duration lease breaks after the remaining lease
1347
+ # period elapses, and an infinite lease breaks immediately.
1348
+ # * +:timeout+ - Integer. A timeout in seconds.
1349
+ #
1350
+ # See http://msdn.microsoft.com/en-us/library/azure/ee691972.aspx
1351
+ #
1352
+ # Returns an Integer of the remaining lease time. This value is the approximate time remaining in the lease
1353
+ # period, in seconds. This header is returned only for a successful request to break the lease. If the break
1354
+ # is immediate, 0 is returned.
1355
+ def break_lease(container, blob, options={})
1356
+ query = { 'comp' => 'lease'}
1357
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
1358
+
1359
+ uri = blob_uri(container, blob, query)
1360
+
1361
+ headers = service_properties_headers
1362
+ headers['x-ms-lease-action'] = 'break'
1363
+ headers['x-ms-lease-break-period'] = options[:break_period].to_s if options[:break_period]
1364
+
1365
+ response = call(:put, uri, nil, headers)
1366
+ response.headers['x-ms-lease-time'].to_i
1367
+ end
1368
+
1369
+ def call(method, uri, body=nil, headers=nil)
1370
+ # Force the request.body to the content encoding of specified in the header
1371
+ # (content encoding probably shouldn't be used this way)
1372
+ if headers && !body.nil?
1373
+ if headers['Content-Encoding'].nil?
1374
+ headers['Content-Encoding'] = body.encoding.to_s
1375
+ else
1376
+ body.force_encoding(headers['Content-Encoding'])
1377
+ end
1378
+ end
1379
+
1380
+ response = super
1381
+
1382
+ # Force the response.body to the content encoding of specified in the header.
1383
+ # content-encoding is echo'd back for the blob and is used to store the encoding of the octet stream
1384
+ if !response.nil? && !response.body.nil? && response.headers['content-encoding']
1385
+ response.body.force_encoding(response.headers['content-encoding'])
1386
+ end
1387
+
1388
+ response
1389
+ end
1390
+
1391
+ # Protected: Generate the URI for the collection of containers.
1392
+ #
1393
+ # ==== Attributes
1394
+ #
1395
+ # * +query+ - A Hash of key => value query parameters.
1396
+ # * +host+ - The host of the API.
1397
+ #
1398
+ # Returns a URI.
1399
+ protected
1400
+ def containers_uri(query={})
1401
+ query = { 'comp' => 'list'}.merge(query)
1402
+ generate_uri('/', query)
1403
+ end
1404
+
1405
+ # Protected: Generate the URI for a specific container.
1406
+ #
1407
+ # ==== Attributes
1408
+ #
1409
+ # * +name+ - The container name. If this is a URI, we just return this.
1410
+ # * +query+ - A Hash of key => value query parameters.
1411
+ # * +host+ - The host of the API.
1412
+ #
1413
+ # Returns a URI.
1414
+ def container_uri(name, query={})
1415
+ return name if name.kind_of? ::URI
1416
+ query = { 'restype' => 'container'}.merge(query)
1417
+ generate_uri(name, query)
1418
+ end
1419
+
1420
+ # Protected: Generate the URI for a specific Blob.
1421
+ #
1422
+ # ==== Attributes
1423
+ #
1424
+ # * +container_name+ - String representing the name of the container.
1425
+ # * +blob_name+ - String representing the name of the blob.
1426
+ # * +query+ - A Hash of key => value query parameters.
1427
+ # * +host+ - The host of the API.
1428
+ #
1429
+ # Returns a URI.
1430
+ def blob_uri(container_name, blob_name, query={})
1431
+ if container_name.nil? || container_name.empty?
1432
+ path = blob_name
1433
+ else
1434
+ path = File.join(container_name, blob_name)
1435
+ end
1436
+
1437
+ path = CGI.escape(path.encode('UTF-8'))
1438
+
1439
+ # Unencode the forward slashes to match what the server expects.
1440
+ path = path.gsub(/%2F/, '/')
1441
+ # Unencode the backward slashes to match what the server expects.
1442
+ path = path.gsub(/%5C/, '/')
1443
+ # Re-encode the spaces (encoded as space) to the % encoding.
1444
+ path = path.gsub(/\+/, '%20')
1445
+
1446
+ generate_uri(path, query)
1447
+ end
1448
+ end
1449
+ end
1450
+ end
1451
+
1452
+ Azure::BlobService = Azure::Blob::BlobService