fog-azure-rm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +2 -1
  4. data/fog-azure-rm.gemspec +11 -9
  5. data/lib/fog/azurerm.rb +1 -0
  6. data/lib/fog/azurerm/compute.rb +3 -3
  7. data/lib/fog/azurerm/config.rb +33 -0
  8. data/lib/fog/azurerm/credentials.rb +1 -1
  9. data/lib/fog/azurerm/dns.rb +2 -2
  10. data/lib/fog/azurerm/docs/storage.md +120 -66
  11. data/lib/fog/azurerm/models/application_gateway/gateway.rb +30 -31
  12. data/lib/fog/azurerm/models/application_gateway/gateways.rb +4 -4
  13. data/lib/fog/azurerm/models/compute/availability_sets.rb +4 -4
  14. data/lib/fog/azurerm/models/compute/server.rb +14 -14
  15. data/lib/fog/azurerm/models/compute/servers.rb +4 -4
  16. data/lib/fog/azurerm/models/compute/virtual_machine_extension.rb +3 -5
  17. data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +5 -5
  18. data/lib/fog/azurerm/models/dns/record_sets.rb +4 -4
  19. data/lib/fog/azurerm/models/dns/zones.rb +4 -4
  20. data/lib/fog/azurerm/models/network/express_route_circuit.rb +2 -5
  21. data/lib/fog/azurerm/models/network/express_route_circuit_authorization.rb +1 -1
  22. data/lib/fog/azurerm/models/network/express_route_circuit_authorizations.rb +4 -4
  23. data/lib/fog/azurerm/models/network/express_route_circuit_peering.rb +3 -5
  24. data/lib/fog/azurerm/models/network/express_route_circuit_peerings.rb +4 -4
  25. data/lib/fog/azurerm/models/network/express_route_circuits.rb +4 -4
  26. data/lib/fog/azurerm/models/network/express_route_service_providers.rb +2 -2
  27. data/lib/fog/azurerm/models/network/load_balancers.rb +5 -5
  28. data/lib/fog/azurerm/models/network/local_network_gateway.rb +1 -1
  29. data/lib/fog/azurerm/models/network/local_network_gateways.rb +4 -4
  30. data/lib/fog/azurerm/models/network/network_interfaces.rb +5 -5
  31. data/lib/fog/azurerm/models/network/network_security_groups.rb +5 -5
  32. data/lib/fog/azurerm/models/network/network_security_rule.rb +3 -4
  33. data/lib/fog/azurerm/models/network/network_security_rules.rb +4 -4
  34. data/lib/fog/azurerm/models/network/public_ips.rb +4 -4
  35. data/lib/fog/azurerm/models/network/subnets.rb +4 -4
  36. data/lib/fog/azurerm/models/network/virtual_network_gateway.rb +6 -7
  37. data/lib/fog/azurerm/models/network/virtual_network_gateway_connection.rb +5 -5
  38. data/lib/fog/azurerm/models/network/virtual_network_gateway_connections.rb +4 -4
  39. data/lib/fog/azurerm/models/network/virtual_network_gateways.rb +4 -4
  40. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -4
  41. data/lib/fog/azurerm/models/resources/azure_resources.rb +2 -2
  42. data/lib/fog/azurerm/models/resources/deployments.rb +4 -4
  43. data/lib/fog/azurerm/models/resources/resource_groups.rb +4 -4
  44. data/lib/fog/azurerm/models/sql/firewall_rule.rb +1 -1
  45. data/lib/fog/azurerm/models/sql/firewall_rules.rb +4 -4
  46. data/lib/fog/azurerm/models/sql/sql_database.rb +28 -24
  47. data/lib/fog/azurerm/models/sql/sql_databases.rb +5 -6
  48. data/lib/fog/azurerm/models/sql/sql_servers.rb +4 -4
  49. data/lib/fog/azurerm/models/storage/directories.rb +49 -24
  50. data/lib/fog/azurerm/models/storage/directory.rb +126 -40
  51. data/lib/fog/azurerm/models/storage/file.rb +226 -114
  52. data/lib/fog/azurerm/models/storage/files.rb +168 -13
  53. data/lib/fog/azurerm/models/storage/recovery_vault.rb +1 -1
  54. data/lib/fog/azurerm/models/storage/recovery_vaults.rb +4 -4
  55. data/lib/fog/azurerm/models/storage/storage_account.rb +5 -5
  56. data/lib/fog/azurerm/models/storage/storage_accounts.rb +4 -4
  57. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  58. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_points.rb +4 -4
  59. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +4 -4
  60. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profiles.rb +4 -4
  61. data/lib/fog/azurerm/network.rb +1 -1
  62. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +17 -13
  63. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +1 -1
  64. data/lib/fog/azurerm/requests/resources/create_deployment.rb +1 -1
  65. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +1 -1
  66. data/lib/fog/azurerm/requests/resources/delete_deployment.rb +1 -1
  67. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +1 -1
  68. data/lib/fog/azurerm/requests/resources/get_deployment.rb +1 -1
  69. data/lib/fog/azurerm/requests/resources/get_resource_group.rb +1 -1
  70. data/lib/fog/azurerm/requests/resources/list_deployments.rb +1 -1
  71. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +1 -1
  72. data/lib/fog/azurerm/requests/resources/list_tagged_resources.rb +1 -1
  73. data/lib/fog/azurerm/requests/resources/tag_resource.rb +1 -1
  74. data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +3 -3
  75. data/lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb +3 -3
  76. data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +3 -3
  77. data/lib/fog/azurerm/requests/sql/delete_database.rb +2 -2
  78. data/lib/fog/azurerm/requests/sql/delete_firewall_rule.rb +4 -4
  79. data/lib/fog/azurerm/requests/sql/delete_sql_server.rb +4 -4
  80. data/lib/fog/azurerm/requests/sql/get_database.rb +3 -3
  81. data/lib/fog/azurerm/requests/sql/get_firewall_rule.rb +3 -3
  82. data/lib/fog/azurerm/requests/sql/get_sql_server.rb +3 -3
  83. data/lib/fog/azurerm/requests/sql/list_databases.rb +3 -3
  84. data/lib/fog/azurerm/requests/sql/list_firewall_rules.rb +3 -3
  85. data/lib/fog/azurerm/requests/sql/list_sql_servers.rb +3 -3
  86. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +5 -2
  87. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +5 -2
  88. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  89. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  90. data/lib/fog/azurerm/requests/storage/copy_blob.rb +8 -8
  91. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +8 -8
  92. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  93. data/lib/fog/azurerm/requests/storage/create_container.rb +12 -10
  94. data/lib/fog/azurerm/requests/storage/create_disk.rb +45 -19
  95. data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +2 -2
  96. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  97. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +2 -2
  98. data/lib/fog/azurerm/requests/storage/delete_blob.rb +10 -5
  99. data/lib/fog/azurerm/requests/storage/delete_container.rb +6 -2
  100. data/lib/fog/azurerm/requests/storage/delete_disk.rb +19 -16
  101. data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +2 -2
  102. data/lib/fog/azurerm/requests/storage/get_backup_container.rb +2 -2
  103. data/lib/fog/azurerm/requests/storage/get_backup_item.rb +2 -2
  104. data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +1 -1
  105. data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +2 -2
  106. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  107. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  108. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  109. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +37 -35
  110. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  111. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  112. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +16 -12
  113. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  114. data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +2 -2
  115. data/lib/fog/azurerm/requests/storage/get_storage_access_keys.rb +4 -3
  116. data/lib/fog/azurerm/requests/storage/get_storage_account.rb +2 -2
  117. data/lib/fog/azurerm/requests/storage/list_blobs.rb +110 -24
  118. data/lib/fog/azurerm/requests/storage/list_containers.rb +46 -23
  119. data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +2 -2
  120. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +2 -2
  121. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +2 -2
  122. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  123. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  124. data/lib/fog/azurerm/requests/storage/{set_blob_metadata.rb → put_blob_metadata.rb} +7 -3
  125. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  126. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  127. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  128. data/lib/fog/azurerm/requests/storage/{set_container_metadata.rb → put_container_metadata.rb} +7 -3
  129. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +4 -1
  130. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +4 -1
  131. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  132. data/lib/fog/azurerm/requests/storage/start_backup.rb +1 -1
  133. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  134. data/lib/fog/azurerm/resources.rb +2 -2
  135. data/lib/fog/azurerm/storage.rb +33 -19
  136. data/lib/fog/azurerm/traffic_manager.rb +1 -1
  137. data/lib/fog/azurerm/utilities/general.rb +70 -3
  138. data/lib/fog/azurerm/version.rb +1 -1
  139. data/rake-script.sh +5 -2
  140. data/test/api_stub/models/application_gateway/gateway.rb +1 -1
  141. data/test/api_stub/models/compute/server.rb +1 -1
  142. data/test/api_stub/models/dns/record_set.rb +2 -2
  143. data/test/api_stub/models/dns/zone.rb +1 -1
  144. data/test/api_stub/models/network/express_route_circuit.rb +1 -1
  145. data/test/api_stub/models/network/express_route_circuit_authorization.rb +1 -1
  146. data/test/api_stub/models/network/express_route_circuit_peering.rb +1 -1
  147. data/test/api_stub/models/network/express_route_service_provider.rb +1 -1
  148. data/test/api_stub/models/network/load_balancer.rb +1 -1
  149. data/test/api_stub/models/network/network_interface.rb +1 -1
  150. data/test/api_stub/models/network/network_security_group.rb +1 -1
  151. data/test/api_stub/models/network/network_security_rule.rb +1 -1
  152. data/test/api_stub/models/network/public_ip.rb +1 -1
  153. data/test/api_stub/models/network/subnet.rb +1 -1
  154. data/test/api_stub/models/network/virtual_network.rb +1 -1
  155. data/test/api_stub/models/network/virtual_network_gateway.rb +1 -1
  156. data/test/api_stub/models/network/virtual_network_gateway_connection.rb +1 -1
  157. data/test/api_stub/models/resources/resource.rb +2 -2
  158. data/test/api_stub/models/resources/resource_group.rb +1 -1
  159. data/test/api_stub/models/storage/directory.rb +148 -62
  160. data/test/api_stub/models/storage/file.rb +122 -119
  161. data/test/api_stub/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  162. data/test/api_stub/models/traffic_manager/traffic_manager_profile.rb +1 -1
  163. data/test/api_stub/requests/application_gateway/gateway.rb +2 -2
  164. data/test/api_stub/requests/compute/availability_set.rb +3 -3
  165. data/test/api_stub/requests/compute/virtual_machine.rb +9 -9
  166. data/test/api_stub/requests/dns/record_set.rb +3 -3
  167. data/test/api_stub/requests/dns/zone.rb +18 -18
  168. data/test/api_stub/requests/network/express_route_circuit.rb +2 -2
  169. data/test/api_stub/requests/network/express_route_circuit_authorization.rb +1 -1
  170. data/test/api_stub/requests/network/express_route_circuit_peering.rb +2 -2
  171. data/test/api_stub/requests/network/express_route_service_provider.rb +1 -1
  172. data/test/api_stub/requests/network/load_balancer.rb +2 -2
  173. data/test/api_stub/requests/network/network_interface.rb +4 -4
  174. data/test/api_stub/requests/network/network_security_group.rb +3 -3
  175. data/test/api_stub/requests/network/network_security_rule.rb +2 -2
  176. data/test/api_stub/requests/network/public_ip.rb +2 -2
  177. data/test/api_stub/requests/network/subnet.rb +2 -2
  178. data/test/api_stub/requests/network/virtual_network.rb +2 -2
  179. data/test/api_stub/requests/network/virtual_network_gateway.rb +2 -2
  180. data/test/api_stub/requests/network/virtual_network_gateway_connection.rb +3 -3
  181. data/test/api_stub/requests/resources/resource.rb +2 -2
  182. data/test/api_stub/requests/resources/resource_group.rb +2 -2
  183. data/test/api_stub/requests/storage/directory.rb +59 -65
  184. data/test/api_stub/requests/storage/file.rb +183 -113
  185. data/test/api_stub/requests/storage/storageaccount.rb +1 -1
  186. data/test/api_stub/requests/traffic_manager/traffic_manager_endpoint.rb +1 -1
  187. data/test/api_stub/requests/traffic_manager/traffic_manager_profile.rb +2 -2
  188. data/test/integration/Virtual_network_gateway_connection.rb +189 -182
  189. data/test/integration/application_gateway.rb +208 -183
  190. data/test/integration/availability_set.rb +44 -27
  191. data/test/integration/blob.rb +293 -169
  192. data/test/integration/container.rb +93 -42
  193. data/test/integration/data_disk.rb +57 -46
  194. data/test/integration/deployment.rb +40 -32
  195. data/test/integration/express_route_circuit.rb +86 -82
  196. data/test/integration/external_load_balancer.rb +108 -100
  197. data/test/integration/internal_load_balancer.rb +115 -106
  198. data/test/integration/local_network_gateway.rb +46 -39
  199. data/test/integration/network_interface.rb +119 -107
  200. data/test/integration/network_security_group.rb +86 -74
  201. data/test/integration/network_security_rule.rb +65 -57
  202. data/test/integration/public_ip.rb +50 -42
  203. data/test/integration/record_set.rb +90 -78
  204. data/test/integration/resource_group.rb +26 -14
  205. data/test/integration/resource_tag.rb +56 -45
  206. data/test/integration/server.rb +152 -135
  207. data/test/integration/server_custom_image.rb +85 -76
  208. data/test/integration/sql_server.rb +130 -117
  209. data/test/integration/storage_account.rb +82 -70
  210. data/test/integration/subnet.rb +87 -74
  211. data/test/integration/traffic_manager.rb +86 -74
  212. data/test/integration/virtual_machine_extension.rb +115 -106
  213. data/test/integration/virtual_network.rb +121 -100
  214. data/test/integration/virtual_network_gateway.rb +86 -79
  215. data/test/integration/virtual_network_gateway_connection_to_express_route.rb +94 -87
  216. data/test/integration/zone.rb +36 -28
  217. data/test/models/storage/test_directories.rb +26 -71
  218. data/test/models/storage/test_directory.rb +111 -58
  219. data/test/models/storage/test_file.rb +179 -143
  220. data/test/models/storage/test_files.rb +197 -30
  221. data/test/models/storage/test_storage_account.rb +1 -1
  222. data/test/requests/compute/test_attach_data_disk_to_vm.rb +15 -17
  223. data/test/requests/storage/test_acquire_blob_lease.rb +23 -4
  224. data/test/requests/storage/test_acquire_container_lease.rb +24 -5
  225. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  226. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  227. data/test/requests/storage/test_copy_blob.rb +22 -3
  228. data/test/requests/storage/test_copy_blob_from_uri.rb +23 -4
  229. data/test/requests/storage/test_create_block_blob.rb +80 -0
  230. data/test/requests/storage/test_create_container.rb +18 -13
  231. data/test/requests/storage/test_create_disk.rb +57 -4
  232. data/test/requests/storage/test_create_page_blob.rb +34 -0
  233. data/test/requests/storage/test_delete_blob.rb +25 -5
  234. data/test/requests/storage/test_delete_container.rb +21 -9
  235. data/test/requests/storage/test_delete_disk.rb +14 -7
  236. data/test/requests/storage/test_get_blob.rb +141 -0
  237. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  238. data/test/requests/storage/test_get_blob_https_url.rb +30 -0
  239. data/test/requests/storage/test_get_blob_properties.rb +29 -7
  240. data/test/requests/storage/test_get_blob_url.rb +33 -0
  241. data/test/requests/storage/test_get_container_acl.rb +37 -0
  242. data/test/requests/storage/test_get_container_properties.rb +25 -11
  243. data/test/requests/storage/test_get_container_url.rb +33 -0
  244. data/test/requests/storage/test_list_blobs.rb +77 -0
  245. data/test/requests/storage/test_list_containers.rb +38 -7
  246. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  247. data/test/requests/storage/test_put_blob_block.rb +34 -0
  248. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  249. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  250. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  251. data/test/requests/storage/test_put_container_acl.rb +34 -0
  252. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  253. data/test/requests/storage/test_release_blob_lease.rb +20 -2
  254. data/test/requests/storage/test_release_container_lease.rb +21 -3
  255. data/test/requests/storage/test_save_page_blob.rb +115 -0
  256. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  257. data/test/test_helper.rb +34 -21
  258. metadata +92 -46
  259. data/lib/fog/azurerm/requests/storage/check_blob_exist.rb +0 -25
  260. data/lib/fog/azurerm/requests/storage/compare_blob.rb +0 -73
  261. data/lib/fog/azurerm/requests/storage/download_blob_to_file.rb +0 -56
  262. data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +0 -59
  263. data/lib/fog/azurerm/requests/storage/get_container_access_control_list.rb +0 -30
  264. data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +0 -32
  265. data/lib/fog/azurerm/requests/storage/set_blob_properties.rb +0 -26
  266. data/lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb +0 -60
  267. data/test/requests/storage/test_check_blob_exist.rb +0 -17
  268. data/test/requests/storage/test_compare_blob.rb +0 -17
  269. data/test/requests/storage/test_download_blob_to_file.rb +0 -25
  270. data/test/requests/storage/test_get_blob_metadata.rb +0 -18
  271. data/test/requests/storage/test_get_container_access_control_list.rb +0 -31
  272. data/test/requests/storage/test_get_container_metadata.rb +0 -18
  273. data/test/requests/storage/test_list_blobs_in_container.rb +0 -23
  274. data/test/requests/storage/test_set_blob_metadata.rb +0 -17
  275. data/test/requests/storage/test_set_blob_properties.rb +0 -16
  276. data/test/requests/storage/test_set_container_metadata.rb +0 -17
  277. data/test/requests/storage/test_upload_block_blob_from_file.rb +0 -23
