gitlab-fog-azure-rm 0.6.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +0 -3
- data/CHANGELOG.md +34 -0
- data/gitlab-fog-azure-rm.gemspec +6 -6
- data/lib/fog/azurerm/docs/storage.md +0 -147
- data/lib/fog/azurerm/models/storage/file.rb +1 -6
- data/lib/fog/azurerm/requests/storage/create_block_blob.rb +3 -31
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +1 -1
- data/lib/fog/azurerm/requests/storage/list_containers.rb +1 -1
- data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +1 -1
- data/lib/fog/azurerm/storage.rb +21 -16
- data/lib/fog/azurerm/utilities/general.rb +5 -0
- data/lib/fog/azurerm/version.rb +1 -1
- data/rakefile +2 -0
- data/test/models/storage/test_file.rb +2 -4
- data/test/requests/storage/test_create_block_blob.rb +0 -9
- data/test/requests/storage/test_get_blob_https_url.rb +16 -0
- data/test/requests/storage/test_list_blobs.rb +2 -2
- data/test/requests/storage/test_list_containers.rb +2 -2
- data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +1 -1
- data/test/test_helper.rb +8 -0
- metadata +21 -27
- data/lib/fog/azurerm/requests/storage/create_disk.rb +0 -62
- data/lib/fog/azurerm/requests/storage/delete_disk.rb +0 -36
- data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +0 -110
- data/test/requests/storage/test_create_disk.rb +0 -70
- data/test/requests/storage/test_delete_disk.rb +0 -30
- data/test/requests/storage/test_multipart_save_block_blob.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 177b1f767e814e126cce9905dc11bd5b4384daaafb7292ae379a9f05c435b4ea
|
4
|
+
data.tar.gz: 19d21cd53ffd3a246e195009c4f709df9e4e955ae5c2dace73e4436f82f5ac4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa5d061efb46aee21a8c74d949f7ba5c1632019ccda79799cfe70775f40b6a3448d0f4c01fc12b0c82863419c74a673a68992ca9582317a1df45c42d3ffd5dad
|
7
|
+
data.tar.gz: 8d45eb802da36f53c8aa7a67a49f609de9e39be351af967237166da94c52bda5e474cbb7633200f18bc9386341591d8880df9cda8cd7e5a055beb6f0ad09e13c
|
data/.rubocop_todo.yml
CHANGED
@@ -43,7 +43,6 @@ Layout/EndOfLine:
|
|
43
43
|
Layout/HashAlignment:
|
44
44
|
Exclude:
|
45
45
|
- 'lib/fog/azurerm/models/storage/file.rb'
|
46
|
-
- 'lib/fog/azurerm/requests/storage/create_disk.rb'
|
47
46
|
- 'test/test_helper.rb'
|
48
47
|
|
49
48
|
# Offense count: 1
|
@@ -133,7 +132,6 @@ Naming/RescuedExceptionsVariableName:
|
|
133
132
|
# SupportedStyles: separated, grouped
|
134
133
|
Style/AccessorGrouping:
|
135
134
|
Exclude:
|
136
|
-
- 'lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb'
|
137
135
|
- 'lib/fog/azurerm/requests/storage/save_page_blob.rb'
|
138
136
|
- 'test/test_helper.rb'
|
139
137
|
|
@@ -227,7 +225,6 @@ Style/RescueStandardError:
|
|
227
225
|
Exclude:
|
228
226
|
- 'lib/fog/azurerm/models/storage/files.rb'
|
229
227
|
- 'lib/fog/azurerm/requests/storage/create_block_blob.rb'
|
230
|
-
- 'lib/fog/azurerm/requests/storage/create_disk.rb'
|
231
228
|
- 'lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb'
|
232
229
|
- 'lib/fog/azurerm/requests/storage/save_page_blob.rb'
|
233
230
|
- 'lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
- Fix multipart uploads not working and drop multipart_save_block_blob !19
|
6
|
+
|
7
|
+
## 0.9.0
|
8
|
+
|
9
|
+
- Fix TimeoutError deprecation !17
|
10
|
+
- Update Azure storage libraries !16
|
11
|
+
|
12
|
+
## 0.8.1
|
13
|
+
|
14
|
+
- Fix `azure_storage_domain` not getting propagated properly !14
|
15
|
+
|
16
|
+
## 0.8.0
|
17
|
+
|
18
|
+
- Add `azure_storage_domain` for specifying custom domain !11
|
19
|
+
|
20
|
+
## 0.7.0
|
21
|
+
|
22
|
+
- Loosen mime-types version dependency !9
|
23
|
+
- Drop azure_mgmt_storage and other dependencies !8
|
24
|
+
|
25
|
+
## 0.6.0
|
26
|
+
|
27
|
+
- Fix get_object_url !7
|
28
|
+
- Add get_object_url method !6
|
29
|
+
- Add support for copy_object !5
|
30
|
+
- Add support for DELETE blob !4
|
31
|
+
- Add support for PUT blobs !3
|
32
|
+
- Add and update Rubocop files !2
|
33
|
+
- Delete all code except blob storage-related functionality !1
|
34
|
+
|
1
35
|
## 0.5.2
|
2
36
|
|
3
37
|
**Added**
|
data/gitlab-fog-azure-rm.gemspec
CHANGED
@@ -19,13 +19,13 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.post_install_message = 'Thanks for installing!'
|
20
20
|
spec.add_development_dependency 'codeclimate-test-reporter' , '~> 1.0.0'
|
21
21
|
spec.add_development_dependency 'minitest', '~> 5.8.4'
|
22
|
-
spec.add_development_dependency 'rake', '~>
|
23
|
-
spec.add_development_dependency 'rubocop', '~> 0.89'
|
22
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
23
|
+
spec.add_development_dependency 'rubocop', '~> 0.89.1'
|
24
24
|
spec.add_development_dependency 'simplecov'
|
25
|
-
spec.add_dependency '
|
26
|
-
spec.add_dependency 'azure-storage', '~>
|
25
|
+
spec.add_dependency 'azure-storage-blob', '~> 2.0'
|
26
|
+
spec.add_dependency 'azure-storage-common', '~> 2.0'
|
27
27
|
spec.add_dependency 'fog-core', '= 2.1.0'
|
28
28
|
spec.add_dependency 'fog-json', '~> 1.2.0'
|
29
|
-
spec.add_dependency 'mime-types'
|
30
|
-
spec.add_dependency '
|
29
|
+
spec.add_dependency 'mime-types'
|
30
|
+
spec.add_dependency 'ms_rest_azure', '~> 0.12.0'
|
31
31
|
end
|
@@ -12,32 +12,6 @@ require 'fog/azurerm'
|
|
12
12
|
|
13
13
|
## Create Connection
|
14
14
|
|
15
|
-
Next, create a connection to the Storage Service:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
fog_storage_service = Fog::Storage::AzureRM.new(
|
19
|
-
tenant_id: '<Tenant Id>', # Tenant Id of Azure Active Directory Application
|
20
|
-
client_id: '<Client Id>', # Client Id of Azure Active Directory Application
|
21
|
-
client_secret: '<Client Secret>', # Client Secret of Azure Active Directory Application
|
22
|
-
subscription_id: '<Subscription Id>', # Subscription Id of an Azure Account
|
23
|
-
azure_storage_account_name: '<Storage Account Name>', # Name of an Azure Storage Account
|
24
|
-
azure_storage_access_key: '<Storage Account Key>', # Key of an Azure Storage Account
|
25
|
-
environment: '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
|
26
|
-
)
|
27
|
-
```
|
28
|
-
|
29
|
-
If you only want to manage the storage accounts, you can create the connection without the storage account information:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
fog_storage_service = Fog::Storage::AzureRM.new(
|
33
|
-
tenant_id: '<Tenant Id>', # Tenant Id of Azure Active Directory Application
|
34
|
-
client_id: '<Client Id>', # Client Id of Azure Active Directory Application
|
35
|
-
client_secret: '<Client Secret>', # Client Secret of Azure Active Directory Application
|
36
|
-
subscription_id: '<Subscription Id>', # Subscription Id of an Azure Account
|
37
|
-
environment: '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
|
38
|
-
)
|
39
|
-
```
|
40
|
-
|
41
15
|
If you only want to manage the storage data, you can create the connection without the Azure subscription information:
|
42
16
|
|
43
17
|
```ruby
|
@@ -48,127 +22,6 @@ fog_storage_service = Fog::Storage::AzureRM.new(
|
|
48
22
|
)
|
49
23
|
```
|
50
24
|
|
51
|
-
## Check Name Availability
|
52
|
-
|
53
|
-
This operation checks that account name is valid and is not already in use. _Storage Account Type_ is an optional parameter
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
fog_storage_service.storage_accounts.check_name_availability('<Storage Account Name>', '<Storage Account Type>')
|
57
|
-
```
|
58
|
-
|
59
|
-
## Check Storage Account Existence
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
fog_storage_service.storage_accounts.check_storage_account_exists('<Resource Group Name>', '<Storage Account Name>')
|
63
|
-
```
|
64
|
-
|
65
|
-
## Create Storage Account
|
66
|
-
|
67
|
-
Create a new storage account. Replication attribute for Standard and Premium account types are as follows
|
68
|
-
|
69
|
-
##### Standard
|
70
|
-
|
71
|
-
1. LRS (Standard Locally-redundant storage)
|
72
|
-
2. ZRS (Standard Zone-redundant storage)
|
73
|
-
3. GRS (Standard Geo-redundant storage)
|
74
|
-
4. RAGRS (Standard Read access geo-redundant storage)
|
75
|
-
|
76
|
-
##### Premium
|
77
|
-
1. LRS (Premium Locally-redundant storage)
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
fog_storage_service.storage_accounts.create(
|
81
|
-
name: '<Storage Account name>',
|
82
|
-
location: '<Location>',
|
83
|
-
resource_group: '<Resource Group Name>',
|
84
|
-
account_type: '<Standard/Premium>', # [Optional] Default value 'Standard'. Allowed values can only be Standard or Premium
|
85
|
-
replication: '<Replication Type>', # [Optional] Default value 'LRS'
|
86
|
-
encryption: <True/False>, # [Optional] Enables encryption. Default is false.
|
87
|
-
tags: { key1: 'value1', key2: 'value2', keyN: 'valueN' } # [Optional]
|
88
|
-
)
|
89
|
-
```
|
90
|
-
Premium Storage account store data on solid state drives (SSDs). For more details on standard and premium storage accounts, see [Introduction to Microsoft Azure Storage](https://azure.microsoft.com/en-us/documentation/articles/storage-introduction/) and [Premium Storage: High-Performance Storage for Azure Virtual Machine Workloads](https://azure.microsoft.com/en-us/documentation/articles/storage-premium-storage/).
|
91
|
-
|
92
|
-
## List storage accounts
|
93
|
-
|
94
|
-
##### List storage accounts in a subscription
|
95
|
-
|
96
|
-
```ruby
|
97
|
-
fog_storage_service.storage_accounts.each do |storage_acc|
|
98
|
-
puts "#{storage_acc.name}"
|
99
|
-
puts "#{storage_acc.location}"
|
100
|
-
end
|
101
|
-
```
|
102
|
-
##### List storage accounts in a resource group
|
103
|
-
|
104
|
-
```ruby
|
105
|
-
storage_accounts = fog_storage_service.storage_accounts(resource_group: '<Resource Group Name>')
|
106
|
-
storage_accounts.each do |storage_acc|
|
107
|
-
puts "#{storage_acc.name}"
|
108
|
-
puts "#{storage_acc.location}"
|
109
|
-
end
|
110
|
-
```
|
111
|
-
|
112
|
-
## Retrieve a single Storage Account
|
113
|
-
|
114
|
-
Get a single record of Storage Account
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
storage_acc = fog_storage_service
|
118
|
-
.storage_accounts
|
119
|
-
.get('<Resource Group Name>', '<Storage Account Name>')
|
120
|
-
puts "#{storage_acc.name}"
|
121
|
-
```
|
122
|
-
|
123
|
-
## Enable encryption on Storage Account
|
124
|
-
|
125
|
-
Get a single record of Storage Account and enable encryption on that Storage Account
|
126
|
-
|
127
|
-
```ruby
|
128
|
-
storage_acc = fog_storage_service
|
129
|
-
.storage_accounts
|
130
|
-
.get('<Resource Group Name>', '<Storage Account Name>')
|
131
|
-
|
132
|
-
storage_acc.update(encryption: true)
|
133
|
-
```
|
134
|
-
|
135
|
-
## Get Access Keys
|
136
|
-
|
137
|
-
Get access keys of a storage account
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
keys_hash = storage_acc.get_access_keys
|
141
|
-
keys_hash.each do |keys|
|
142
|
-
puts "#{keys.key_name}: #{keys.value}"
|
143
|
-
end
|
144
|
-
```
|
145
|
-
|
146
|
-
## Destroy a single Storage Account
|
147
|
-
|
148
|
-
Get storage account object from the get method and then destroy that storage account.
|
149
|
-
|
150
|
-
```ruby
|
151
|
-
storage_acc.destroy
|
152
|
-
```
|
153
|
-
|
154
|
-
## Create a Disk
|
155
|
-
|
156
|
-
Create a Disk in storage account. _disk_size_in_gb_ must be an integer and the range is [1, 1023].
|
157
|
-
By default the disk will be created in the container 'vhds'. You can specify other container by set options[:container_name].
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
fog_storage_service.create_disk('<Data Disk Name>', disk_size_in_gb, options = {})
|
161
|
-
```
|
162
|
-
|
163
|
-
## Delete a Disk
|
164
|
-
|
165
|
-
Delete a Disk from a storage account. Disk must be in unlocked state i.e detached from server (virtual machine) to successfully perform this action.
|
166
|
-
By default the disk will be deleted from the container 'vhds'. You can specify other container by set options[:container_name].
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
fog_storage_service.delete_disk('<Data Disk Name>', options = {})
|
170
|
-
```
|
171
|
-
|
172
25
|
## Check Storage Container Existence
|
173
26
|
|
174
27
|
```ruby
|
@@ -248,12 +248,7 @@ module Fog
|
|
248
248
|
# Upload blob
|
249
249
|
def save_blob(options)
|
250
250
|
if options[:blob_type].nil? || options[:blob_type] == 'BlockBlob'
|
251
|
-
|
252
|
-
service.create_block_blob(directory.key, key, body, options)
|
253
|
-
else
|
254
|
-
service.multipart_save_block_blob(directory.key, key, body, options)
|
255
|
-
service.get_blob_properties(directory.key, key)
|
256
|
-
end
|
251
|
+
service.create_block_blob(directory.key, key, body, options)
|
257
252
|
else
|
258
253
|
service.save_page_blob(directory.key, key, body, options)
|
259
254
|
service.get_blob_properties(directory.key, key)
|
@@ -8,37 +8,9 @@ module Fog
|
|
8
8
|
msg = "create_block_blob #{blob_name} to the container #{container_name}. options: #{options}"
|
9
9
|
Fog::Logger.debug msg
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
elsif body.respond_to?(:read)
|
15
|
-
if body.respond_to?(:rewind)
|
16
|
-
begin
|
17
|
-
body.rewind
|
18
|
-
rescue
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
data = body.read
|
23
|
-
else
|
24
|
-
data = Fog::Storage.parse_data(body)
|
25
|
-
options[:content_length] = data[:headers]['Content-Length']
|
26
|
-
options[:content_type] = data[:headers]['Content-Type']
|
27
|
-
data = data[:body]
|
28
|
-
end
|
29
|
-
|
30
|
-
raise ArgumentError.new('The maximum size for a block blob created via create_block_blob is 64 MB.') if !data.nil? && Fog::Storage.get_body_size(data) > 64 * 1024 * 1024
|
31
|
-
blob = @blob_client.create_block_blob(container_name, blob_name, data, options)
|
32
|
-
rescue Azure::Core::Http::HTTPError => ex
|
33
|
-
raise_azure_exception(ex, msg)
|
34
|
-
end
|
35
|
-
|
36
|
-
if data.nil?
|
37
|
-
Fog::Logger.debug "Create a block blob #{blob_name} successfully."
|
38
|
-
else
|
39
|
-
Fog::Logger.debug "Upload a block blob #{blob_name} successfully."
|
40
|
-
end
|
41
|
-
blob
|
11
|
+
@blob_client.create_block_blob(container_name, blob_name, body, options)
|
12
|
+
rescue Azure::Core::Http::HTTPError => ex
|
13
|
+
raise_azure_exception(ex, msg)
|
42
14
|
end
|
43
15
|
end
|
44
16
|
|
@@ -21,7 +21,7 @@ module Fog
|
|
21
21
|
Fog::Logger.debug msg
|
22
22
|
temp = @blob_client.list_blobs(container_name, options)
|
23
23
|
# Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
|
24
|
-
raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
|
24
|
+
raise temp unless temp.instance_of?(Azure::Storage::Common::Service::EnumerationResults)
|
25
25
|
|
26
26
|
blobs += temp unless temp.empty?
|
27
27
|
break if temp.continuation_token.nil? || temp.continuation_token.empty?
|
@@ -16,7 +16,7 @@ module Fog
|
|
16
16
|
Fog::Logger.debug msg
|
17
17
|
temp = @blob_client.list_containers(options)
|
18
18
|
# Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
|
19
|
-
raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
|
19
|
+
raise temp unless temp.instance_of?(Azure::Storage::Common::Service::EnumerationResults)
|
20
20
|
|
21
21
|
containers += temp unless temp.empty?
|
22
22
|
break if temp.continuation_token.nil? || temp.continuation_token.empty?
|
@@ -18,7 +18,7 @@ module Fog
|
|
18
18
|
break if copy_status != COPY_STATUS[:PENDING]
|
19
19
|
|
20
20
|
elapse_time = Time.new - start_time
|
21
|
-
raise
|
21
|
+
raise Timeout::Error.new("The copy operation cannot be finished in #{timeout} seconds") if !timeout.nil? && elapse_time >= timeout
|
22
22
|
|
23
23
|
copied_bytes, total_bytes = blob_props[:copy_progress].split('/').map(&:to_i)
|
24
24
|
interval = copied_bytes.zero? ? 5 : (total_bytes - copied_bytes).to_f / copied_bytes * elapse_time
|
data/lib/fog/azurerm/storage.rb
CHANGED
@@ -12,12 +12,11 @@ module Fog
|
|
12
12
|
# Recognizes when creating data client
|
13
13
|
recognizes :azure_storage_account_name
|
14
14
|
recognizes :azure_storage_access_key
|
15
|
+
recognizes :azure_storage_domain
|
16
|
+
|
15
17
|
recognizes :debug
|
16
18
|
|
17
19
|
request_path 'fog/azurerm/requests/storage'
|
18
|
-
# Azure Storage Disk requests
|
19
|
-
request :delete_disk
|
20
|
-
request :create_disk
|
21
20
|
# Azure Storage Container requests
|
22
21
|
request :create_container
|
23
22
|
request :release_container_lease
|
@@ -58,7 +57,6 @@ module Fog
|
|
58
57
|
request :put_blob_pages
|
59
58
|
request :wait_blob_copy_operation_to_finish
|
60
59
|
request :save_page_blob
|
61
|
-
request :multipart_save_block_blob
|
62
60
|
|
63
61
|
model_path 'fog/azurerm/models/storage'
|
64
62
|
model :directory
|
@@ -70,8 +68,8 @@ module Fog
|
|
70
68
|
class Mock
|
71
69
|
def initialize(_options = {})
|
72
70
|
begin
|
73
|
-
require '
|
74
|
-
require 'azure/storage'
|
71
|
+
require 'azure/storage/common'
|
72
|
+
require 'azure/storage/blob'
|
75
73
|
rescue LoadError => e
|
76
74
|
retry if require('rubygems')
|
77
75
|
raise e.message
|
@@ -83,10 +81,9 @@ module Fog
|
|
83
81
|
class Real
|
84
82
|
def initialize(options)
|
85
83
|
begin
|
86
|
-
require '
|
87
|
-
require 'azure/storage'
|
84
|
+
require 'azure/storage/common'
|
85
|
+
require 'azure/storage/blob'
|
88
86
|
require 'securerandom'
|
89
|
-
require 'vhd'
|
90
87
|
@debug = ENV['DEBUG'] || options[:debug]
|
91
88
|
require 'azure/core/http/debug_filter' if @debug
|
92
89
|
rescue LoadError => e
|
@@ -110,15 +107,23 @@ module Fog
|
|
110
107
|
|
111
108
|
@azure_storage_account_name = options[:azure_storage_account_name]
|
112
109
|
@azure_storage_access_key = options[:azure_storage_access_key]
|
110
|
+
@azure_storage_domain = options[:azure_storage_domain]
|
111
|
+
|
112
|
+
domain =
|
113
|
+
if @azure_storage_domain.nil? || @azure_storage_domain.empty?
|
114
|
+
get_blob_endpoint(@azure_storage_account_name, true, @environment)
|
115
|
+
else
|
116
|
+
get_blob_endpoint_with_domain(@azure_storage_account_name, true, @azure_storage_domain)
|
117
|
+
end
|
113
118
|
|
114
|
-
azure_client = Azure::Storage::Client.create(storage_account_name: @azure_storage_account_name,
|
115
|
-
|
116
|
-
|
117
|
-
@blob_client = azure_client
|
118
|
-
@blob_client.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)
|
119
|
+
azure_client = Azure::Storage::Common::Client.create(storage_account_name: @azure_storage_account_name,
|
120
|
+
storage_access_key: @azure_storage_access_key,
|
121
|
+
storage_blob_host: domain)
|
122
|
+
@blob_client = Azure::Storage::Blob::BlobService.new(client: azure_client)
|
123
|
+
@blob_client.with_filter(Azure::Storage::Common::Core::Filter::ExponentialRetryPolicyFilter.new)
|
119
124
|
@blob_client.with_filter(Azure::Core::Http::DebugFilter.new) if @debug
|
120
|
-
@signature_client = Azure::Storage::Core::Auth::SharedAccessSignature.new(@azure_storage_account_name,
|
121
|
-
|
125
|
+
@signature_client = Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(@azure_storage_account_name,
|
126
|
+
@azure_storage_access_key)
|
122
127
|
end
|
123
128
|
end
|
124
129
|
end
|
@@ -125,6 +125,11 @@ def get_blob_endpoint(storage_account_name, enable_https = false, environment =
|
|
125
125
|
"#{protocol}://#{storage_account_name}.blob#{storage_endpoint_suffix(environment)}"
|
126
126
|
end
|
127
127
|
|
128
|
+
def get_blob_endpoint_with_domain(storage_account_name, enable_https = false, domain = 'blob.core.windows.net')
|
129
|
+
protocol = enable_https ? 'https' : 'http'
|
130
|
+
"#{protocol}://#{storage_account_name}.#{domain}"
|
131
|
+
end
|
132
|
+
|
128
133
|
def current_time
|
129
134
|
time = Time.now.to_f.to_s
|
130
135
|
time.split(/\W+/).join
|
data/lib/fog/azurerm/version.rb
CHANGED
data/rakefile
CHANGED
@@ -76,10 +76,8 @@ class TestFile < Minitest::Test
|
|
76
76
|
def test_save_method_with_large_block_blob_success
|
77
77
|
@file.body = 'd' * (32 * 1024 * 1024 + 1) # SINGLE_BLOB_PUT_THRESHOLD is 32 * 1024 * 1024
|
78
78
|
|
79
|
-
@service.stub :
|
80
|
-
@
|
81
|
-
assert @file.save
|
82
|
-
end
|
79
|
+
@service.stub :create_block_blob, @raw_cloud_blob do
|
80
|
+
assert @file.save
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
@@ -52,15 +52,6 @@ class TestCreateBlockBlob < Minitest::Test
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def test_create_block_blob_exceed_max_body_size
|
56
|
-
data = []
|
57
|
-
data.stub :size, 64 * 1024 * 1024 + 1 do
|
58
|
-
assert_raises(ArgumentError) do
|
59
|
-
@service.create_block_blob('test_container', 'test_blob', data)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
55
|
def test_create_block_blob_http_exception
|
65
56
|
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
66
57
|
@blob_client.stub :create_block_blob, http_exception do
|
@@ -25,6 +25,22 @@ class TestGetBlobHttpsUrl < Minitest::Test
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_get_blob_https_url_with_domain_success
|
29
|
+
service = Fog::Storage::AzureRM.new(storage_account_credentials_with_domain)
|
30
|
+
blob_client = service.instance_variable_get(:@blob_client)
|
31
|
+
signature_client = service.instance_variable_get(:@signature_client)
|
32
|
+
|
33
|
+
url = 'https://mockaccount.test.example.com/test_container/test_blob'
|
34
|
+
token = ApiStub::Requests::Storage::File.blob_url_token
|
35
|
+
|
36
|
+
blob_client.stub :generate_uri, url do
|
37
|
+
signature_client.stub :generate_service_sas_token, token do
|
38
|
+
assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
39
|
+
assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
def test_get_blob_https_url_mock
|
29
45
|
assert_equal "#{@url}?#{@token}", @mock_service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
30
46
|
assert_equal "#{@url}?#{@token}", @mock_service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
@@ -13,11 +13,11 @@ class TestListBlobs < Minitest::Test
|
|
13
13
|
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
14
|
|
15
15
|
@blob_list = ApiStub::Requests::Storage::File.blob_list
|
16
|
-
@blobs1 = Azure::Service::EnumerationResults.new
|
16
|
+
@blobs1 = Azure::Storage::Common::Service::EnumerationResults.new
|
17
17
|
@blobs1.continuation_token = 'marker'
|
18
18
|
@blobs1.push(@blob_list[0])
|
19
19
|
@blobs1.push(@blob_list[1])
|
20
|
-
@blobs2 = Azure::Service::EnumerationResults.new
|
20
|
+
@blobs2 = Azure::Storage::Common::Service::EnumerationResults.new
|
21
21
|
@blobs2.push(@blob_list[2])
|
22
22
|
@blobs2.push(@blob_list[3])
|
23
23
|
end
|
@@ -13,11 +13,11 @@ class TestListContainers < Minitest::Test
|
|
13
13
|
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
14
|
|
15
15
|
@containers = ApiStub::Requests::Storage::Directory.container_list
|
16
|
-
@containers1 = Azure::Service::EnumerationResults.new
|
16
|
+
@containers1 = Azure::Storage::Common::Service::EnumerationResults.new
|
17
17
|
@containers1.continuation_token = 'marker'
|
18
18
|
@containers1.push(@containers[0])
|
19
19
|
@containers1.push(@containers[1])
|
20
|
-
@containers2 = Azure::Service::EnumerationResults.new
|
20
|
+
@containers2 = Azure::Storage::Common::Service::EnumerationResults.new
|
21
21
|
@containers2.push(@containers[2])
|
22
22
|
end
|
23
23
|
|
@@ -106,7 +106,7 @@ class TestWaitBlobCopyOperationToFinish < Minitest::Test
|
|
106
106
|
|
107
107
|
@service.stub :get_blob_properties, multiple_values do
|
108
108
|
@service.stub :delete_blob, true do
|
109
|
-
assert_raises(
|
109
|
+
assert_raises(Timeout::Error) do
|
110
110
|
@service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status, 2)
|
111
111
|
end
|
112
112
|
end
|
data/test/test_helper.rb
CHANGED
@@ -36,6 +36,14 @@ def storage_account_credentials
|
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
39
|
+
def storage_account_credentials_with_domain
|
40
|
+
storage_account_credentials.merge(
|
41
|
+
{
|
42
|
+
azure_storage_domain: 'test.example.com'
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
39
47
|
# Mock Class for Blob
|
40
48
|
class MockBlob
|
41
49
|
def initialize
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-fog-azure-rm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaffan Chaudhry
|
@@ -18,7 +18,7 @@ authors:
|
|
18
18
|
autorequire:
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
|
-
date: 2020-
|
21
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: codeclimate-test-reporter
|
@@ -54,28 +54,28 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
57
|
+
version: '13.0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
60
|
version_requirements: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - "~>"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '13.0'
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: rubocop
|
67
67
|
requirement: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - "~>"
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: 0.89.1
|
72
72
|
type: :development
|
73
73
|
prerelease: false
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - "~>"
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 0.89.1
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
80
|
name: simplecov
|
81
81
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,33 +91,33 @@ dependencies:
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: azure-storage-blob
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: '0
|
99
|
+
version: '2.0'
|
100
100
|
type: :runtime
|
101
101
|
prerelease: false
|
102
102
|
version_requirements: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '0
|
106
|
+
version: '2.0'
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
|
-
name: azure-storage
|
108
|
+
name: azure-storage-common
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: '2.0'
|
114
114
|
type: :runtime
|
115
115
|
prerelease: false
|
116
116
|
version_requirements: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - "~>"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
120
|
+
version: '2.0'
|
121
121
|
- !ruby/object:Gem::Dependency
|
122
122
|
name: fog-core
|
123
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,30 +150,30 @@ dependencies:
|
|
150
150
|
name: mime-types
|
151
151
|
requirement: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- - "
|
153
|
+
- - ">="
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
155
|
+
version: '0'
|
156
156
|
type: :runtime
|
157
157
|
prerelease: false
|
158
158
|
version_requirements: !ruby/object:Gem::Requirement
|
159
159
|
requirements:
|
160
|
-
- - "
|
160
|
+
- - ">="
|
161
161
|
- !ruby/object:Gem::Version
|
162
|
-
version:
|
162
|
+
version: '0'
|
163
163
|
- !ruby/object:Gem::Dependency
|
164
|
-
name:
|
164
|
+
name: ms_rest_azure
|
165
165
|
requirement: !ruby/object:Gem::Requirement
|
166
166
|
requirements:
|
167
|
-
- -
|
167
|
+
- - "~>"
|
168
168
|
- !ruby/object:Gem::Version
|
169
|
-
version: 0.0
|
169
|
+
version: 0.12.0
|
170
170
|
type: :runtime
|
171
171
|
prerelease: false
|
172
172
|
version_requirements: !ruby/object:Gem::Requirement
|
173
173
|
requirements:
|
174
|
-
- -
|
174
|
+
- - "~>"
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
version: 0.0
|
176
|
+
version: 0.12.0
|
177
177
|
description: This is a stripped-down fork of fog-azure-rm that enables Azure Blob
|
178
178
|
Storage to be used with CarrierWave and Fog.
|
179
179
|
email:
|
@@ -233,12 +233,10 @@ files:
|
|
233
233
|
- lib/fog/azurerm/requests/storage/copy_object.rb
|
234
234
|
- lib/fog/azurerm/requests/storage/create_block_blob.rb
|
235
235
|
- lib/fog/azurerm/requests/storage/create_container.rb
|
236
|
-
- lib/fog/azurerm/requests/storage/create_disk.rb
|
237
236
|
- lib/fog/azurerm/requests/storage/create_page_blob.rb
|
238
237
|
- lib/fog/azurerm/requests/storage/delete_blob.rb
|
239
238
|
- lib/fog/azurerm/requests/storage/delete_blob_https_url.rb
|
240
239
|
- lib/fog/azurerm/requests/storage/delete_container.rb
|
241
|
-
- lib/fog/azurerm/requests/storage/delete_disk.rb
|
242
240
|
- lib/fog/azurerm/requests/storage/delete_object_url.rb
|
243
241
|
- lib/fog/azurerm/requests/storage/get_blob.rb
|
244
242
|
- lib/fog/azurerm/requests/storage/get_blob_http_url.rb
|
@@ -251,7 +249,6 @@ files:
|
|
251
249
|
- lib/fog/azurerm/requests/storage/get_object_url.rb
|
252
250
|
- lib/fog/azurerm/requests/storage/list_blobs.rb
|
253
251
|
- lib/fog/azurerm/requests/storage/list_containers.rb
|
254
|
-
- lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb
|
255
252
|
- lib/fog/azurerm/requests/storage/put_blob_block.rb
|
256
253
|
- lib/fog/azurerm/requests/storage/put_blob_https_url.rb
|
257
254
|
- lib/fog/azurerm/requests/storage/put_blob_metadata.rb
|
@@ -293,12 +290,10 @@ files:
|
|
293
290
|
- test/requests/storage/test_copy_blob_from_uri.rb
|
294
291
|
- test/requests/storage/test_create_block_blob.rb
|
295
292
|
- test/requests/storage/test_create_container.rb
|
296
|
-
- test/requests/storage/test_create_disk.rb
|
297
293
|
- test/requests/storage/test_create_page_blob.rb
|
298
294
|
- test/requests/storage/test_delete_blob.rb
|
299
295
|
- test/requests/storage/test_delete_blob_https_url.rb
|
300
296
|
- test/requests/storage/test_delete_container.rb
|
301
|
-
- test/requests/storage/test_delete_disk.rb
|
302
297
|
- test/requests/storage/test_get_blob.rb
|
303
298
|
- test/requests/storage/test_get_blob_http_url.rb
|
304
299
|
- test/requests/storage/test_get_blob_https_url.rb
|
@@ -309,7 +304,6 @@ files:
|
|
309
304
|
- test/requests/storage/test_get_container_url.rb
|
310
305
|
- test/requests/storage/test_list_blobs.rb
|
311
306
|
- test/requests/storage/test_list_containers.rb
|
312
|
-
- test/requests/storage/test_multipart_save_block_blob.rb
|
313
307
|
- test/requests/storage/test_put_blob_block.rb
|
314
308
|
- test/requests/storage/test_put_blob_https_url.rb
|
315
309
|
- test/requests/storage/test_put_blob_metadata.rb
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Fog
|
2
|
-
module Storage
|
3
|
-
class AzureRM
|
4
|
-
# This class provides the actual implementation for service calls.
|
5
|
-
class Real
|
6
|
-
# Create a disk in Azure storage.
|
7
|
-
#
|
8
|
-
# @param disk_name [String] Name of disk
|
9
|
-
# @param disk_size_in_gb [Integer] Disk size in GiB. Value range: [1, 1023]
|
10
|
-
# @param options [Hash]
|
11
|
-
# @option options [String] container_name Sets name of the container which contains the disk. Default is 'vhds'.
|
12
|
-
#
|
13
|
-
# @return [Boolean]
|
14
|
-
#
|
15
|
-
def create_disk(disk_name, disk_size_in_gb, options = {})
|
16
|
-
msg = "Creating disk(#{disk_name}, #{disk_size_in_gb}). options: #{options}"
|
17
|
-
Fog::Logger.debug msg
|
18
|
-
|
19
|
-
raise ArgumentError, "disk_size_in_gb #{disk_size_in_gb} must be an integer" unless disk_size_in_gb.is_a?(Integer)
|
20
|
-
raise ArgumentError, "Azure minimum disk size is 1 GiB: #{disk_size_in_gb}" if disk_size_in_gb < 1
|
21
|
-
raise ArgumentError, "Azure maximum disk size is 1023 GiB: #{disk_size_in_gb}" if disk_size_in_gb > 1023
|
22
|
-
|
23
|
-
container_name = options.delete(:container_name)
|
24
|
-
container_name = 'vhds' if container_name.nil?
|
25
|
-
blob_name = "#{disk_name}.vhd"
|
26
|
-
vhd_size = disk_size_in_gb * 1024 * 1024 * 1024
|
27
|
-
blob_size = vhd_size + 512
|
28
|
-
|
29
|
-
opts = {
|
30
|
-
type: :fixed,
|
31
|
-
name: '/tmp/footer.vhd', # Only used to initialize vhd, no local file is generated.
|
32
|
-
size: disk_size_in_gb
|
33
|
-
}
|
34
|
-
vhd_footer = Vhd::Library.new(opts).footer.values.join
|
35
|
-
|
36
|
-
begin
|
37
|
-
create_page_blob(container_name, blob_name, blob_size, options)
|
38
|
-
put_blob_pages(container_name, blob_name, vhd_size, blob_size - 1, vhd_footer, options)
|
39
|
-
rescue
|
40
|
-
begin
|
41
|
-
delete_blob(container_name, blob_name)
|
42
|
-
rescue => ex
|
43
|
-
Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after create_disk failed. #{ex.inspect}"
|
44
|
-
end
|
45
|
-
raise
|
46
|
-
end
|
47
|
-
|
48
|
-
Fog::Logger.debug "Created a disk #{disk_name} successfully."
|
49
|
-
true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# This class provides the mock implementation for unit tests.
|
54
|
-
class Mock
|
55
|
-
def create_disk(*)
|
56
|
-
Fog::Logger.debug 'Disk created successfully.'
|
57
|
-
true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Fog
|
2
|
-
module Storage
|
3
|
-
class AzureRM
|
4
|
-
# This class provides the actual implementation for service calls.
|
5
|
-
class Real
|
6
|
-
# Delete a disk in Azure storage.
|
7
|
-
#
|
8
|
-
# @param disk_name [String] Name of disk
|
9
|
-
# @param options [Hash]
|
10
|
-
# @option options [String] container_name Sets name of the container which contains the disk. Default is 'vhds'.
|
11
|
-
#
|
12
|
-
# @return [Boolean]
|
13
|
-
#
|
14
|
-
def delete_disk(disk_name, options = {})
|
15
|
-
msg = "Deleting disk(#{disk_name}). options: #{options}"
|
16
|
-
Fog::Logger.debug msg
|
17
|
-
|
18
|
-
container_name = options.delete(:container_name)
|
19
|
-
container_name = 'vhds' if container_name.nil?
|
20
|
-
delete_blob(container_name, "#{disk_name}.vhd")
|
21
|
-
|
22
|
-
Fog::Logger.debug "Successfully deleted Disk: #{disk_name}."
|
23
|
-
true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# This class provides the mock implementation for unit tests.
|
28
|
-
class Mock
|
29
|
-
def delete_disk(*)
|
30
|
-
Fog::Logger.debug 'Successfully deleted Disk'
|
31
|
-
true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,110 +0,0 @@
|
|
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
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.expand_path '../../test_helper', __dir__
|
2
|
-
|
3
|
-
# Storage Data Disk Class
|
4
|
-
class TestCreateDisk < Minitest::Test
|
5
|
-
# This class posesses the test cases for the request of create disk.
|
6
|
-
def setup
|
7
|
-
Fog.mock!
|
8
|
-
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
-
Fog.unmock!
|
10
|
-
@mocked_response = mocked_storage_http_error
|
11
|
-
|
12
|
-
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_create_disk_success
|
16
|
-
@service.stub :create_page_blob, true do
|
17
|
-
@service.stub :put_blob_pages, true do
|
18
|
-
assert @service.create_disk('test_disk', 10)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_create_disk_in_another_container_success
|
24
|
-
@service.stub :create_page_blob, true do
|
25
|
-
@service.stub :put_blob_pages, true do
|
26
|
-
assert @service.create_disk('test_disk', 10, container_name: 'test_container')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_create_disk_with_invalid_size_exception
|
32
|
-
assert_raises(ArgumentError) do
|
33
|
-
@service.create_disk('test_disk', 'invalid_size')
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_raises(ArgumentError) do
|
37
|
-
@service.create_disk('test_disk', 0)
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_raises(ArgumentError) do
|
41
|
-
@service.create_disk('test_disk', 1024)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_create_disk_http_exception
|
46
|
-
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
47
|
-
@service.stub :create_page_blob, http_exception do
|
48
|
-
@service.stub :delete_blob, true do
|
49
|
-
assert_raises(Azure::Core::Http::HTTPError) do
|
50
|
-
@service.create_disk('test_disk', 10, container_name: 'test_container')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_create_disk_fail_when_delete_blob_http_exception
|
57
|
-
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
58
|
-
@service.stub :create_page_blob, http_exception do
|
59
|
-
@service.stub :delete_blob, http_exception do
|
60
|
-
assert_raises(Azure::Core::Http::HTTPError) do
|
61
|
-
@service.create_disk('test_disk', 10, container_name: 'test_container')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_create_disk_mock
|
68
|
-
assert @mock_service.create_disk('test_disk')
|
69
|
-
end
|
70
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path '../../test_helper', __dir__
|
2
|
-
|
3
|
-
# Storage Data Disk Class
|
4
|
-
class TestDeleteDisk < Minitest::Test
|
5
|
-
# This class posesses the test cases for the requests of deleting data disks.
|
6
|
-
def setup
|
7
|
-
Fog.mock!
|
8
|
-
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
-
Fog.unmock!
|
10
|
-
@mocked_response = mocked_storage_http_error
|
11
|
-
|
12
|
-
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_delete_disk_success
|
16
|
-
@service.stub :delete_blob, true do
|
17
|
-
assert @service.delete_disk('test_disk')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_delete_disk_in_another_container_success
|
22
|
-
@service.stub :delete_blob, true do
|
23
|
-
assert @service.delete_disk('test_disk', container_name: 'test_container')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_delete_disk_mock
|
28
|
-
assert @mock_service.delete_disk('test_disk')
|
29
|
-
end
|
30
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require File.expand_path '../../test_helper', __dir__
|
2
|
-
|
3
|
-
# Storage Blob Class
|
4
|
-
class TestMultipartSaveBlockBlob < Minitest::Test
|
5
|
-
# This class posesses the test cases for the requests of saving storage block blob with multiple parts.
|
6
|
-
def setup
|
7
|
-
Fog.mock!
|
8
|
-
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
-
Fog.unmock!
|
10
|
-
@mocked_response = mocked_storage_http_error
|
11
|
-
|
12
|
-
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_multipart_save_block_blob_success
|
16
|
-
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
17
|
-
|
18
|
-
@service.stub :create_block_blob, true do
|
19
|
-
@service.stub :put_blob_block, true do
|
20
|
-
@service.stub :commit_blob_blocks, true do
|
21
|
-
assert @service.multipart_save_block_blob('test_container', 'test_blob', body, worker_thread_num: 6, content_md5: 'oafL1+HS78x65+e39PGIIg==')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_multipart_save_block_blob_with_file_handle_success
|
28
|
-
i = 0
|
29
|
-
multiple_values = lambda do |*|
|
30
|
-
i += 1
|
31
|
-
return 'd' * 4 * 1024 * 1024 if i == 1
|
32
|
-
return 'd' * (1 * 1024 * 1024 + 1) if i == 2
|
33
|
-
return nil
|
34
|
-
end
|
35
|
-
temp_file = '/dev/null'
|
36
|
-
File.open(temp_file, 'r') do |file_handle|
|
37
|
-
file_handle.stub :read, multiple_values do
|
38
|
-
file_handle.stub :rewind, nil do
|
39
|
-
@service.stub :create_block_blob, @raw_cloud_blob do
|
40
|
-
@service.stub :put_blob_block, true do
|
41
|
-
@service.stub :commit_blob_blocks, true do
|
42
|
-
assert @service.multipart_save_block_blob('test_container', 'test_blob', file_handle, worker_thread_num: 0)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_multipart_save_block_blob_with_file_handle_do_not_support_rewind_success
|
52
|
-
i = 0
|
53
|
-
multiple_values = lambda do |*|
|
54
|
-
i += 1
|
55
|
-
return 'd' * 4 * 1024 * 1024 if i == 1
|
56
|
-
return 'd' * (1 * 1024 * 1024 + 1) if i == 2
|
57
|
-
return nil
|
58
|
-
end
|
59
|
-
temp_file = '/dev/null'
|
60
|
-
exception = ->(*) { raise 'do not support rewind' }
|
61
|
-
File.open(temp_file, 'r') do |file_handle|
|
62
|
-
file_handle.stub :read, multiple_values do
|
63
|
-
file_handle.stub :rewind, exception do
|
64
|
-
@service.stub :create_block_blob, @raw_cloud_blob do
|
65
|
-
@service.stub :put_blob_block, true do
|
66
|
-
@service.stub :commit_blob_blocks, true do
|
67
|
-
assert @service.multipart_save_block_blob('test_container', 'test_blob', file_handle, worker_thread_num: 'invalid')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_multipart_save_block_blob_http_exception
|
77
|
-
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
78
|
-
|
79
|
-
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
80
|
-
@service.stub :create_block_blob, http_exception do
|
81
|
-
@service.stub :delete_blob, true do
|
82
|
-
assert_raises(Azure::Core::Http::HTTPError) do
|
83
|
-
@service.multipart_save_block_blob('test_container', 'test_blob', body, {})
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_multipart_save_block_blob_fail_when_delete_blob_http_exception
|
90
|
-
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
91
|
-
|
92
|
-
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
93
|
-
@service.stub :create_block_blob, http_exception do
|
94
|
-
@service.stub :delete_blob, http_exception do
|
95
|
-
assert_raises(Azure::Core::Http::HTTPError) do
|
96
|
-
@service.multipart_save_block_blob('test_container', 'test_blob', body, {})
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_multipart_save_block_blob_mock
|
103
|
-
assert @mock_service.multipart_save_block_blob('test_container', 'test_blob', 'content', {})
|
104
|
-
end
|
105
|
-
end
|