gitlab-fog-azure-rm 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/.arclint +8 -0
  3. data/.codeclimate.yml +17 -0
  4. data/.gitignore +6 -0
  5. data/.gitlab-ci.yml +17 -0
  6. data/.hound.yml +2 -0
  7. data/.rubocop.yml +5 -0
  8. data/.rubocop_todo.yml +274 -0
  9. data/.travis.yml +49 -0
  10. data/CHANGELOG.md +414 -0
  11. data/CONTRIBUTING.md +40 -0
  12. data/CONTRIBUTORS.md +12 -0
  13. data/Gemfile +3 -0
  14. data/LICENSE.md +20 -0
  15. data/README.md +100 -0
  16. data/gitlab-fog-azure-rm.gemspec +31 -0
  17. data/lib/fog/azurerm.rb +30 -0
  18. data/lib/fog/azurerm/async_response.rb +44 -0
  19. data/lib/fog/azurerm/config.rb +1 -0
  20. data/lib/fog/azurerm/constants.rb +72 -0
  21. data/lib/fog/azurerm/credentials.rb +40 -0
  22. data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
  23. data/lib/fog/azurerm/docs/storage.md +398 -0
  24. data/lib/fog/azurerm/docs/structure.md +53 -0
  25. data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
  26. data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
  27. data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
  28. data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
  29. data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
  30. data/lib/fog/azurerm/models/resources/provider.rb +27 -0
  31. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
  32. data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
  33. data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
  34. data/lib/fog/azurerm/models/storage/directories.rb +75 -0
  35. data/lib/fog/azurerm/models/storage/directory.rb +151 -0
  36. data/lib/fog/azurerm/models/storage/file.rb +265 -0
  37. data/lib/fog/azurerm/models/storage/files.rb +183 -0
  38. data/lib/fog/azurerm/models/storage/kind.rb +12 -0
  39. data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
  40. data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
  41. data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
  42. data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
  43. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
  44. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
  45. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
  46. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  47. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  48. data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
  49. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
  50. data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
  51. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  52. data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
  53. data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
  54. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  55. data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
  56. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
  57. data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
  58. data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
  59. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
  60. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  61. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  62. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  63. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
  64. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  65. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  66. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
  67. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  68. data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
  69. data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
  70. data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
  71. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  72. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  73. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
  74. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
  75. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  76. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  77. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  78. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
  79. data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
  80. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
  81. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
  82. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  83. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  84. data/lib/fog/azurerm/storage.rb +126 -0
  85. data/lib/fog/azurerm/utilities/general.rb +186 -0
  86. data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
  87. data/lib/fog/azurerm/version.rb +5 -0
  88. data/rake-script.sh +10 -0
  89. data/rakefile +29 -0
  90. data/test/api_stub.rb +147 -0
  91. data/test/api_stub/models/storage/directory.rb +178 -0
  92. data/test/api_stub/models/storage/file.rb +181 -0
  93. data/test/api_stub/requests/storage/directory.rb +89 -0
  94. data/test/api_stub/requests/storage/file.rb +252 -0
  95. data/test/integration/README.md +14 -0
  96. data/test/integration/blob.rb +297 -0
  97. data/test/integration/container.rb +160 -0
  98. data/test/integration/credentials/azure.yml +5 -0
  99. data/test/integration/storage_account.rb +135 -0
  100. data/test/models/storage/test_directories.rb +74 -0
  101. data/test/models/storage/test_directory.rb +178 -0
  102. data/test/models/storage/test_file.rb +294 -0
  103. data/test/models/storage/test_files.rb +234 -0
  104. data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
  105. data/test/requests/storage/test_acquire_container_lease.rb +36 -0
  106. data/test/requests/storage/test_check_container_exists.rb +18 -0
  107. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  108. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  109. data/test/requests/storage/test_copy_blob.rb +39 -0
  110. data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
  111. data/test/requests/storage/test_create_block_blob.rb +80 -0
  112. data/test/requests/storage/test_create_container.rb +36 -0
  113. data/test/requests/storage/test_create_disk.rb +70 -0
  114. data/test/requests/storage/test_create_page_blob.rb +34 -0
  115. data/test/requests/storage/test_delete_blob.rb +42 -0
  116. data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
  117. data/test/requests/storage/test_delete_container.rb +42 -0
  118. data/test/requests/storage/test_delete_disk.rb +30 -0
  119. data/test/requests/storage/test_get_blob.rb +141 -0
  120. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  121. data/test/requests/storage/test_get_blob_https_url.rb +32 -0
  122. data/test/requests/storage/test_get_blob_properties.rb +47 -0
  123. data/test/requests/storage/test_get_blob_url.rb +75 -0
  124. data/test/requests/storage/test_get_container_acl.rb +37 -0
  125. data/test/requests/storage/test_get_container_properties.rb +45 -0
  126. data/test/requests/storage/test_get_container_url.rb +33 -0
  127. data/test/requests/storage/test_list_blobs.rb +77 -0
  128. data/test/requests/storage/test_list_containers.rb +54 -0
  129. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  130. data/test/requests/storage/test_put_blob_block.rb +34 -0
  131. data/test/requests/storage/test_put_blob_https_url.rb +32 -0
  132. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  133. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  134. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  135. data/test/requests/storage/test_put_container_acl.rb +34 -0
  136. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  137. data/test/requests/storage/test_release_blob_lease.rb +34 -0
  138. data/test/requests/storage/test_release_container_lease.rb +34 -0
  139. data/test/requests/storage/test_save_page_blob.rb +115 -0
  140. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  141. data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
  142. data/test/test_credentials.rb +63 -0
  143. data/test/test_helper.rb +846 -0
  144. metadata +352 -0
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ # Get a public blob url from Azure blob storage
7
+ # This is to make this library compatible with CarrierWave.
8
+ def get_object_url(container_name, blob_name, expires)
9
+ get_blob_https_url(container_name, blob_name, expires)
10
+ end
11
+ end
12
+
13
+ # This class provides the mock implementation for unit tests.
14
+ class Mock
15
+ def get_object_url(container_name, blob_name, expires)
16
+ get_blob_https_url(container_name, blob_name, expires)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,168 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ # https://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
6
+ class Real
7
+ def list_blobs(container_name, options = {})
8
+ options = options.dup
9
+ options[:metadata] = true
10
+ next_marker = nil
11
+ blobs = []
12
+
13
+ msg = nil
14
+
15
+ max_results = -1
16
+ max_results = options[:max_results].to_i if options[:max_results]
17
+ begin
18
+ loop do
19
+ options[:request_id] = SecureRandom.uuid
20
+ msg = "Listing blobs in container: #{container_name}, options: #{options}"
21
+ Fog::Logger.debug msg
22
+ temp = @blob_client.list_blobs(container_name, options)
23
+ # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
24
+ raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
25
+
26
+ blobs += temp unless temp.empty?
27
+ break if temp.continuation_token.nil? || temp.continuation_token.empty?
28
+ options[:marker] = temp.continuation_token
29
+
30
+ next if max_results == -1
31
+
32
+ options[:max_results] = max_results - blobs.size
33
+ if options[:max_results].zero?
34
+ next_marker = temp.continuation_token
35
+ break
36
+ end
37
+ end
38
+ rescue Azure::Core::Http::HTTPError => ex
39
+ raise 'NotFound' if ex.message.include?('(404)')
40
+ raise_azure_exception(ex, msg)
41
+ end
42
+
43
+ Fog::Logger.debug "Listing blobs in container: #{container_name} successfully."
44
+ {
45
+ next_marker: next_marker,
46
+ blobs: blobs
47
+ }
48
+ end
49
+ end
50
+
51
+ # This class provides the mock implementation for unit tests.
52
+ class Mock
53
+ def list_blobs(*)
54
+ Fog::Logger.debug 'Listing blobs in container successfully.'
55
+ {
56
+ next_marker: 'marker',
57
+ blobs: [
58
+ {
59
+ 'name' => 'test_blob1',
60
+ 'metadata' => {},
61
+ 'properties' => {
62
+ 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
63
+ 'etag' => '0x8D3A3B5F017F52D',
64
+ 'lease_status' => 'unlocked',
65
+ 'lease_state' => 'available',
66
+ 'content_length' => 4_194_304,
67
+ 'content_type' => 'application/octet-stream',
68
+ 'content_encoding' => nil,
69
+ 'content_language' => nil,
70
+ 'content_disposition' => nil,
71
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
72
+ 'cache_control' => nil,
73
+ 'sequence_number' => 0,
74
+ 'blob_type' => 'PageBlob',
75
+ 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c',
76
+ 'copy_status' => 'success',
77
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z',
78
+ 'copy_progress' => '4194304/4194304',
79
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT',
80
+ 'copy_status_description' => nil,
81
+ 'accept_ranges' => 0
82
+ }
83
+ },
84
+ {
85
+ 'name' => 'test_blob2',
86
+ 'metadata' => {},
87
+ 'properties' => {
88
+ 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
89
+ 'etag' => '0x8D29C92173526C8',
90
+ 'lease_status' => 'unlocked',
91
+ 'lease_state' => 'available',
92
+ 'content_length' => 4_194_304,
93
+ 'content_type' => 'application/octet-stream',
94
+ 'content_encoding' => nil,
95
+ 'content_language' => nil,
96
+ 'content_disposition' => nil,
97
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
98
+ 'cache_control' => nil,
99
+ 'sequence_number' => 0,
100
+ 'blob_type' => 'PageBlob',
101
+ 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
102
+ 'copy_status' => 'success',
103
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
104
+ 'copy_progress' => '4194304/4194304',
105
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
106
+ 'copy_status_description' => nil,
107
+ 'accept_ranges' => 0
108
+ }
109
+ },
110
+ {
111
+ 'name' => 'test_blob3',
112
+ 'metadata' => {},
113
+ 'properties' => {
114
+ 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
115
+ 'etag' => '0x8D29C92173526C8',
116
+ 'lease_status' => 'unlocked',
117
+ 'lease_state' => 'available',
118
+ 'content_length' => 4_194_304,
119
+ 'content_type' => 'application/octet-stream',
120
+ 'content_encoding' => nil,
121
+ 'content_language' => nil,
122
+ 'content_disposition' => nil,
123
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
124
+ 'cache_control' => nil,
125
+ 'sequence_number' => 0,
126
+ 'blob_type' => 'PageBlob',
127
+ 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
128
+ 'copy_status' => 'success',
129
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
130
+ 'copy_progress' => '4194304/4194304',
131
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
132
+ 'copy_status_description' => nil,
133
+ 'accept_ranges' => 0
134
+ }
135
+ },
136
+ {
137
+ 'name' => 'test_blob4',
138
+ 'metadata' => {},
139
+ 'properties' => {
140
+ 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
141
+ 'etag' => '0x8D29C92173526C8',
142
+ 'lease_status' => 'unlocked',
143
+ 'lease_state' => 'available',
144
+ 'content_length' => 4_194_304,
145
+ 'content_type' => 'application/octet-stream',
146
+ 'content_encoding' => nil,
147
+ 'content_language' => nil,
148
+ 'content_disposition' => nil,
149
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
150
+ 'cache_control' => nil,
151
+ 'sequence_number' => 0,
152
+ 'blob_type' => 'PageBlob',
153
+ 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
154
+ 'copy_status' => 'success',
155
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
156
+ 'copy_progress' => '4194304/4194304',
157
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
158
+ 'copy_status_description' => nil,
159
+ 'accept_ranges' => 0
160
+ }
161
+ }
162
+ ]
163
+ }
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,73 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ # https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx
6
+ class Real
7
+ def list_containers
8
+ options = { metadata: true }
9
+ containers = []
10
+ msg = nil
11
+
12
+ begin
13
+ loop do
14
+ options[:request_id] = SecureRandom.uuid
15
+ msg = "Listing containers. options: #{options}"
16
+ Fog::Logger.debug msg
17
+ temp = @blob_client.list_containers(options)
18
+ # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
19
+ raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
20
+
21
+ containers += temp unless temp.empty?
22
+ break if temp.continuation_token.nil? || temp.continuation_token.empty?
23
+ options[:marker] = temp.continuation_token
24
+ end
25
+ rescue Azure::Core::Http::HTTPError => ex
26
+ raise_azure_exception(ex, msg)
27
+ end
28
+
29
+ Fog::Logger.debug 'Listing containers successfully.'
30
+ containers
31
+ end
32
+ end
33
+
34
+ # This class provides the mock implementation for unit tests.
35
+ class Mock
36
+ def list_containers
37
+ [
38
+ {
39
+ 'name' => 'test_container1',
40
+ 'metadata' => {},
41
+ 'properties' => {
42
+ 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
43
+ 'etag' => '0x8D3A3B5F017F52D',
44
+ 'lease_status' => 'unlocked',
45
+ 'lease_state' => 'available'
46
+ }
47
+ },
48
+ {
49
+ 'name' => 'test_container2',
50
+ 'metadata' => {},
51
+ 'properties' => {
52
+ 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT',
53
+ 'etag' => '0x8D29C92176C8352',
54
+ 'lease_status' => 'unlocked',
55
+ 'lease_state' => 'available'
56
+ }
57
+ },
58
+ {
59
+ 'name' => 'test_container3',
60
+ 'metadata' => {},
61
+ 'properties' => {
62
+ 'last_modified' => 'Tue, 01 Sep 2015 05:15:36 GMT',
63
+ 'etag' => '0x8D2B28C5EB36458',
64
+ 'lease_status' => 'unlocked',
65
+ 'lease_state' => 'available'
66
+ }
67
+ }
68
+ ]
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,110 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ # This class is used to store chunk data for block blob before uploading.
7
+ class BlockChunk
8
+ attr_reader :id # For debug
9
+ attr_reader :block_id
10
+ attr_reader :data
11
+
12
+ def initialize(id, block_id, data)
13
+ @id = id
14
+ @block_id = block_id
15
+ @data = data
16
+ end
17
+ end
18
+
19
+ # This class is a stream to read chunk data.
20
+ class BlockFileStream
21
+ attr_reader :blocks
22
+
23
+ def initialize(body)
24
+ if body.respond_to?(:read)
25
+ if body.respond_to?(:rewind)
26
+ begin
27
+ body.rewind
28
+ rescue => ex
29
+ Fog::Logger.debug "multipart_save_block_blob - body responds to :rewind but throws an exception when calling :rewind: #{ex.inspect}"
30
+ end
31
+ end
32
+ @stream = body
33
+ else
34
+ @stream = StringIO.new(body)
35
+ end
36
+ @mutex = Mutex.new
37
+ @blocks = []
38
+ end
39
+
40
+ def read(size)
41
+ block_id = Base64.strict_encode64(random_string(32))
42
+ data = nil
43
+ id = 0
44
+ @mutex.synchronize do
45
+ data = @stream.read(size)
46
+ return nil if data.nil?
47
+ @blocks << [block_id]
48
+ id = @blocks.size
49
+ end
50
+ BlockChunk.new(id, block_id, data)
51
+ end
52
+ end
53
+
54
+ def multipart_save_block_blob(container_name, blob_name, body, options)
55
+ threads_num = options.delete(:worker_thread_num)
56
+ threads_num = UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1
57
+
58
+ begin
59
+ # Initiate the upload
60
+ Fog::Logger.debug "Creating the block blob #{container_name}/#{blob_name}. options: #{options}"
61
+ content_md5 = options.delete(:content_md5)
62
+ create_block_blob(container_name, blob_name, nil, options)
63
+
64
+ # Uploading parts
65
+ Fog::Logger.debug "Starting to upload parts for the block blob #{container_name}/#{blob_name}."
66
+ iostream = BlockFileStream.new(body)
67
+
68
+ threads = []
69
+ threads_num.times do |id|
70
+ thread = Thread.new do
71
+ Fog::Logger.debug "Created upload thread #{id}."
72
+ while (chunk = iostream.read(MAXIMUM_CHUNK_SIZE))
73
+ Fog::Logger.debug "Upload thread #{id} is uploading #{chunk.id}, size: #{chunk.data.size}, options: #{options}."
74
+ put_blob_block(container_name, blob_name, chunk.block_id, chunk.data, options)
75
+ end
76
+ Fog::Logger.debug "Upload thread #{id} finished."
77
+ end
78
+ thread.abort_on_exception = true
79
+ threads << thread
80
+ end
81
+
82
+ threads.each(&:join)
83
+ # Complete the upload
84
+ options[:content_md5] = content_md5 unless content_md5.nil?
85
+ Fog::Logger.debug "Commiting the block blob #{container_name}/#{blob_name}. options: #{options}"
86
+ commit_blob_blocks(container_name, blob_name, iostream.blocks, options)
87
+ rescue
88
+ # Abort the upload & reraise
89
+ begin
90
+ delete_blob(container_name, blob_name)
91
+ rescue => ex
92
+ Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after multipart_save_block_blob failed. #{ex.inspect}"
93
+ end
94
+ raise
95
+ end
96
+
97
+ Fog::Logger.debug "Successfully save the block blob: #{container_name}/#{blob_name}."
98
+ true
99
+ end
100
+ end
101
+
102
+ # This class provides the mock implementation for unit tests.
103
+ class Mock
104
+ def multipart_save_block_blob(*)
105
+ true
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ def put_blob_block(container_name, blob_name, block_id, data, options = {})
7
+ options[:request_id] = SecureRandom.uuid
8
+ msg = "put_blob_block block_id: #{block_id} / #{blob_name} to the container #{container_name}. options: #{options}"
9
+ Fog::Logger.debug msg
10
+
11
+ begin
12
+ @blob_client.put_blob_block(container_name, blob_name, block_id, data, options)
13
+ rescue Azure::Core::Http::HTTPError => ex
14
+ raise_azure_exception(ex, msg)
15
+ end
16
+
17
+ Fog::Logger.debug "block_id #{block_id} is uploaded successfully."
18
+ true
19
+ end
20
+ end
21
+
22
+ # This class provides the mock implementation.
23
+ class Mock
24
+ def put_blob_block(*)
25
+ true
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ # Generate a pre-signed URL for create an object in an Azure blob storage
7
+ #
8
+ # @param container_name [String] Name of container containing blob
9
+ # @param blob_name [String] Name of blob to get expiring url for
10
+ # @param expires [Time] An expiry time for this url
11
+ #
12
+ # @return [String] - https url for blob
13
+ #
14
+ # @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob
15
+ #
16
+ def put_blob_https_url(container_name, blob_name, expires)
17
+ relative_path = "#{container_name}/#{blob_name}"
18
+ params = {
19
+ service: 'b',
20
+ resource: 'b',
21
+ permissions: 'c',
22
+ expiry: expires.utc.iso8601,
23
+ protocol: 'https'
24
+ }
25
+ token = @signature_client.generate_service_sas_token(relative_path, params)
26
+ uri = @blob_client.generate_uri(relative_path)
27
+ "#{uri}?#{token}"
28
+ end
29
+ end
30
+
31
+ # This class provides the mock implementation for unit tests.
32
+ class Mock
33
+ def put_blob_https_url(*)
34
+ 'https://sa.blob.core.windows.net/test_container/test_blob?token'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ def put_blob_metadata(container_name, name, metadata, options = {})
7
+ options[:request_id] = SecureRandom.uuid
8
+ msg = "Setting Blob #{name} metadata in a container #{container_name}. options: #{options}"
9
+ Fog::Logger.debug msg
10
+
11
+ begin
12
+ @blob_client.set_blob_metadata(container_name, name, metadata, options)
13
+ rescue Azure::Core::Http::HTTPError => ex
14
+ raise_azure_exception(ex, msg)
15
+ end
16
+
17
+ Fog::Logger.debug "Setting metadata of blob #{name} successfully."
18
+ true
19
+ end
20
+ end
21
+
22
+ # This class provides the mock implementation for unit tests.
23
+ class Mock
24
+ def put_blob_metadata(container_name, name, metadata, _options = {})
25
+ Fog::Logger.debug "Set Blob #{name} metadata #{metadata} in a container #{container_name} successfully."
26
+ true
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end