@@ -4,146 +4,258 @@ module Fog
4
4
  # This class is giving implementation of create/save and
5
5
  # delete/destroy for Blob.
6
6
  class File < Fog::Model
7
- identity :key, aliases: %w(Name name)
8
- attribute :accept_ranges
9
- attribute :cache_control
10
- attribute :committed_block_count
11
- attribute :content_length
12
- attribute :content_type
13
- attribute :content_md5
14
- attribute :content_encoding
15
- attribute :content_language
16
- attribute :content_disposition
17
- attribute :copy_completion_time
18
- attribute :copy_status
19
- attribute :copy_status_description
20
- attribute :copy_id
21
- attribute :copy_progress
22
- attribute :copy_source
7
+ identity :key, aliases: %w(Name name Key)
8
+
9
+ attr_writer :body
23
10
  attribute :directory
24
- attribute :etag
25
- attribute :file_path
26
- attribute :last_modified
27
- attribute :lease_duration
28
- attribute :lease_state
29
- attribute :lease_status
11
+ attribute :accept_ranges, aliases: %w(Accept-Ranges AcceptRanges)
12
+ attribute :content_length, aliases: %w(Content-Length Size), type: :integer
13
+ attribute :content_type, aliases: %w(Content-Type ContentType)
14
+ attribute :content_md5, aliases: %w(Content-MD5 ContentMD5)
15
+ attribute :content_encoding, aliases: %w(Content-Encoding ContentEncoding)
16
+ attribute :content_language, aliases: %w(Content-Language ContentLanguage)
17
+ attribute :cache_control, aliases: %w(Cache-Control CacheControl)
18
+ attribute :content_disposition, aliases: %w(Content-Disposition ContentDisposition)
19
+ attribute :copy_completion_time, aliases: %w(Copy-Completion-Time CopyCompletionTime)
20
+ attribute :copy_status, aliases: %w(Copy-Status CopyStatus)
21
+ attribute :copy_status_description, aliases: %w(Copy-Status-Description CopyStatusDescription)
22
+ attribute :copy_id, aliases: %w(Copy-Id CopyId)
23
+ attribute :copy_progress, aliases: %w(Copy-Progress CopyProgress)
24
+ attribute :copy_source, aliases: %w(Copy-Source CopySource)
25
+ attribute :etag, aliases: %w(Etag ETag)
26
+ attribute :last_modified, aliases: %w(Last-Modified LastModified), type: 'time'
27
+ attribute :lease_duration, aliases: %w(Lease-Duration LeaseDuration)
28
+ attribute :lease_state, aliases: %w(Lease-State LeaseState)
29
+ attribute :lease_status, aliases: %w(Lease-Status LeaseStatus)
30
+ attribute :sequence_number, aliases: %w(Sequence-Number SequenceNumber)
31
+ attribute :blob_type, aliases: %w(Blob-Type BlobType)
30
32
  attribute :metadata
