gitlab-fog-azure-rm 1.0.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +7 -1
- data/CHANGELOG.md +16 -0
- data/lib/fog/azurerm/models/storage/file.rb +9 -1
- data/lib/fog/azurerm/models/storage/files.rb +4 -4
- data/lib/fog/azurerm/requests/storage/get_blob.rb +6 -6
- data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +4 -2
- data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +4 -2
- data/lib/fog/azurerm/requests/storage/get_object_url.rb +4 -4
- data/lib/fog/azurerm/utilities/general.rb +4 -0
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/models/storage/test_file.rb +13 -1
- data/test/requests/storage/test_get_blob_http_url.rb +37 -0
- data/test/requests/storage/test_get_blob_https_url.rb +42 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc0e6fc125b778bb49c22a6fbfeb0ab779d99bfffaca5496df1834d2a0f69a86
|
4
|
+
data.tar.gz: 5f9ce8aa7d939260edc6047636e6fdfbebaeae6cd7fd611921aa7cc2a3c36056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1578489ca552ed032d47387738f1b8807f467bac75b1d2446fe0ea547ed8b96b81d44c9af7c3134d50da7bb86158e757f8bb18ce4e3e998a9badfb5ce76a55e4
|
7
|
+
data.tar.gz: ff5993b7140d6e3dd0de19d776dd2666980f65a1cb0baeee5abc28ed98eb29a71386108763530f591cb768116493994fbdec1bd877a2c8939c31c6cb85535385
|
data/.gitlab-ci.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
default:
|
2
|
+
image: "ruby:${RUBY_VERSION}"
|
2
3
|
|
3
4
|
cache:
|
4
5
|
paths:
|
@@ -11,7 +12,12 @@ before_script:
|
|
11
12
|
test:
|
12
13
|
script:
|
13
14
|
- bundle exec rake test
|
15
|
+
parallel:
|
16
|
+
matrix:
|
17
|
+
- RUBY_VERSION: [ "2.7", "3.0", "3.1" ]
|
14
18
|
|
15
19
|
rubocop:
|
16
20
|
script:
|
17
21
|
- bundle exec rubocop
|
22
|
+
variables:
|
23
|
+
RUBY_VERSION: "2.7"
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## 1.3.0
|
4
|
+
|
5
|
+
- Fix Ruby 3.0 compatibility !27
|
6
|
+
|
7
|
+
## 1.2.0
|
8
|
+
|
9
|
+
- Support setting returned Content-Disposition in GetBlob requests !25
|
10
|
+
|
11
|
+
## 1.1.1
|
12
|
+
|
13
|
+
- Remove trailing periods per path segment when retrieving blob URLs !23
|
14
|
+
|
15
|
+
## 1.1.0
|
16
|
+
|
17
|
+
- Yanked
|
18
|
+
|
3
19
|
## 1.0.1
|
4
20
|
|
5
21
|
- Fix URL generation for files with UTF-8 characters !21
|
@@ -240,11 +240,19 @@ module Fog
|
|
240
240
|
#
|
241
241
|
def url(expires, options = {})
|
242
242
|
requires :key
|
243
|
-
collection.get_url(key, expires, options)
|
243
|
+
collection.get_url(key, expires, normalize_options(options))
|
244
244
|
end
|
245
245
|
|
246
246
|
private
|
247
247
|
|
248
|
+
def normalize_options(options)
|
249
|
+
# AWS S3 and Google Cloud Storage pass response-content-disposition
|
250
|
+
# as a query string, while Azure needs the content_disposition parameter
|
251
|
+
# to generate a SAS token.
|
252
|
+
options[:content_disposition] ||= options.dig(:query, 'response-content-disposition')
|
253
|
+
options
|
254
|
+
end
|
255
|
+
|
248
256
|
# Upload blob
|
249
257
|
def save_blob(options)
|
250
258
|
if options[:blob_type].nil? || options[:blob_type] == 'BlockBlob'
|
@@ -123,10 +123,10 @@ module Fog
|
|
123
123
|
#
|
124
124
|
# @return [String] A http URL.
|
125
125
|
#
|
126
|
-
def get_http_url(key, expires,
|
126
|
+
def get_http_url(key, expires, options = {})
|
127
127
|
requires :directory
|
128
128
|
|
129
|
-
service.get_blob_http_url(directory.key, key, expires)
|
129
|
+
service.get_blob_http_url(directory.key, key, expires, options)
|
130
130
|
end
|
131
131
|
|
132
132
|
# Get the https URL of the file(blob) with the given name.
|
@@ -139,10 +139,10 @@ module Fog
|
|
139
139
|
#
|
140
140
|
# @return [String] A https URL.
|
141
141
|
#
|
142
|
-
def get_https_url(key, expires,
|
142
|
+
def get_https_url(key, expires, options = {})
|
143
143
|
requires :directory
|
144
144
|
|
145
|
-
service.get_blob_https_url(directory.key, key, expires)
|
145
|
+
service.get_blob_https_url(directory.key, key, expires, options)
|
146
146
|
end
|
147
147
|
|
148
148
|
# Get the file(blob) without content with the given name.
|
@@ -5,7 +5,7 @@ module Fog
|
|
5
5
|
class Real
|
6
6
|
BLOCK_SIZE = 32 * 1024 * 1024 # 32 MB
|
7
7
|
|
8
|
-
def get_blob_with_block_given(container_name, blob_name, options, &
|
8
|
+
def get_blob_with_block_given(container_name, blob_name, options, &block)
|
9
9
|
options[:request_id] = SecureRandom.uuid
|
10
10
|
msg = "get_blob_with_block_given: blob #{blob_name} in the container #{container_name}. options: #{options}"
|
11
11
|
Fog::Logger.debug msg
|
@@ -19,7 +19,7 @@ module Fog
|
|
19
19
|
|
20
20
|
content_length = blob.properties[:content_length]
|
21
21
|
if content_length.zero?
|
22
|
-
|
22
|
+
block.call('', 0, 0)
|
23
23
|
return [blob, '']
|
24
24
|
end
|
25
25
|
|
@@ -30,7 +30,7 @@ module Fog
|
|
30
30
|
raise ArgumentError.new(':end_range MUST be greater than :start_range') if start_range > end_range
|
31
31
|
|
32
32
|
if start_range == end_range
|
33
|
-
|
33
|
+
block.call('', 0, 0)
|
34
34
|
return [blob, '']
|
35
35
|
end
|
36
36
|
|
@@ -55,7 +55,7 @@ module Fog
|
|
55
55
|
raise_azure_exception(ex, msg)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
block.call(content, end_range - buffer_end_range, total_bytes)
|
59
59
|
buffer_start_range += buffer_size
|
60
60
|
end
|
61
61
|
# No need to return content when block is given.
|
@@ -84,7 +84,7 @@ module Fog
|
|
84
84
|
|
85
85
|
# This class provides the mock implementation for unit tests.
|
86
86
|
class Mock
|
87
|
-
def get_blob(_container_name, _blob_name, _options = {}, &
|
87
|
+
def get_blob(_container_name, _blob_name, _options = {}, &block)
|
88
88
|
Fog::Logger.debug 'get_blob successfully.'
|
89
89
|
unless block_given?
|
90
90
|
return [
|
@@ -122,7 +122,7 @@ module Fog
|
|
122
122
|
remaining = total_bytes = data.length
|
123
123
|
while remaining > 0
|
124
124
|
chunk = data.read([remaining, 2].min)
|
125
|
-
|
125
|
+
block.call(chunk, remaining, total_bytes)
|
126
126
|
remaining -= 2
|
127
127
|
end
|
128
128
|
|
@@ -13,13 +13,15 @@ module Fog
|
|
13
13
|
#
|
14
14
|
# @see https://msdn.microsoft.com/en-us/library/azure/mt584140.aspx
|
15
15
|
#
|
16
|
-
def get_blob_http_url(container_name, blob_name, expires)
|
16
|
+
def get_blob_http_url(container_name, blob_name, expires, options = {})
|
17
17
|
relative_path = "#{container_name}/#{blob_name}"
|
18
|
+
relative_path = remove_trailing_periods_from_path_segments(relative_path)
|
18
19
|
params = {
|
19
20
|
service: 'b',
|
20
21
|
resource: 'b',
|
21
22
|
permissions: 'r',
|
22
|
-
expiry: expires.utc.iso8601
|
23
|
+
expiry: expires.utc.iso8601,
|
24
|
+
content_disposition: options[:content_disposition]
|
23
25
|
}
|
24
26
|
token = @signature_client.generate_service_sas_token(relative_path, params)
|
25
27
|
uri = @blob_client.generate_uri(relative_path, {}, { encode: true })
|
@@ -13,14 +13,16 @@ module Fog
|
|
13
13
|
#
|
14
14
|
# @see https://msdn.microsoft.com/en-us/library/azure/mt584140.aspx
|
15
15
|
#
|
16
|
-
def get_blob_https_url(container_name, blob_name, expires)
|
16
|
+
def get_blob_https_url(container_name, blob_name, expires, options = {})
|
17
17
|
relative_path = "#{container_name}/#{blob_name}"
|
18
|
+
relative_path = remove_trailing_periods_from_path_segments(relative_path)
|
18
19
|
params = {
|
19
20
|
service: 'b',
|
20
21
|
resource: 'b',
|
21
22
|
permissions: 'r',
|
22
23
|
expiry: expires.utc.iso8601,
|
23
|
-
protocol: 'https'
|
24
|
+
protocol: 'https',
|
25
|
+
content_disposition: options[:content_disposition]
|
24
26
|
}
|
25
27
|
token = @signature_client.generate_service_sas_token(relative_path, params)
|
26
28
|
uri = @blob_client.generate_uri(relative_path, {}, { encode: true })
|
@@ -5,15 +5,15 @@ module Fog
|
|
5
5
|
class Real
|
6
6
|
# Get a public blob url from Azure blob storage
|
7
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)
|
8
|
+
def get_object_url(container_name, blob_name, expires, options = {})
|
9
|
+
get_blob_https_url(container_name, blob_name, expires, options)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
# This class provides the mock implementation for unit tests.
|
14
14
|
class Mock
|
15
|
-
def get_object_url(container_name, blob_name, expires)
|
16
|
-
get_blob_https_url(container_name, blob_name, expires)
|
15
|
+
def get_object_url(container_name, blob_name, expires, options = {})
|
16
|
+
get_blob_https_url(container_name, blob_name, expires, options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/fog/azurerm/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path '../../test_helper', __dir__
|
2
2
|
|
3
3
|
# Test class for Storage Container Model
|
4
|
-
class TestFile < Minitest::Test
|
4
|
+
class TestFile < Minitest::Test # rubocop:disable Metrics/ClassLength
|
5
5
|
def setup
|
6
6
|
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
7
7
|
@directory = directory(@service)
|
@@ -283,6 +283,18 @@ class TestFile < Minitest::Test
|
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
|
+
def test_url_method_with_content_disposition
|
287
|
+
@file.collection.stub :get_url, @blob_https_url, { content_disposition: 'attachment' } do
|
288
|
+
assert @file.url(Time.now + 3600, content_disposition: 'attachment'), @blob_https_url
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_url_method_with_response_content_disposition
|
293
|
+
@file.collection.stub :get_url, @blob_https_url, { content_disposition: 'attachment' } do
|
294
|
+
assert @file.url(Time.now + 3600, { query: { 'response-content-disposition' => 'attachment' } }), @blob_https_url
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
286
298
|
def test_url_method_without_key_exception
|
287
299
|
assert_raises(ArgumentError) do
|
288
300
|
@file.attributes.delete(:key)
|
@@ -24,6 +24,43 @@ class TestGetBlobHttpUrl < Minitest::Test
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_get_blob_http_url_with_content_disposition
|
28
|
+
mock_generate_uri = Minitest::Mock.new
|
29
|
+
mock_generate_service_token = Minitest::Mock.new
|
30
|
+
url_params = { content_disposition: 'attachment' }
|
31
|
+
|
32
|
+
mock_generate_uri.expect(:call, @url, ['test_container/test_blob', {}, { encode: true }])
|
33
|
+
mock_generate_service_token.expect(:call, @token) do |_relative_path, params|
|
34
|
+
params[:service] == 'b' &&
|
35
|
+
params[:resource] == 'b' &&
|
36
|
+
params[:permissions] == 'r' &&
|
37
|
+
params[:protocol].nil? &&
|
38
|
+
params[:content_disposition] == url_params[:content_disposition]
|
39
|
+
end
|
40
|
+
|
41
|
+
@blob_client.stub :generate_uri, mock_generate_uri do
|
42
|
+
@signature_client.stub :generate_service_sas_token, mock_generate_service_token do
|
43
|
+
assert_equal "#{@url}?#{@token}", @service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600, url_params)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_url_remove_trailing_periods_from_path_segments
|
49
|
+
mock_generate_uri = Minitest::Mock.new
|
50
|
+
mock_generate_service_token = Minitest::Mock.new
|
51
|
+
|
52
|
+
mock_generate_uri.expect(:call, @url, ['.test0/..test1/...test2', {}, { encode: true }])
|
53
|
+
mock_generate_service_token.expect(:call, @token) do |relative_path, _|
|
54
|
+
relative_path == '.test0/..test1/...test2'
|
55
|
+
end
|
56
|
+
|
57
|
+
@blob_client.stub :generate_uri, mock_generate_uri do
|
58
|
+
@signature_client.stub :generate_service_sas_token, mock_generate_service_token do
|
59
|
+
assert_equal "#{@url}?#{@token}", @service.get_blob_http_url('.test0.', '..test1../...test2...', Time.now.utc + 3600)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
27
64
|
def test_get_blob_http_url_mock
|
28
65
|
assert_equal "#{@url}?#{@token}", @mock_service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600)
|
29
66
|
end
|
@@ -31,6 +31,48 @@ class TestGetBlobHttpsUrl < Minitest::Test
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_get_blob_https_url_with_content_disposition
|
35
|
+
mock_generate_uri = Minitest::Mock.new
|
36
|
+
mock_generate_service_token = Minitest::Mock.new
|
37
|
+
url_params = { content_disposition: 'attachment' }
|
38
|
+
|
39
|
+
2.times do
|
40
|
+
mock_generate_uri.expect(:call, @url, ['test_container/test_blob', {}, { encode: true }])
|
41
|
+
mock_generate_service_token.expect(:call, @token) do |_relative_path, params|
|
42
|
+
params[:service] == 'b' &&
|
43
|
+
params[:resource] == 'b' &&
|
44
|
+
params[:permissions] == 'r' &&
|
45
|
+
params[:content_disposition] == url_params[:content_disposition]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@blob_client.stub :generate_uri, mock_generate_uri do
|
50
|
+
@signature_client.stub :generate_service_sas_token, mock_generate_service_token do
|
51
|
+
assert_equal "#{@url}?#{@token}", @service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600, url_params)
|
52
|
+
assert_equal "#{@url}?#{@token}", @service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600, url_params)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_url_remove_trailing_periods_from_path_segments
|
58
|
+
mock_generate_uri = Minitest::Mock.new
|
59
|
+
mock_generate_service_token = Minitest::Mock.new
|
60
|
+
|
61
|
+
2.times do
|
62
|
+
mock_generate_uri.expect(:call, @url, ['.test0/..test1/...test2', {}, { encode: true }])
|
63
|
+
mock_generate_service_token.expect(:call, @token) do |relative_path, _|
|
64
|
+
relative_path == '.test0/..test1/...test2'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
@blob_client.stub :generate_uri, mock_generate_uri do
|
69
|
+
@signature_client.stub :generate_service_sas_token, mock_generate_service_token do
|
70
|
+
assert_equal "#{@url}?#{@token}", @service.get_blob_https_url('.test0.', '..test1../...test2...', Time.now.utc + 3600)
|
71
|
+
assert_equal "#{@url}?#{@token}", @service.get_object_url('.test0.', '..test1../...test2...', Time.now.utc + 3600)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
34
76
|
def test_get_blob_https_url_with_domain_success
|
35
77
|
service = Fog::Storage::AzureRM.new(storage_account_credentials_with_domain)
|
36
78
|
blob_client = service.instance_variable_get(:@blob_client)
|
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: 1.0
|
4
|
+
version: 1.3.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:
|
21
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: codeclimate-test-reporter
|
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
338
338
|
- !ruby/object:Gem::Version
|
339
339
|
version: '0'
|
340
340
|
requirements: []
|
341
|
-
rubygems_version: 3.1.
|
341
|
+
rubygems_version: 3.1.6
|
342
342
|
signing_key:
|
343
343
|
specification_version: 4
|
344
344
|
summary: Module for the 'fog' gem to support Azure Blob Storage with CarrierWave and
|