31
- attribute :sequence_number
32
- attribute :blob_type
33
33
 
34
+ # Save the file to the directory in Azure storage.
35
+ # TODO: Support snapshots.
36
+ #
37
+ # required attributes: body(Only if update_body is true), directory, key
38
+ #
39
+ # @param identity [String] Name of directory
40
+ # @param options [Hash]
41
+ # @option options [Boolean] update_body Sets whether to upload the body of the file. Default is true.
42
+ # Will update metadata and properties when update_body is set to false.
43
+ # @option options [Integer] worker_thread_num Sets how many threads will be used to upload the body. Default is 8.
44
+ # @option options [String] blob_type or
45
+ # Blob-Type Sets blob type for the file. Options: 'BlockBlob' or 'PageBlob'. Default is 'BlockBlob'.
46
+ # @option options [String] content_type or
47
+ # Content-Type Sets content type for the file. For example, 'text/plain'.
48
+ # @option options [String] content_md5 or
49
+ # Content-MD5 Sets content MD5 hash for the file. Only for store.
50
+ # When a block file whose size <= 32 MB, Azure will verify the integrity of the blob during transport.
51
+ # Please reference this issue: https://github.com/Azure/azure-storage-ruby/issues/64
52
+ # @option options [String] content_encoding or
53
+ # Content-Encoding Sets content encoding for the file. For example, 'x-gzip'.
54
+ # @option options [String] content_language or
55
+ # Content-Language Sets the natural languages used by the file.
56
+ # @option options [String] cache_control or
57
+ # Cache-Control Sets content encoding for the file. For example, 'No-cache'.
58
+ # @option options [String] content_disposition or
59
+ # Content-Disposition Sets content disposition for the file. For exampple, 'attachment; filename=testing.txt'.
60
+ # @option options [Hash] metadata Sets custom metadata values to store with the file.
61
+ #
62
+ # @return [Boolean]
63
+ #
34
64
  def save(options = {})
35
- requires :key
36
- requires :directory
37
- merge_attributes(File.parse(service.upload_block_blob_from_file(directory, key, file_path, options)))
65
+ update_body = options.delete(:update_body)
66
+ update_body = true if update_body.nil?
67
+ requires :directory, :key
68
+ raise ArgumentError.new('body is required when update_body is true') if update_body && attributes[:body].nil?
69
+
70
+ remap_attributes(
71
+ options,
72
+ 'Blob-Type' => :blob_type,
73
+ 'Content-Type' => :content_type,
74
+ 'Content-MD5' => :content_md5,
75
+ 'Content-Encoding' => :content_encoding,
76
+ 'Content-Language' => :content_language,
77
+ 'Cache-Control' => :cache_control,
78
+ 'Content-Disposition' => :content_disposition
79
+ )
80
+ options = {
81
+ blob_type: blob_type,
82
+ content_type: content_type,
83
+ content_md5: content_md5,
84
+ content_encoding: content_encoding,
85
+ content_language: content_language,
86
+ cache_control: cache_control,
87
+ content_disposition: content_disposition,
88
+ metadata: metadata
89
+ }.merge!(options)
90
+ options = options.reject { |_key, value| value.nil? || value.to_s.empty? }
91
+
92
+ if update_body
93
+ blob = save_blob(options)
94
+
95
+ data = parse_storage_object(blob)
96
+ merge_attributes(data)
97
+ attributes[:content_length] = Fog::Storage.get_body_size(body)
98
+ attributes[:content_type] ||= Fog::Storage.get_content_type(body)
99
+ else
100
+ service.put_blob_metadata(directory.key, key, options[:metadata]) if options[:metadata]
101
+ options.delete(:metadata)
102
+ service.put_blob_properties(directory.key, key, options)
103
+
104
+ blob = service.get_blob_properties(directory.key, key)
105
+ data = parse_storage_object(blob)
106
+ merge_attributes(data)
107
+ end
108
+
109
+ true
38
110
  end
39
111
 
40
- alias create save
112
+ # Get file's body if exists, else ''.
113
+ #
114
+ # @return [File || String]
115
+ #
116
+ def body
117
+ return attributes[:body] if attributes[:body]
118
+ return '' unless last_modified
41
119
 
42
- def destroy(options = {})
43
- requires :key
44
- requires :directory
45
- service.delete_blob directory, key, options
120
+ file = collection.get(identity)
121
+ if file.nil?
122
+ attributes[:body] = ''
123
+ return ''
124
+ end
125
+
126
+ attributes[:body] = file.body
46
127
  end
47
128
 
48
- def save_to_file(file_path, options = {})
49
- requires :key
50
- requires :directory
51
- merge_attributes(file_path: file_path)
52
- merge_attributes(File.parse(service.download_blob_to_file(directory, key, file_path, options)))
129
+ # Set body attribute.
130
+ #
131
+ # @param new_body [File || String]
132
+ #
133
+ # @return [File || String]
134
+ #
135
+ def body=(new_body)
136
+ attributes[:body] = new_body
53
137
  end
54
138
 
55
- def get_properties(options = {})
56
- requires :key
57
- requires :directory
58
- merge_attributes(File.parse(service.get_blob_properties(directory, key, options)))
139
+ # Copy object from one container to other container.
140
+ #
141
+ # required attributes: directory, key
142
+ #
143
+ # @param target_directory_key [String]
144
+ # @param target_file_key [String]
145
+ # @param options [Hash] options for copy_object method
146
+ # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds.
147
+ #
148
+ # @return [Fog::Storage::AzureRM::File] New File.
149
+ #
150
+ def copy(target_directory_key, target_file_key, options = {})
151
+ requires :directory, :key
152
+
153
+ timeout = options.delete(:timeout)
154
+ copy_id, copy_status = service.copy_blob(target_directory_key, target_file_key, directory.key, key, options)
155
+ service.wait_blob_copy_operation_to_finish(target_directory_key, target_file_key, copy_id, copy_status, timeout)
156
+
157
+ target_directory = service.directories.new(key: target_directory_key)
158
+ target_directory.files.head(target_file_key)
59
159
  end
60
160
 
61
- def set_properties(properties = {})
62
- requires :key
63
- requires :directory
64
- service.set_blob_properties(directory, key, properties)
65
- merge_attributes(properties)
161
+ # Copy object from a uri.
162
+ #
163
+ # required attributes: directory, key
164
+ #
165
+ # @param source_uri [String]
166
+ # @param options [Hash] options for copy_object method
167
+ # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds.
168
+ #
169
+ # @return [Boolean]
170
+ #
171
+ def copy_from_uri(source_uri, options = {})
172
+ requires :directory, :key
173
+
174
+ timeout = options.delete(:timeout)
175
+ copy_id, copy_status = service.copy_blob_from_uri(directory.key, key, source_uri, options)
176
+ service.wait_blob_copy_operation_to_finish(directory.key, key, copy_id, copy_status, timeout)
177
+
178
+ blob = service.get_blob_properties(directory.key, key)
179
+ data = parse_storage_object(blob)
180
+ merge_attributes(data)
181
+
182
+ true
66
183
  end
67
184
 
68
- def get_metadata(options = {})
185
+ # Destroy file.
186
+ #
187
+ # required attributes: directory, key
188
+ #
189
+ # @param options [Hash]
190
+ # @option options versionId []
191
+ #
192
+ # @return [Boolean] true if successful
193
+ #
194
+ def destroy(options = {})
69
195
  requires :key
70
196
  requires :directory
71
- merge_attributes(metadata: service.get_blob_metadata(directory, key, options))
197
+ attributes[:body] = nil
198
+ service.delete_blob(directory.key, key, options)
199
+
200
+ true
72
201
  end
73
202
 
74
- def set_metadata(metadata, options = {})
75
- requires :key
203
+ # Get whether the file can be accessed by anonymous.
204
+ #
205
+ # @return [Boolean]
206
+ #
207
+ def public?
76
208
  requires :directory
77
- service.set_blob_metadata(directory, key, metadata, options)
78
- merge_attributes(metadata: metadata)
209
+
210
+ # TBD: The blob can be accessed if read permision is set in one access policy of the container.
211
+ directory.acl == 'container' || directory.acl == 'blob'
79
212
  end
80
213
 
81
- def self.parse(blob)
82
- if blob.is_a? Hash
83
- parse_hash blob
84
- else
85
- parse_object blob
86
- end
214
+ # Get publicly accessible url.
215
+ #
216
+ # required attributes: directory, key
217
+ #
218
+ # @param options [Hash]
219
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
220
+ #
221
+ # @return [String] A public url.
222
+ #
223
+ def public_url(options = {})
224
+ requires :directory, :key
225
+ options[:scheme] == 'https' if options[:scheme].nil?
226
+ @service.get_blob_url(directory.key, key, options) if public?
87
227
  end
88
228
 
89
- def self.parse_hash(blob)
90
- hash = {}
91
- hash['key'] = blob['name']
92
- hash['metadata'] = blob['metadata']
93
- return hash unless blob.key?('properties')
94
-
95
- hash['last_modified'] = blob['properties']['last_modified']
96
- hash['etag'] = blob['properties']['etag']
97
- hash['lease_duration'] = blob['properties']['lease_duration']
98
- hash['lease_status'] = blob['properties']['lease_status']
99
- hash['lease_state'] = blob['properties']['lease_state']
100
- hash['content_length'] = blob['properties']['content_length']
101
- hash['content_type'] = blob['properties']['content_type']
102
- hash['content_encoding'] = blob['properties']['content_encoding']
103
- hash['content_language'] = blob['properties']['content_language']
104
- hash['content_disposition'] = blob['properties']['content_disposition']
105
- hash['content_md5'] = blob['properties']['content_md5']
106
- hash['cache_control'] = blob['properties']['cache_control']
107
- hash['sequence_number'] = blob['properties']['sequence_number']
108
- hash['blob_type'] = blob['properties']['blob_type']
109
- hash['copy_id'] = blob['properties']['copy_id']
110
- hash['copy_status'] = blob['properties']['copy_status']
111
- hash['copy_source'] = blob['properties']['copy_source']
112
- hash['copy_progress'] = blob['properties']['copy_progress']
113
- hash['copy_completion_time'] = blob['properties']['copy_completion_time']
114
- hash['copy_status_description'] = blob['properties']['copy_status_description']
115
- hash['accept_ranges'] = blob['properties']['accept_ranges']
116
- hash
229
+ # Get a url for file.
230
+ #
231
+ # required attributes: key
232
+ #
233
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
234
+ # @param options [Hash]
235
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
236
+ #
237
+ # @return [String] A public url which will expire after the specified time.
238
+ #
239
+ def url(expires, options = {})
240
+ requires :key
241
+ collection.get_url(key, expires, options)
117
242
  end
118
243
 
119
- def self.parse_object(blob)
120
- hash = {}
121
- hash['key'] = blob.name
122
- hash['metadata'] = blob.metadata
123
- return hash unless blob.respond_to?('properties')
124
-
125
- hash['last_modified'] = blob.properties[:last_modified]
126
- hash['etag'] = blob.properties[:etag]
127
- hash['lease_duration'] = blob.properties[:lease_duration]
128
- hash['lease_status'] = blob.properties[:lease_status]
129
- hash['lease_state'] = blob.properties[:lease_state]
130
- hash['content_length'] = blob.properties[:content_length]
131
- hash['content_type'] = blob.properties[:content_type]
132
- hash['content_encoding'] = blob.properties[:content_encoding]
133
- hash['content_language'] = blob.properties[:content_language]
134
- hash['content_disposition'] = blob.properties[:content_disposition]
135
- hash['content_md5'] = blob.properties[:content_md5]
136
- hash['cache_control'] = blob.properties[:cache_control]
137
- hash['sequence_number'] = blob.properties[:sequence_number]
138
- hash['blob_type'] = blob.properties[:blob_type]
139
- hash['copy_id'] = blob.properties[:copy_id]
140
- hash['copy_status'] = blob.properties[:copy_status]
141
- hash['copy_source'] = blob.properties[:copy_source]
142
- hash['copy_progress'] = blob.properties[:copy_progress]
143
- hash['copy_completion_time'] = blob.properties[:copy_completion_time]
144
- hash['copy_status_description'] = blob.properties[:copy_status_description]
145
- hash['accept_ranges'] = blob.properties[:accept_ranges]
146
- hash
244
+ private
245
+
246
+ # Upload blob
247
+ def save_blob(options)
248
+ if options[:blob_type].nil? || options[:blob_type] == 'BlockBlob'
249
+ if Fog::Storage.get_body_size(body) <= SINGLE_BLOB_PUT_THRESHOLD
250
+ service.create_block_blob(directory.key, key, body, options)
251
+ else
252
+ service.multipart_save_block_blob(directory.key, key, body, options)
253
+ service.get_blob_properties(directory.key, key)
254
+ end
255
+ else
256
+ service.save_page_blob(directory.key, key, body, options)
257
+ service.get_blob_properties(directory.key, key)
258
+ end
147
259
  end
148
260
  end
149
261
  end
@@ -3,24 +3,179 @@ module Fog
3
3
  class AzureRM
4
4
  # This class is giving implementation of listing blobs.
5
5
  class Files < Fog::Collection
6
- model File
7
6
  attribute :directory
7
+ attribute :delimiter, aliases: 'Delimiter'
8
+ attribute :marker, aliases: 'Marker'
9
+ attribute :max_results, aliases: %w(max-results MaxResults max_keys MaxKeys max-keys)
10
+ attribute :next_marker, aliases: %w(NextMarker next-marker)
11
+ attribute :prefix, aliases: 'Prefix'
8
12
 
9
- def all(options = { metadata: true })
10
- files = []
11
- service.list_blobs(directory, options).each do |blob|
12
- hash = File.parse blob
13
- hash['directory'] = directory
14
- files << hash
13
+ model Fog::Storage::AzureRM::File
14
+
15
+ # List all files(blobs) under the directory.
16
+ #
17
+ # required attributes: directory
18
+ #
19
+ # @param options [Hash]
20
+ # @option options [String] max_keys or
21
+ # max_results Sets the maximum number of files to return.
22
+ # @option options [String] delimiter Sets to cause that the operation returns a BlobPrefix element in the response body that acts
23
+ # as a placeholder for all files whose names begin with the same substring up to the appearance
24
+ # of the delimiter character. The delimiter may be a single character or a string.
25
+ # @option options [String] marker Sets the identifier that specifies the portion of the list to be returned.
26
+ # @option options [String] prefix Sets filters the results to return only files whose name begins with the specified prefix.
27
+ #
28
+ # @return [Fog::Storage::AzureRM::Files] Return nil if the directory does not exist.
29
+ #
30
+ def all(options = {})
31
+ requires :directory
32
+
33
+ options = {
34
+ max_results: max_results,
35
+ delimiter: delimiter,
36
+ marker: marker,
37
+ prefix: prefix
38
+ }.merge!(options)
39
+ options = options.reject { |_key, value| value.nil? || value.to_s.empty? }
40
+ merge_attributes(options)
41
+ parent = directory.collection.get(
42
+ directory.key,
43
+ options
44
+ )
45
+ return nil unless parent
46
+
47
+ merge_attributes(parent.files.attributes)
48
+ load(parent.files.map(&:attributes))
49
+ end
50
+
51
+ # Enumerate every file under the directory if block_given?
52
+ #
53
+ # @return [Fog::Storage::AzureRM::Files]
54
+ #
55
+ alias each_file_this_page each
56
+ def each
57
+ if block_given?
58
+ subset = dup.all
59
+
60
+ subset.each_file_this_page { |f| yield f }
61
+ while subset.next_marker
62
+ subset = subset.all(marker: subset.next_marker)
63
+ subset.each_file_this_page { |f| yield f }
64
+ end
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ # Get the file(blob) with full content as :body with the given name.
71
+ #
72
+ # required attributes: directory
73
+ #
74
+ # @param key [String] Name of file
75
+ # @param options [Hash]
76
+ # @option options [String] block_size Sets buffer size when block_given? is true. Default is 32 MB
77
+ #
78
+ # @return [Fog::Storage::AzureRM::File] A file. Return nil if the file does not exist.
79
+ #
80
+ def get(key, options = {}, &block)
81
+ requires :directory
82
+
83
+ blob, content = service.get_blob(directory.key, key, options, &block)
84
+ data = parse_storage_object(blob)
85
+ file_data = data.merge(
86
+ body: content,
87
+ key: key
88
+ )
89
+ new(file_data)
90
+ rescue => error
91
+ return nil if error.message == 'NotFound'
92
+ raise error
93
+ end
94
+
95
+ # Get the URL of the file(blob) with the given name.
96
+ #
97
+ # required attributes: directory
98
+ #
99
+ # @param key [String] Name of file
100
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
101
+ # @param options [Hash]
102
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
103
+ #
104
+ # @return [String] A URL.
105
+ #
106
+ def get_url(key, expires, options = {})
107
+ requires :directory
108
+
109
+ if options[:scheme] == 'http'
110
+ get_http_url(key, expires, options)
111
+ else
112
+ get_https_url(key, expires, options)
15
113
  end
16
- load files
17
114
  end
18
115
 
19
- def get(directory, name)
20
- file = File.new(service: service)
21
- file.directory = directory
22
- file.key = name
23
- file
116
+ # Get the http URL of the file(blob) with the given name.
117
+ #
118
+ # required attributes: directory
119
+ #
120
+ # @param key [String] Name of file
121
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
122
+ # @param options [Hash] Unused. To keep same interface as other providers.
123
+ #
124
+ # @return [String] A http URL.
125
+ #
126
+ def get_http_url(key, expires, _options = {})
127
+ requires :directory
128
+
129
+ service.get_blob_http_url(directory.key, key, expires)
130
+ end
131
+
132
+ # Get the https URL of the file(blob) with the given name.
133
+ #
134
+ # required attributes: directory
135
+ #
136
+ # @param key [String] Name of file
137
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
138
+ # @param options [Hash] Unused. To keep same interface as other providers.
139
+ #
140
+ # @return [String] A https URL.
141
+ #
142
+ def get_https_url(key, expires, _options = {})
143
+ requires :directory
144
+
145
+ service.get_blob_https_url(directory.key, key, expires)
146
+ end
147
+
148
+ # Get the file(blob) without content with the given name.
149
+ #
150
+ # required attributes: directory
151
+ #
152
+ # @param key [String] Name of file
153
+ # @param options [Hash]
154
+ #
155
+ # @return [Fog::Storage::AzureRM::File] A file. Return nil if the file does not exist.
156
+ #
157
+ def head(key, options = {})
158
+ requires :directory
159
+
160
+ blob = service.get_blob_properties(directory.key, key, options)
161
+ data = parse_storage_object(blob)
162
+ file_data = data.merge(key: key)
163
+ new(file_data)
164
+ rescue => error
165
+ return nil if error.message == 'NotFound'
166
+ raise error
167
+ end
168
+
169
+ # Create a new file.
170
+ #
171
+ # required attributes: directory
172
+ #
173
+ # @return [Fog::Storage::AzureRM::File] A file. You need to use File.save to upload this new file.
174
+ #
175
+ def new(attributes = {})
176
+ requires :directory
177
+
178
+ super({ directory: directory }.merge!(attributes))
24
179
  end
25
180
  end
26
181
  end